Repository navigation
Harden RFC 10025 cookie parsing - #1086
asllanmaciel wants to merge 2 commits into
Conversation
|
One thing we may want to reconsider before merging this: RFC 6265 has been obsoleted by RFC 10025, and the newer Set-Cookie parsing algorithm is slightly stricter than what this PR currently tests. RFC 10025 first requires a user agent to reject the entire i.e. CTLs excluding HTAB. Only after that validation does it remove leading/trailing So the This also suggests that the hardening may need two separate pieces: WSP trimming ( |
|
Good catch on RFC 10025. I updated the PR in 9bdaa17: the cookie WSP constant now references RFC 10025, all %x00-08 / %x0A-1F / %x7F controls are rejected by direct Cookie::parse(), and parse_from_headers() ignores only the invalid Set-Cookie entry so other response cookies continue to be processed. I also replaced the VT-preservation expectation with data-driven coverage for all 32 disallowed control values plus a mixed valid/invalid response-header case. The new tests were RED before the change and are GREEN now (165 focused tests / 440 assertions); lint and changed-file PHPCS pass, and the full-suite failure count is identical to a clean develop baseline. |
Pull Request Type
This is a:
Context
Follow-up to #1084 after #1083. The initial patch narrowed cookie whitespace trimming to protocol WSP (
SP / HTAB). During review, RFC 10025 was identified as the current cookie specification (it obsoletes RFC 6265) and adds an important first parsing step: aSet-Cookiestring containing%x00-08 / %x0A-1F / %x7Fmust be ignored.This update separates those two responsibilities instead of treating all control characters as trim candidates.
Fixes #1084.
Detailed Description
Trim::WHITESPACE_CHARS_RFC10025and keeps normalization limited toSP / HTAB;Cookie::parse()rejects such direct inputs withInvalidArgumentinstead of silently normalizing them;Cookie::parse_from_headers()ignores an invalidSet-Cookieentry and continues processing the other response cookies, matching the RFC's user-agent parsing behavior;RFC reference: https://www.rfc-editor.org/rfc/rfc10025#section-5.6
Quality assurance
Validation on PHP 8.3.14 / PHPUnit 10.5.64:
composer lint: 176 files — PASS;git diff --check— PASS;developbaseline (6200ba9a): 3,202 tests / 5,410 assertions, the same 50 failures and 6 warnings. The baseline failures are unrelated environment/integration failures (public test-server redirects/proxy availability), so this patch adds no full-suite regressions.Documentation
No public API feature is added; the behavior is protocol hardening and is covered inline by the RFC-linked comments/tests.
AI assistance
AI-assisted tooling was used to investigate the RFC change, prepare the tests/patch, and compare the branch against a clean upstream baseline. The final code, test results, and scope were reviewed directly by the contributor.