Skip to content

feat(libSceNKWebKit): implement WebCore::SecurityOrigin and SecurityOriginData origin queries - #22751

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
opxdelwin:feat/libscenkwebkit-security-origin
Nov 18, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
opxdelwin:feat/libscenkwebkit-security-origin

Conversation

@opxdelwin

Copy link
Copy Markdown
Contributor

What

Implements 11 libSceNKWebKit exports for WebKit's origin model, ported from the pinned PS5 WebKit source neonmodder123/PS5-WebKit-11.x@80f77e94c63e (SecurityOrigin.cpp/.h, SecurityOriginData.cpp/.h, OriginAccessEntry.cpp, and URL::hasSpecialScheme from WTF/wtf/URL.cpp):

  • WebCore::SecurityOrigin::create(const URL&), toString, toRawString, isolatedCopy, equal, isSameOriginAs, domainForCachePartition, isMatchingRegistrableDomainSuffix
  • WebCore::SecurityOriginData::toString, databaseIdentifier, securityOrigin

Changes:

  • src/SecurityOriginAbi.hpp (new) models the release-build layout of SecurityOrigin (64 bytes) and SecurityOriginData (32 bytes, a std::variant of tuple and opaque data), taken from the pinned SecurityOrigin.h, SecurityOriginData.h and ProcessQualified.h. static_asserts pin every offset and both sizes.
  • include/SecurityOriginExports.hpp holds the typed declarations. The stubs are removed from Export.cpp, and the declarations from InventoryExports.hpp.
  • src/Mime.cpp gets two small accessors over the existing no-access and cache-partitioned scheme registries.
  • src/WtfString.cpp exposes the existing URL port helper.

Paths that still throw NotImplemented_nid_no_patch, all recorded in the debt fragment:

  • create(URL) for blob: URLs, because there is no blob origin cache;
  • SecurityOriginData::securityOrigin for local schemes other than file, because there is no URL parser.

The fragment also records the layout assumption that libc++'s std::variant index is 32 bits.

Known nit, left for review: raw URL bit masks could be a named helper.

Note on overlap: tools/pr_overlap.py --branch reports a textual conflict with #19636 in src/Mime.cpp (L711-712 on main). Both PRs append new code at the end of the file, so the conflict is trivial to resolve and neither PR changes the other's code. The tool could not compare 29 other PRs (#13515, #14138, #14164, #14259, #14860, #16510, #17550, #17569, #17695, #17771, #17793, #17805, #17922, #17927, #17933, #18395, #18797, #18802, #19105, #19823, #20304, #20314, #20327, #21957, #22454, #22555, #22556, #22557, #22674), because each conflicts with main. They share only Export.cpp / InventoryExports.hpp with this PR. I checked their diffs by hand: none adds, edits or removes any of the exports this PR implements.

Tested

Not tested with a title or homebrew. Unit tests only, on Linux (Docker, Ubuntu image).

The build targets were libSceNKWebKit nkwebkit_securityorigin_tests nkwebkit_forwarding_tests nkwebkit_symbolset_tests, run with ctest -R '^(nkwebkit_securityorigin|nkwebkit_forwarding|nkwebkit_symbolset|public_headers.*)$':

  • GCC, on this commit rebased onto main 64da164: 68 of 68 tests pass.
  • Clang, on the same change before that rebase: nkwebkit_securityorigin, nkwebkit_forwarding and nkwebkit_symbolset pass. Four tests fail: public_headers_compile_1/16/29/39, on -Winvalid-offsetof for Region in RegionExports.hpp, a file this PR does not touch. Unmodified main (324cc95) built with Clang fails the same four tests (4 of 67), so they fail before this PR too.

New tests cover:

  • tuple, opaque and file origins;
  • default-port stripping and 16-bit strings;
  • equal, isSameOriginAs and document.domain handling;
  • isolatedCopy (deep string copies, every flag, refcounts);
  • domainForCachePartition, including a registered scheme;
  • isMatchingRegistrableDomainSuffix (public suffixes, IP address vs domain);
  • SecurityOriginData::toString, databaseIdentifier and securityOrigin;
  • the NotImplemented paths, a valueless variant and null-pointer throws.

A scratch program built with both g++ and clang++ checked the layout offsets against the static_asserts.

Also passed: tools/check_conventions.py --base upstream/main and tools/debt_fold.py --check.

Not run: the Windows (MSYS2) build, and the Clang tests after the rebase. None of the commits the rebase took in touch libSceNKWebKit.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

Copy link
Copy Markdown

Progress report (33b6998 → b444623)

📈 System libraries: 42.34% (+0.02%, +9 implemented functions)

✅ 9 implemented
Library Name
libSceNKWebKit _ZNK7WebCore14SecurityOrigin11toRawStringEv
libSceNKWebKit _ZNK7WebCore14SecurityOrigin12isolatedCopyEv
libSceNKWebKit _ZNK7WebCore14SecurityOrigin14isSameOriginAsERKS0_
libSceNKWebKit _ZNK7WebCore14SecurityOrigin23domainForCachePartitionEv
libSceNKWebKit _ZNK7WebCore14SecurityOrigin33isMatchingRegistrableDomainSuffixERKN3WTF6StringEb
libSceNKWebKit _ZNK7WebCore14SecurityOrigin5equalEPKS0_
libSceNKWebKit _ZNK7WebCore14SecurityOrigin8toStringEv
libSceNKWebKit _ZNK7WebCore18SecurityOriginData18databaseIdentifierEv
libSceNKWebKit _ZNK7WebCore18SecurityOriginData8toStringEv

Changed libraries (implemented exports)

Library Before After Change
libSceNKWebKit 3402/11275 (30.17%) 3411/11275 (30.25%) +0.08%

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b4446230cf:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_securityorigin_tests built cleanly.
  • CTest (nkwebkit_securityorigin):
    1/1 Test #4545: nkwebkit_securityorigin ..........   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/SecurityOriginExports.hpp, core/libs/prx/libSceNKWebKit/src/Mime.cpp, core/libs/prx/libSceNKWebKit/src/SecurityOrigin.cpp, core/libs/prx/libSceNKWebKit/src/WtfString.cpp, core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • SecurityOriginAbi.hpp: verified struct alignments, sizes (64B for SecurityOrigin, 32B for SecurityOriginData), and offset static_asserts against WebKit release layout and libc++ variant layout
    • SecurityOrigin.cpp: verified null pointer checks using Checked() for self, other, and url across all exported WebCore::SecurityOrigin and WebCore::SecurityOriginData functions
    • SecurityOrigin.cpp: verified fastMalloc/fastFree and atomic refCount memory management in PendingOrigin, CreateFromURL, CreateFromData, and SecurityOrigin::deref
    • SecurityOrigin.cpp: checked string concatenation and length limits in Concatenate, ensuring protection against integer overflow (> std::numeric_limits<int32_t>::max())
    • SecurityOrigin.cpp: checked origin comparisons (equal, isSameOriginAs) for correct handling of opaque identifiers and domainWasSetInDOM semantics
    • docs/dev/debt/changes/feat-libscenkwebkit-security-origin.md: verified debt fragment records all unimplemented paths (blob URLs, non-file local schemes in CreateFromData, etc.) per AGENTS.md rules

Looks Good To Me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants