feat(libSceHttp): add the cookie store #10535

Merged
noamroger merged 6 commits from upstream-pr/10535 into main 2026-11-13 02:05:49 +00:00
noamroger commented 2026-10-24 08:48:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by noamroger on 2026-10-24T08:48:19Z.


What

Implements the libSceHttp cookie store: sceHttpAddCookie, sceHttpGetCookie, sceHttpGetCookieStats, sceHttpSetCookieMaxNum, sceHttpSetCookieMaxNumPerDomain, sceHttpSetCookieMaxSize and sceHttpSetCookieTotalMaxSize. sceHttpCookieFlush now empties the store.

  • Each HTTP context gets its own store, which sceHttpTerm drops. The code is in a new src/Cookies.cpp, so Export.cpp only loses the stubs, which keeps conflicts with #9834 and #10167 small.
  • Behaviour follows the cookie calls of firmware 13.42 libSceHttp.sprx, measured natively by a reviewer (see the review thread): INVALID_ID without a live context, any URL scheme, 0x804321FE for a URL without a host or a Domain the host does not end with, INVALID_VALUE for an empty cookie or a Domain with too few labels (two under com/org/net/edu/gov/mil/int, three elsewhere), cookies without a name or a value kept, cookies without Domain sent to subdomains, the default path keeping its slash and Path as a plain prefix.
  • sceHttpGetCookie(ctx, url, cookie, required, prepared) returns Secure cookies only for https://, writes a=1; b=2, a NUL, a space and a NUL (required = length + 3), returns NOT_FOUND (0x80431025) without a match, and on a short buffer returns OUT_OF_SIZE (0x80431104) with the cookies that fit written and terminated. Longer paths come first.
  • Limits default to 4096 bytes of name + value (over it, or a stored size over the limit + 516: OUT_OF_SIZE), 50 cookies per domain, 3000 cookies and 81920 bytes in total. Past the count or total-size limit the 10 oldest cookies go at once (every older one if fewer) and the new one stays; past the per-domain limit the oldest of the domain goes. Every setter and sceHttpCookieFlush empty the store and keep the peaks. sceHttpGetCookieStats writes the 32-byte layout already in include/Http.hpp, leaving bytes 12-15 untouched; the size is name + value + domain (without its dot) + path + 5.
  • Expiry uses the RFC 6265 §5.1.1 date algorithm; every date case matched the console. A Domain spelled differently is a different cookie.
  • Equal-length paths put the most specific domain first, then the measured per-domain order. sceHttpCookieFlush returns INVALID_ID without a live context, as measured; GuestHttp is updated for it.
  • sceHttpCookieExport, sceHttpCookieImport and sceHttpSetCookieSendCallback still throw; they are left for a follow-up.

Tested

Linux (Ubuntu 24.04, GCC 13.3). libSceHttp was built from its sources, and the guest tests were linked against it. The new GuestHttpCookies passes, as do GuestHttpOptions and GuestHttpResponseHeader. GuestHttp needs the real libc process-parameter fixture and was not run locally. A reviewer built it on Windows 11 (WinLibs GCC 15.2.0, mingw-w64) and found ERROR_NOT_FOUND clashing with the winerror.h macro; it is now ERROR_HTTP_NOT_FOUND, and with that rename guest_http_cookies passed 3 of 3 runs there.

GuestHttpCookies covers every behaviour listed above against the console results: errors and their precedence, the required and partial-write layout, matching and ordering, domain rules, deletion and the date formats, the size bound, each default limit and setter, eviction by age and the stats layout and size. It also passes under ASan and UBSan.

Not run on a PS5 by me; the expectations come from the reviewer's firmware 13.42 measurements.

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
  • 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: #9630
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4993978666 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10535). Originally posted by [noamroger](https://github.com/noamroger) on 2026-10-24T08:48:19Z. --- ### What Implements the libSceHttp cookie store: `sceHttpAddCookie`, `sceHttpGetCookie`, `sceHttpGetCookieStats`, `sceHttpSetCookieMaxNum`, `sceHttpSetCookieMaxNumPerDomain`, `sceHttpSetCookieMaxSize` and `sceHttpSetCookieTotalMaxSize`. `sceHttpCookieFlush` now empties the store. - Each HTTP context gets its own store, which `sceHttpTerm` drops. The code is in a new `src/Cookies.cpp`, so `Export.cpp` only loses the stubs, which keeps conflicts with #9834 and #10167 small. - Behaviour follows the cookie calls of firmware 13.42 `libSceHttp.sprx`, measured natively by a reviewer (see the review thread): `INVALID_ID` without a live context, any URL scheme, `0x804321FE` for a URL without a host or a `Domain` the host does not end with, `INVALID_VALUE` for an empty cookie or a `Domain` with too few labels (two under com/org/net/edu/gov/mil/int, three elsewhere), cookies without a name or a value kept, cookies without `Domain` sent to subdomains, the default path keeping its slash and `Path` as a plain prefix. - `sceHttpGetCookie(ctx, url, cookie, required, prepared)` returns `Secure` cookies only for `https://`, writes `a=1; b=2`, a NUL, a space and a NUL (`required` = length + 3), returns `NOT_FOUND` (0x80431025) without a match, and on a short buffer returns `OUT_OF_SIZE` (0x80431104) with the cookies that fit written and terminated. Longer paths come first. - Limits default to 4096 bytes of name + value (over it, or a stored size over the limit + 516: `OUT_OF_SIZE`), 50 cookies per domain, 3000 cookies and 81920 bytes in total. Past the count or total-size limit the 10 oldest cookies go at once (every older one if fewer) and the new one stays; past the per-domain limit the oldest of the domain goes. Every setter and `sceHttpCookieFlush` empty the store and keep the peaks. `sceHttpGetCookieStats` writes the 32-byte layout already in `include/Http.hpp`, leaving bytes 12-15 untouched; the size is name + value + domain (without its dot) + path + 5. - Expiry uses the RFC 6265 §5.1.1 date algorithm; every date case matched the console. A `Domain` spelled differently is a different cookie. - Equal-length paths put the most specific domain first, then the measured per-domain order. `sceHttpCookieFlush` returns `INVALID_ID` without a live context, as measured; `GuestHttp` is updated for it. - `sceHttpCookieExport`, `sceHttpCookieImport` and `sceHttpSetCookieSendCallback` still throw; they are left for a follow-up. ### Tested Linux (Ubuntu 24.04, GCC 13.3). libSceHttp was built from its sources, and the guest tests were linked against it. The new `GuestHttpCookies` passes, as do `GuestHttpOptions` and `GuestHttpResponseHeader`. `GuestHttp` needs the real libc process-parameter fixture and was not run locally. A reviewer built it on Windows 11 (WinLibs GCC 15.2.0, mingw-w64) and found `ERROR_NOT_FOUND` clashing with the `winerror.h` macro; it is now `ERROR_HTTP_NOT_FOUND`, and with that rename `guest_http_cookies` passed 3 of 3 runs there. `GuestHttpCookies` covers every behaviour listed above against the console results: errors and their precedence, the `required` and partial-write layout, matching and ordering, domain rules, deletion and the date formats, the `size` bound, each default limit and setter, eviction by age and the stats layout and size. It also passes under ASan and UBSan. Not run on a PS5 by me; the expectations come from the reviewer's firmware 13.42 measurements. ### 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) - [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: #9630 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 11:07:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:07:05Z.

Review: CHANGES_REQUESTED


Found a reproducible overflow in parseMaxAge(). The saturation threshold 0x7FFFFFFFFF seconds is much larger than the representable system_clock range on this Linux host (nanosecond ticks). A valid value such as Max-Age=10000000000 is below that threshold, so it reaches now + std::chrono::seconds{seconds}; converting the seconds to the clock duration overflows signed 64-bit nanoseconds. I compiled the exact PR-head Cookies.cpp with a tiny parseMaxAge("10000000000", Clock::now()) probe under -fsanitize=undefined -fno-sanitize-recover=all; UBSan reports signed integer overflow in chrono.h and aborts. Please clamp/check against the clock’s representable remaining range before adding, and add a large-but-valid Max-Age regression (ideally run the focused test under UBSan). This is in addition to the contributor-reported cookie test suite.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638022293 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10535#pullrequestreview-5638022293). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T11:07:05Z. **Review:** CHANGES_REQUESTED --- Found a reproducible overflow in `parseMaxAge()`. The saturation threshold `0x7FFFFFFFFF` seconds is much larger than the representable `system_clock` range on this Linux host (nanosecond ticks). A valid value such as `Max-Age=10000000000` is below that threshold, so it reaches `now + std::chrono::seconds{seconds}`; converting the seconds to the clock duration overflows signed 64-bit nanoseconds. I compiled the exact PR-head `Cookies.cpp` with a tiny `parseMaxAge("10000000000", Clock::now())` probe under `-fsanitize=undefined -fno-sanitize-recover=all`; UBSan reports signed integer overflow in `chrono.h` and aborts. Please clamp/check against the clock’s representable remaining range before adding, and add a large-but-valid Max-Age regression (ideally run the focused test under UBSan). This is in addition to the contributor-reported cookie test suite.
MarcZX10 commented 2026-10-24 12:24:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T12:24:49Z.

Review: CHANGES_REQUESTED


The reported clock-range overflow is addressed on the current head: Max-Age is bounded to the remaining clock range, and Expires is clamped before conversion. The focused regression and UBSan run are author-reported; hosted structural checks pass, while product builds are skipped. Merge coordination is still needed for two concrete file overlaps. #9630 adds a separate allocation-regression target to the same libSceHttp/CMakeLists.txt section where this PR registers GuestHttpCookies, and #6044 reorganizes test paths/registrations. Please agree with those authors on an order or rebase strategy, record it in Depends on/your PR notes, and ensure both test registrations survive the composition. I manually checked #9822/#9826: their libSceHttp change is sceHttpSetCookieEnabled, separate from the cookie store exports here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638227032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10535#pullrequestreview-5638227032). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T12:24:49Z. **Review:** CHANGES_REQUESTED --- The reported clock-range overflow is addressed on the current head: Max-Age is bounded to the remaining clock range, and Expires is clamped before conversion. The focused regression and UBSan run are author-reported; hosted structural checks pass, while product builds are skipped. Merge coordination is still needed for two concrete file overlaps. #9630 adds a separate allocation-regression target to the same libSceHttp/CMakeLists.txt section where this PR registers GuestHttpCookies, and #6044 reorganizes test paths/registrations. Please agree with those authors on an order or rebase strategy, record it in Depends on/your PR notes, and ensure both test registrations survive the composition. I manually checked #9822/#9826: their libSceHttp change is sceHttpSetCookieEnabled, separate from the cookie store exports here.
MarcZX10 commented 2026-10-31 18:29:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T18:29:45Z.

Review: COMMENTED


Re-checked — new head, integration evidence pending

The cookie implementation and its earlier requested fixes are in place, but I cannot verify the final composition with the still-open #9630 dependency at its current head.

What I ran

Reviewed exact PR head 1fac04e35ee1c594063d9243d08a48445c35a675 against PR base 4017310678562c63594d99b8f45db2d68b9aaa6c; the individual preview against current main ca073ec3ad0d766ea9f4658e418a5c977001a353 is clean. Environment: Linux x86-64, Python 3.11.2, Git 2.39.5. I did not build or compile locally.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 10535 --output-dir /tmp/anyps5-10535-review
python3 tools/pr_stack_check.py 10535 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-10535-review/stack
gh pr view 9630 -R boykopovar/AnyPS5 --json state,headRefOid,body

Results

Check Result
Diff and conventions Passed.
Current-main merge preview Clean for #10535 and #9630 considered individually.
Declared dependency #9630 remains open at cff855f72618fbee7bde0b866609854017ca5f9b; its current head is not included in #10535 and overlaps CMakeLists.txt, Export.cpp, and the HTTP debt file.
Local ABI/test-quality helper checks Could not run because those helper scripts are absent from the isolated PR snapshot.
Hosted CI Exact-head conventions, labels, eligibility, and report passed; product and platform jobs were skipped.
Focused cookie tests and sanitizers Reported by the author as passing on the PR head; not independently run here.
Unedited relevant output

Conventions:

All conventions checks passed.

Stack report:

Target branch tip: `ca073ec3ad0d766ea9f4658e418a5c977001a353`
All heads unchanged: **True**
Dependency order: #9630 → #10535
- PR #9630: **clean** against current base; head `cff855f72618fbee7bde0b866609854017ca5f9b`
- PR #10535: **clean** against current base; head `1fac04e35ee1c594063d9243d08a48445c35a675`
- #9630 → #10535: **current_dependency_head_not_included**; overlapping changed paths: `core/libs/prx/libSceHttp/CMakeLists.txt`, `core/libs/prx/libSceHttp/Export.cpp`, `docs/dev/debt/libSceHttp.md`

Sources

Not verified

The author’s Linux, Windows, and sanitizer results were not independently reproduced. In particular, the earlier combined-stack test report predates the current #9630 head; #9630’s latest report also says it does not claim a new combined-stack run. I did not build or run the composed #9630 + #10535 tests. This is a remaining integration-evidence gap, not a code defect found in this review.

To get this to a good state

After #9630 lands, rebase/compose #10535 in the agreed order and run the allocation-regression target together with the cookie tests, preserving both CMake registrations. I will recheck the resulting head and evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724303014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10535#pullrequestreview-5724303014). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T18:29:45Z. **Review:** COMMENTED --- # Re-checked — new head, integration evidence pending The cookie implementation and its earlier requested fixes are in place, but I cannot verify the final composition with the still-open #9630 dependency at its current head. ## What I ran Reviewed exact PR head `1fac04e35ee1c594063d9243d08a48445c35a675` against PR base `4017310678562c63594d99b8f45db2d68b9aaa6c`; the individual preview against current `main` `ca073ec3ad0d766ea9f4658e418a5c977001a353` is clean. Environment: Linux x86-64, Python 3.11.2, Git 2.39.5. I did not build or compile locally. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 10535 --output-dir /tmp/anyps5-10535-review python3 tools/pr_stack_check.py 10535 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-10535-review/stack gh pr view 9630 -R boykopovar/AnyPS5 --json state,headRefOid,body ``` ## Results | Check | Result | |---|---| | Diff and conventions | Passed. | | Current-main merge preview | Clean for #10535 and #9630 considered individually. | | Declared dependency | #9630 remains open at `cff855f72618fbee7bde0b866609854017ca5f9b`; its current head is not included in #10535 and overlaps `CMakeLists.txt`, `Export.cpp`, and the HTTP debt file. | | Local ABI/test-quality helper checks | Could not run because those helper scripts are absent from the isolated PR snapshot. | | Hosted CI | Exact-head conventions, labels, eligibility, and report passed; product and platform jobs were skipped. | | Focused cookie tests and sanitizers | Reported by the author as passing on the PR head; not independently run here. | <details><summary>Unedited relevant output</summary> Conventions: ```text All conventions checks passed. ``` Stack report: ```text Target branch tip: `ca073ec3ad0d766ea9f4658e418a5c977001a353` All heads unchanged: **True** Dependency order: #9630 → #10535 - PR #9630: **clean** against current base; head `cff855f72618fbee7bde0b866609854017ca5f9b` - PR #10535: **clean** against current base; head `1fac04e35ee1c594063d9243d08a48445c35a675` - #9630 → #10535: **current_dependency_head_not_included**; overlapping changed paths: `core/libs/prx/libSceHttp/CMakeLists.txt`, `core/libs/prx/libSceHttp/Export.cpp`, `docs/dev/debt/libSceHttp.md` ``` </details> ## Sources - [Reviewed cookie-store head](https://github.com/boykopovar/AnyPS5/commit/1fac04e35ee1c594063d9243d08a48445c35a675) - [Current #9630 dependency head](https://github.com/boykopovar/AnyPS5/commit/cff855f72618fbee7bde0b866609854017ca5f9b) - [Exact-head hosted checks](https://github.com/boykopovar/AnyPS5/actions/runs/40332150482) ## Not verified The author’s Linux, Windows, and sanitizer results were not independently reproduced. In particular, the earlier combined-stack test report predates the current #9630 head; #9630’s latest report also says it does not claim a new combined-stack run. I did not build or run the composed #9630 + #10535 tests. This is a remaining integration-evidence gap, not a code defect found in this review. ## To get this to a good state After #9630 lands, rebase/compose #10535 in the agreed order and run the allocation-regression target together with the cookie tests, preserving both CMake registrations. I will recheck the resulting head and evidence.
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!10535
No description provided.