Skip to content

fix(Cookie): validate raw cookie values - #10516

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/cookie-raw-crlf
Open

fix(Cookie): validate raw cookie values#10516
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/cookie-raw-crlf

Conversation

@gr8man

@gr8man gr8man commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Description
When a Cookie is created with raw: true, values containing characters rejected by PHP's setrawcookie() (control characters, whitespace, tabs, commas, semicolons, and null bytes) previously bypassed validation during instantiation and only failed later when emitted.

This PR adds fail-fast validation in Cookie (__construct(), withValue(), withRaw(), and fromHeaderString()) to match setrawcookie() constraints:

  • Adds validateValue() to check against invalid raw characters
  • Adds CookieException::forInvalidCookieValue() and language string
  • Adds comprehensive unit test coverage for all rejected characters and fromHeaderString()
  • Updates User Guide and changelog

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants