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

Closed
ToRaNek wants to merge 0 commits from upstream-pr/24874 into main
ToRaNek commented 2026-11-21 08:39:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ToRaNek on 2026-11-21T08:39:08Z.


What

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:5426072127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24874). Originally posted by [ToRaNek](https://github.com/ToRaNek) on 2026-11-21T08:39:08Z. --- ### What 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-21 08:43:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T08:43:45Z.

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 #4754: nkwebkit_crossoriginresponsecheck ...   Passed    0.01 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 null-pointer checks for response and securityOrigin arguments throwing std::invalid_argument in WebCore::passesAccessControlCheck
    • Verified virtual dispatch safety and null vtable validation in CheckEnabled for CrossOriginAccessControlCheckDisabler
    • Verified WebCore CORS error messages, status code formatting, and wildcard handling across StoredCredentialsPolicy modes (DoNotUse, Use, EphemeralStateless)
    • Verified ExpectedVoidString memory management, reference counting semantics, and ABI layout (sizeof == 16, offsetof error == 0, hasValue == 8)
    • Verified AGENTS.md compliance regarding comments, debt fragment tracking in docs/dev/debt/changes/, and absence of title special-casing

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6004207492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24874#pullrequestreview-6004207492). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T08:43:45Z. **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 #4754: nkwebkit_crossoriginresponsecheck ... Passed 0.01 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 null-pointer checks for response and securityOrigin arguments throwing std::invalid_argument in WebCore::passesAccessControlCheck - Verified virtual dispatch safety and null vtable validation in CheckEnabled for CrossOriginAccessControlCheckDisabler - Verified WebCore CORS error messages, status code formatting, and wildcard handling across StoredCredentialsPolicy modes (DoNotUse, Use, EphemeralStateless) - Verified ExpectedVoidString memory management, reference counting semantics, and ABI layout (sizeof == 16, offsetof error == 0, hasValue == 8) - Verified AGENTS.md compliance regarding comments, debt fragment tracking in docs/dev/debt/changes/, and absence of title special-casing Looks Good To Me
MarcZX10 commented 2026-11-21 09:38:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T09:38:14Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the behavior and ABI assumptions are supported by the code inspected, though console ABI compatibility remains unverified.

What I ran

Reviewed head a3a5ea7dbe2bbc07f242e8e65237288b665c0b8a using the prepared diff and repo_read.py. No commands or tests were run. The author reports Windows 11 / MinGW GCC 15.2 tests; those results were not independently run.

Results

Check Result Note
Code review passed Implemented CORS branches and result construction inspected
Tests not run Author-reported test results only
Console ABI not run ABI layouts were not measured on console

Findings

Blocking

None.

Non-blocking

  • The response status offset and Expected<void, String> layout are inferred from upstream structures, not measured against a console module. The change records this limitation in its debt note.

Not verified

Did not run tests, builds, convention checks, or console validation. Read the changed implementation, ABI headers, test source, debt note, and relevant sections of Export.cpp and InventoryExports.hpp. files.json was not accessible through the reader; manifest.json identifies Export.cpp and InventoryExports.hpp as excluded from the review bundle, and their relevant ranges were read through repo_read.py. Other changed files were not individually read from their full head text. No precheck output was available.

To get this to a good state

Nothing is required. Optional: validate the ABI layouts against a console module and close the recorded technical debt when compared.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6004432746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24874#pullrequestreview-6004432746). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T09:38:14Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the behavior and ABI assumptions are supported by the code inspected, though console ABI compatibility remains unverified. ## What I ran Reviewed head `a3a5ea7dbe2bbc07f242e8e65237288b665c0b8a` using the prepared diff and `repo_read.py`. No commands or tests were run. The author reports Windows 11 / MinGW GCC 15.2 tests; those results were not independently run. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Implemented CORS branches and result construction inspected | | Tests | not run | Author-reported test results only | | Console ABI | not run | ABI layouts were not measured on console | ## Findings ### Blocking None. ### Non-blocking - The response status offset and `Expected<void, String>` layout are inferred from upstream structures, not measured against a console module. The change records this limitation in its debt note. ## Not verified Did not run tests, builds, convention checks, or console validation. Read the changed implementation, ABI headers, test source, debt note, and relevant sections of `Export.cpp` and `InventoryExports.hpp`. `files.json` was not accessible through the reader; `manifest.json` identifies `Export.cpp` and `InventoryExports.hpp` as excluded from the review bundle, and their relevant ranges were read through `repo_read.py`. Other changed files were not individually read from their full head text. No precheck output was available. ## To get this to a good state Nothing is required. Optional: validate the ABI layouts against a console module and close the recorded technical debt when compared.

Pull request closed

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!24874
No description provided.