Skip to content

feat(libSceHttp2): store cookies in cookie boxes - #10534

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
noamroger:claude/project-thread-io5xtc
Oct 26, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
noamroger:claude/project-thread-io5xtc

Conversation

@noamroger

@noamroger noamroger commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Gives the cookie boxes sceHttp2CreateCookieBox already creates a real cookie store, in a new Cookies.cpp so it stays out of the transport work in Export.cpp:

  • sceHttp2AddCookie, sceHttp2GetCookie, sceHttp2GetCookieStats, sceHttp2SetCookieMaxNum, sceHttp2SetCookieMaxNumPerDomain and sceHttp2SetCookieMaxSize, with signatures from SharpProspero's Http2.cs, declared in include/Http2.hpp.
  • Behavior follows a run of this PR's test sequence against firmware 13.42's libSceHttp2.sprx (thanks to the reviewer who ran it): error codes, the no-match error, required = header length + 3, no scheme check, refused foreign Domain, cookies without =, prefix/suffix matching, the 4096/50 default limits, oldest-first eviction, a limit of 0, and the 32-byte stats with their size accounting. Expiry keeps the RFC 6265 date algorithm, which matched every tested date.
  • sceHttp2CreateCookieBox maps its pool from flexible memory as 13.42 does and returns the kernel's error unchanged. sceHttp2CookieFlush empties a box and sceHttp2DeleteCookieBox drops its cookies.
  • sceHttp2GetCookieBox/SetCookieBox are untouched (feat(http2): add synchronous HTTP/2 transport over TLS #10167 changes them).

What is still assumed (default total limit, the bytes after the header, the stack check that is not reproduced) is listed in docs/dev/debt/libSceHttp2.md.

Tested

  • Linux x86-64, GCC: GuestHttp2Cookies.cpp (registered as guest_http2_cookies) passes plain and under ASan/UBSan, built by hand against Export.cpp and Cookies.cpp with the kernel's flexible-memory calls stubbed. tools/check_conventions.py --base origin/main passes.
  • Windows 11 (WinLibs GCC 15.2.0, Release): an earlier head (9bcdf99c59) was built and passed 3 of 3 runs by a reviewer; the current head has not been rerun there.
  • Expected values come from the 13.42 run described above; not run on a console by me.

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

Generated with Claude Code

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Progress report (afc780e → 93f7df5)

📈 System libraries: 51.01% (+0.05%, +7 implemented functions)

✅ 7 implemented
Library Name
libSceHttp2 sceHttp2AddCookie
libSceHttp2 sceHttp2CookieFlush
libSceHttp2 sceHttp2GetCookie
libSceHttp2 sceHttp2GetCookieStats
libSceHttp2 sceHttp2SetCookieMaxNum
libSceHttp2 sceHttp2SetCookieMaxNumPerDomain
libSceHttp2 sceHttp2SetCookieMaxSize

Changed libraries (implemented exports)

Library Before After Change
libSceHttp2 5/62 (8.06%) 12/62 (19.35%) +11.29 pp

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9598 core/libs/prx/libSceHttp2/CMakeLists.txt
core/libs/prx/libSceHttp2/Export.cpp
docs/dev/debt/libSceHttp2.md
PR 11145 core/libs/prx/libSceHttp2/CMakeLists.txt
core/libs/prx/libSceHttp2/Export.cpp
core/libs/tests/GuestHttp2.cpp
docs/dev/debt/libSceHttp2.md
PR 11470 core/libs/prx/libSceHttp2/CMakeLists.txt
core/libs/prx/libSceHttp2/Export.cpp
core/libs/tests/GuestHttp2.cpp
docs/dev/debt/libSceHttp2.md
PR 11518 core/libs/tests/GuestHttp2.cpp

@MarcZX10 MarcZX10 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.

The oversized-pool guard throws std::overflow_error from this guest-facing extern "C" API. A guest can reach this path with a poolSize above SIZE_MAX - 0x3fff, so the overflow is converted into a C++ exception crossing the ABI boundary (or terminating the process if it is not caught). Please return the project/API error code for an invalid or unrepresentable pool size instead, and add a regression that passes a near-SIZE_MAX value and verifies a normal error return without allocation or exception escape. The ordinary cookie tests and PR checks do not exercise this input.

@noamroger

Copy link
Copy Markdown
Contributor Author

Fixed in 62c4148: sceHttp2CreateCookieBox now returns 0x817B1022 (out of memory, as prosper names it) when the pool size cannot be rounded or allocated, using a non-throwing allocation, so no C++ exception crosses the ABI. GuestHttp2Cookies.cpp covers SIZE_MAX, SIZE_MAX - 0x3fff, SIZE_MAX - 0x4000 and SIZE_MAX / 2. The code is listed in the libSceHttp2 debt file as not measured on a console.

@noamroger
noamroger requested a review from MarcZX10 October 24, 2026 11:36

@MarcZX10 MarcZX10 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.

The current head addresses the reported oversized-pool path: rounding overflow and failed array allocation now return the out-of-memory code, and tests cover near-SIZE_MAX inputs. The focused ASan/UBSan run is author-reported; hosted structural checks pass, while product builds are skipped. Please resolve the remaining direct overlap before merge: #10167 changes sceHttp2CookieFlush, sceHttp2CreateCookieBox and sceHttp2DeleteCookieBox in the same Export.cpp, while this PR implements those functions against its cookie store. The current #10167 version makes CookieFlush throw and changes the Create/Delete handle operations, so the behavior cannot be combined by a simple file rebase. Coordinate with its author on an order and the intended composed behavior, then record the dependency/order in this PR. Also coordinate the shared CMake/test relocation with #6044 so GuestHttp2Cookies and its registration are preserved.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 25, 2026
@BunnyFl

BunnyFl commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

The debt entry says errors, limits and accounting are assumed, so I ran this PR's GuestHttp2Cookies.cpp sequence against firmware 13.42's own libSceHttp2.sprx (sha256 a4f48d9e99a9b64137efee483c3050b857d79fe200f8d88e30f6f825fa8c84bb), loaded natively on x86-64. Its sceHttpUri* imports went to 13.42's libSceHttp.sprx (2b909058...58cd) and sceRtcParseDateTime to 13.42's libSceRtc.sprx (93146785...0e9d), also loaded natively. Memory, mutexes and the clock were host stand-ins. No sceHttp2Init call was needed for cookie boxes. Three runs, identical output.

Same as this PR: ids that don't exist, or a deleted box, give 0x817B1100. A pool below 0x10000 gives 0x817B121D. A buffer that is too small gives 0x817B1104. Secure cookies go only to https. Max-Age=0 and a past Expires delete a cookie, and an unparsable Expires leaves a session cookie. cookieLength cuts the string ("cut=12345", 5 is cut=1). The stats peaks survive CookieFlush, and the invalid-id cases in the test match on all six calls.

Different on 13.42:

  • No match: GetCookie returns 0x817B1025 and leaves *required unwritten (the PR returns 0 with required 1). This covers an empty box, another host, and an empty or hostless URL.
  • required: it is the header length + 3 ("a=1" gives 6, "sid=1; wide=1; lang=fr" gives 25). With a too-small buffer, *required is not written but cookie[0] is set to 0; the PR's test expects required == 27 there. A NULL required with a large enough buffer is accepted and the header is written.
  • NULL arguments give 0x817B11FE, not 0x817B1225: NULL url in Add/Get, NULL cookie in Add, NULL stats, NULL buffer and NULL required together, and Add with cookieLength 0. GetCookieStats(0, NULL) gives 0x817B11FE, so NULL is checked before the id there.
  • No scheme check: ftp://example.com/ and example.com/ are accepted by Add and Get and match example.com cookies. http:///path and "" give 0x817B1219 in Add (the PR's test expects 0x817B3060 for http:///path).
  • Domain attribute that doesn't cover the host: "evil=1; Domain=other.com" and "evil=1; Domain=ample.com" set from example.com give 0x817B1219 (the PR returns 0).
  • Stored, not ignored: "noequals" and "=value" are kept and sent as noequals and value.
  • Matching: a Path=/a cookie is sent to /ab, and a host-only cookie set by example.com is sent to www.example.com. https://example.com/a/b?q#f gives sid=1; wide=1; token=x; lang=fr.
  • Size limit: a cookie whose name+value is over the max size is refused with 0x817B1104. The default allows name+value 4096 and refuses 4097. With max 4, "abc=defg" is refused and "ab=cd" stored. SetCookieMaxSize(0) refuses every cookie (0x817B1104), so every later Add in the PR's test is refused.
  • Eviction is by age, not last use:
    • Per-domain limit (default 50): each Add over the limit removes the oldest cookie of that domain, even one that was just read. The 51st and 52nd cookie each removed one, and of 60, c0-c9 went although c0 had just been read. With limit 2, after d1, d2, a read and d3, the box holds d2, d3.
    • Total limit: with SetCookieMaxNum(2) and three cookies stored, adding a fourth removed all three.
    • A limit of 0 is not "no limit": after SetCookieMaxNum(0) or SetCookieMaxNumPerDomain(0), 60 Adds leave 1 cookie (59 removed).
    • Re-running the PR's limit steps with the default max size: c=1; ab=cd, d=1; c=1, e=1; d=1, then only t=1 is left (removedNum 5, not 4).
  • Stats: 32 bytes are written. The PR's reserved at +32 is left as it was, so the test's reserved == 0 after memset(0xff) fails. currentInuseSize counts name + value + domain (without a leading dot) + path + 5: ab=cd on example.com path / is 21, name=value; Path=/x from www.example.com adds 31, and d=1; Domain=.example.com; Path=/longer/path adds 30.
  • CreateCookieBox sizes: the pool is rounded up to a multiple of 0x4000 and mapped with sceKernelMapNamedFlexibleMemory. For SIZE_MAX the rounded size is 0. A failing map's error code is returned unchanged (checked with two different codes), not 0x817B1022.
  • Stack check: AddCookie, GetCookie, GetCookieStats, SetCookieMaxNum and CreateCookieBox return 0x817B1076 when the thread's stack has less than 0x1FD0 bytes left; the cookie in that Add was not stored.

Not checked: the default total limit, and the clock-dependent parts beyond the cases above.

@wachi35676

Copy link
Copy Markdown
Contributor

Tested head 9bcdf99c59 merged onto main 14eb2cda22 on Windows 11 (WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON). This adds the Windows run to the Linux one in the description.

  • The tree configures with the new test registration, and guest_http2_cookies build and pass 3 of 3 runs on Windows.

AI-assisted: yes (Claude Code); results above were run on this machine.

@noamroger

Copy link
Copy Markdown
Contributor Author

Thanks a lot for running the sequence against the real module, this is exactly what the debt entry was missing. Pushed 172a0cc, which follows your results:

  • GetCookie: no match returns 0x817B1025 with *required untouched (empty box, other host, empty or hostless URL); required is the header length + 3; a too-small buffer gets cookie[0] = 0 and leaves required alone; a NULL required with a large enough buffer is accepted.
  • NULL arguments and cookieLength 0 return 0x817B11FE; GetCookieStats checks NULL before the id.
  • No scheme check (ftp://example.com/ and example.com/ work); a hostless URL or a Domain that doesn't cover the host is refused in AddCookie with 0x817B1219.
  • noequals and =value are stored and sent back as noequals and value.
  • Matching: plain path prefix, the default path keeps its trailing slash, and host-only cookies reach subdomains. Equal-length paths come back as in your runs (the first stored comes last), so https://example.com/a/b?q#f gives sid=1; wide=1; token=x; lang=fr.
  • Limits: 4096 and 50 by default, an oversized cookie returns 0x817B1104, SetCookieMaxSize(0) refuses everything, eviction drops the oldest stored cookies, and past MaxNum the oldest 10 (or all of them, if fewer) go at once. The limit steps now end with t=1 and removedNum 5, and a limit of 0 leaves 1 cookie after 60 adds.
  • Stats are 32 bytes with bytes 12-15 untouched, and the size counts name + value + domain + path + 5.
  • CreateCookieBox rounds to 0x4000 (wrapping for SIZE_MAX), maps with sceKernelMapNamedFlexibleMemory and returns its error unchanged.

The test asserts all of these, so it encodes your measurements. Not reproduced: the 0x817B1076 stack check. Still assumed and listed in the debt file: the default total limit (3000, libSceHttp's value), the NUL/space/NUL after the header (libSceHttp's, consistent with + 3), and the mapping name. If you still have the setup, the default total limit is the one measurement I'm missing.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@adriadam10 adriadam10 self-assigned this Oct 26, 2026
noamroger and others added 2 commits October 26, 2026 20:10
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VcCKPwMu3oNWaS8AUph6MW
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the claude/project-thread-io5xtc branch from 172a0cc to 93f7df5 Compare October 26, 2026 19:17
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 26, 2026 19:20

Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@adriadam10
adriadam10 merged commit cf69e44 into boykopovar:main Oct 26, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto current main (the HTTP/2 transport from #10167 touched the same Export.cpp, CMakeLists.txt and debt file; squashed into one commit) and added one commit: GuestHttp2.cpp expected sceHttp2CookieFlush to throw, it now returns 0 on a cookie box.

Checked the six cookie exports against the 13.42 run in this thread (error codes, no-match, required = length + 3, 4096/50 limits, oldest-first eviction, 32-byte stats), the oversized-pool path (error code, no exception), and the debt entries. Full ctest on the rebased head: 170/170 pass; merged.

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.

5 participants