feat(libSceNKWebKit): implement WebCore::passesAccessControlCheck #26408

Merged
ToRaNek merged 1 commit from upstream-pr/26408 into main 2026-11-24 00:28:15 +00:00
ToRaNek commented 2026-11-23 22:26:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ToRaNek on 2026-11-23T22:26:17Z.


What

Resubmission of #24874, which was closed when my fork left the fork network (I switched it to private by mistake) and cannot be reopened. Same head commit a3a5ea7dbe2; the reviews and the discussion are on #24874.

Implements WebCore::passesAccessControlCheck, the CORS check of a response, which was a stub.

It follows the pinned source line by line (CrossOriginAccessControl.cpp L259-L286):

Response Result
Access-Control-Allow-Origin: *, policy DoNotUse, or a disabler that says the check is off success
* otherwise Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.
a value with a comma Access-Control-Allow-Origin cannot contain more than one origin.
any other value that is not the origin's string (header absent included) Origin <origin> is not allowed by Access-Control-Allow-Origin. Status code: <code>
the origin's string, policy Use, Access-Control-Allow-Credentials not exactly true Credentials flag is true, but Access-Control-Allow-Credentials is not "true".
the origin's string otherwise success

It uses three exports that are already implemented: ResourceResponseBase::httpHeaderField(HTTPHeaderName), SecurityOrigin::toString and WTF::equal(const StringImpl*, const StringImpl*). The disabler is asked through its virtual table, with the slot the library already uses, and only when the policy is not DoNotUse.

Two layouts are new, both derived from the pinned source and not measured on a console:

  • Expected<void, String>, returned through the hidden pointer: the error string at offset 0, the has flag at offset 8, 16 bytes (Expected.h L292-L304 and L378-L383).
  • The HTTP status code at offset 176 of the response. After the header map, which ends at 112, come Box<NetworkLoadMetrics> (one pointer), std::optional<CertificateInfo> and short m_httpStatusCode (ResourceResponseBase.h L316-L327). The curl CertificateInfo is an int, a Vector and, on PlayStation, a second Vector and a String: 48 bytes (CertificateInfo.h L94-L100), 56 with the flag of the optional. The code is only used in the text of the mismatch message.

The rest of the family stays stubbed, because each one needs something main does not have yet: validatePreflightResponse, validateCrossOriginResourcePolicy, createAccessControlPreflightRequest and three of the Vary helpers are 3.20-era exports that take 3.20 layouts; the preflight cache holds guest HashMap and HashSet tables; updateRedirectChainStatus needs computeFreshnessLifetimeForHTTPFamily. I did not implement any of them partially.

Tested

Windows 11, MinGW GCC 15.2.

  • The test is new (nkwebkit_crossoriginresponsecheck) and cannot be built on main, where the export is an untyped stub; on main the function throws.
  • It passes on the branch. It covers each row above with the exact message; the wildcard for the three policies and for a value outside the enumeration; the disabler called through its table, and not called for DoNotUse (a call counter); the origin comparison for case, spaces, port, 8-bit against 16-bit strings, an empty header; an opaque origin and a file origin; seven status codes written at offset 176 with 0xFF around them; the returned object (flag at offset 8, guard bytes on both sides intact, reference counts); null arguments.
  • Six negative controls, each rebuilt and run, each makes the test fail: the wildcard allowed for every policy but Use (line 183), the wildcard accepted without the condition (line 181), the comma test removed (line 299), the status code suffix removed (line 197), the credentials header required for every policy but DoNotUse (line 262), the disabler's answer inverted (line 222).
  • I also rebuilt and ran the whole library: all 177 nkwebkit_* tests and patched_libraries pass on the branch.
  • python tools/check_conventions.py --base origin/main and python tools/debt_fold.py --check pass.

Not tested on a console.

Overlap (python tools/pr_overlap.py --branch feat/nkwebkit-cors-response-checks):

  • No open PR implements this function. #24322, a refactor that splits the large libraries into smaller ones, moves the stub without changing it.
  • The tool could not compare 34 PRs that conflict with main and share Export.cpp or InventoryExports.hpp, the two files every implementation edits. I searched each of their diffs for the symbol: none changes it (in #16510 it only appears as the context of a hunk header).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5462297227 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26408). Originally posted by [ToRaNek](https://github.com/ToRaNek) on 2026-11-23T22:26:17Z. --- ### What Resubmission of #24874, which was closed when my fork left the fork network (I switched it to private by mistake) and cannot be reopened. Same head commit `a3a5ea7dbe2`; the reviews and the discussion are on #24874. Implements `WebCore::passesAccessControlCheck`, the CORS check of a response, which was a stub. It follows the pinned source line by line ([CrossOriginAccessControl.cpp L259-L286](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/loader/CrossOriginAccessControl.cpp#L259-L286)): | Response | Result | |---|---| | `Access-Control-Allow-Origin: *`, policy `DoNotUse`, or a disabler that says the check is off | success | | `*` otherwise | `Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.` | | a value with a comma | `Access-Control-Allow-Origin cannot contain more than one origin.` | | any other value that is not the origin's string (header absent included) | `Origin <origin> is not allowed by Access-Control-Allow-Origin. Status code: <code>` | | the origin's string, policy `Use`, `Access-Control-Allow-Credentials` not exactly `true` | `Credentials flag is true, but Access-Control-Allow-Credentials is not "true".` | | the origin's string otherwise | success | It uses three exports that are already implemented: `ResourceResponseBase::httpHeaderField(HTTPHeaderName)`, `SecurityOrigin::toString` and `WTF::equal(const StringImpl*, const StringImpl*)`. The disabler is asked through its virtual table, with the slot the library already uses, and only when the policy is not `DoNotUse`. Two layouts are new, both derived from the pinned source and not measured on a console: - **`Expected<void, String>`**, returned through the hidden pointer: the error string at offset 0, the `has` flag at offset 8, 16 bytes ([Expected.h L292-L304 and L378-L383](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/Expected.h#L292-L383)). - **The HTTP status code at offset 176 of the response.** After the header map, which ends at 112, come `Box<NetworkLoadMetrics>` (one pointer), `std::optional<CertificateInfo>` and `short m_httpStatusCode` ([ResourceResponseBase.h L316-L327](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/network/ResourceResponseBase.h#L316-L327)). The curl `CertificateInfo` is an `int`, a `Vector` and, on PlayStation, a second `Vector` and a `String`: 48 bytes ([CertificateInfo.h L94-L100](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/platform/network/curl/CertificateInfo.h#L94-L100)), 56 with the flag of the optional. The code is only used in the text of the mismatch message. The rest of the family stays stubbed, because each one needs something `main` does not have yet: `validatePreflightResponse`, `validateCrossOriginResourcePolicy`, `createAccessControlPreflightRequest` and three of the `Vary` helpers are 3.20-era exports that take 3.20 layouts; the preflight cache holds guest `HashMap` and `HashSet` tables; `updateRedirectChainStatus` needs `computeFreshnessLifetimeForHTTPFamily`. I did not implement any of them partially. ### Tested Windows 11, MinGW GCC 15.2. - The test is new (`nkwebkit_crossoriginresponsecheck`) and cannot be built on `main`, where the export is an untyped stub; on `main` the function throws. - It passes on the branch. It covers each row above with the exact message; the wildcard for the three policies and for a value outside the enumeration; the disabler called through its table, and not called for `DoNotUse` (a call counter); the origin comparison for case, spaces, port, 8-bit against 16-bit strings, an empty header; an opaque origin and a `file` origin; seven status codes written at offset 176 with `0xFF` around them; the returned object (flag at offset 8, guard bytes on both sides intact, reference counts); null arguments. - Six negative controls, each rebuilt and run, each makes the test fail: the wildcard allowed for every policy but `Use` (line 183), the wildcard accepted without the condition (line 181), the comma test removed (line 299), the status code suffix removed (line 197), the credentials header required for every policy but `DoNotUse` (line 262), the disabler's answer inverted (line 222). - I also rebuilt and ran the whole library: all 177 `nkwebkit_*` tests and `patched_libraries` pass on the branch. - `python tools/check_conventions.py --base origin/main` and `python tools/debt_fold.py --check` pass. Not tested on a console. **Overlap** (`python tools/pr_overlap.py --branch feat/nkwebkit-cors-response-checks`): - No open PR implements this function. #24322, a refactor that splits the large libraries into smaller ones, moves the stub without changing it. - The tool could not compare 34 PRs that conflict with `main` and share `Export.cpp` or `InventoryExports.hpp`, the two files every implementation edits. I searched each of their diffs for the symbol: none changes it (in #16510 it only appears as the context of a hunk header). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-24 00:15:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-24T00:15:33Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_crossoriginresponsecheck_tests built cleanly.
  • CTest (nkwebkit_crossoriginresponsecheck):
    1/1 Test #4905: nkwebkit_crossoriginresponsecheck ...   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/CrossOriginAccessControlExports.hpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControl.cpp, core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControlAbi.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified WebCore::passesAccessControlCheck null checks for response and securityOrigin throw std::invalid_argument in core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControl.cpp:187-188
    • Verified checkDisabler null handling and virtual table validation in CheckEnabled in core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControl.cpp:118-122
    • Verified CORS response logic and error messages against pinned WebKit source (wildcard credentials flag check, comma separation check, origin mismatch with status code, credentials flag mismatch)
    • Verified ABI layout, sizeof, and member offsets in ResourceResponseStatusAbi.hpp and WtfExpectedAbi.hpp matching System V AMD64 calling conventions
    • Verified AGENTS.md compliance: no forbidden comments, technical debt fragment in docs/dev/debt/changes/, and proper export declarations in CrossOriginAccessControlExports.hpp
    • Verified comprehensive test suite in CrossOriginResponseCheck.cpp covering wildcards, disabler singleton/custom vtables, status codes, 8-bit/16-bit encoding, and reference counting

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6031637013 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26408#pullrequestreview-6031637013). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-24T00:15:33Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `a3a5ea7dbe`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_crossoriginresponsecheck_tests` built cleanly. - **CTest** (`nkwebkit_crossoriginresponsecheck`): ``` 1/1 Test #4905: nkwebkit_crossoriginresponsecheck ... 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/CrossOriginAccessControlExports.hpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControl.cpp`, `core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControlAbi.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified WebCore::passesAccessControlCheck null checks for response and securityOrigin throw std::invalid_argument in core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControl.cpp:187-188 - Verified checkDisabler null handling and virtual table validation in CheckEnabled in core/libs/prx/libSceNKWebKit/src/CrossOriginAccessControl.cpp:118-122 - Verified CORS response logic and error messages against pinned WebKit source (wildcard credentials flag check, comma separation check, origin mismatch with status code, credentials flag mismatch) - Verified ABI layout, sizeof, and member offsets in ResourceResponseStatusAbi.hpp and WtfExpectedAbi.hpp matching System V AMD64 calling conventions - Verified AGENTS.md compliance: no forbidden comments, technical debt fragment in docs/dev/debt/changes/, and proper export declarations in CrossOriginAccessControlExports.hpp - Verified comprehensive test suite in CrossOriginResponseCheck.cpp covering wildcards, disabler singleton/custom vtables, status codes, 8-bit/16-bit encoding, and reference counting Looks Good To Me
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!26408
No description provided.