Skip to content

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

Merged
paulbalandan merged 1 commit into
codeigniter4:developfrom
gr8man:fix/cookie-raw-crlf
Sep 4, 2026
Merged

fix(Cookie): validate raw cookie values#10516
paulbalandan merged 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

@paulbalandan paulbalandan added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 4, 2026
@paulbalandan
paulbalandan merged commit 17b02c4 into codeigniter4:develop Sep 4, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants