fix(Cookie): validate cookie path and domain attributes - #10527
Open
gr8man wants to merge 3 commits into
Open
Conversation
gr8man
force-pushed
the
fix/cookie-validate-path-domain
branch
from
September 5, 2026 21:00
b5e5f79 to
a3ad401
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Non-raw prefixes still bypass validation and can cause setcookie() to throw a ValueError.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds cookie attribute validation to prevent header injection and native PHP ValueErrors. Review assumes the develop base branch.
Changes:
- Validates cookie paths, domains, and prefixes.
- Defaults nullable cookie options safely.
- Adds tests, messages, and documentation.
File summaries
| File | Description |
|---|---|
system/Cookie/Cookie.php |
Implements normalization and validation. |
system/Cookie/Exceptions/CookieException.php |
Adds validation exceptions. |
system/Language/en/Cookie.php |
Adds error messages. |
tests/system/Cookie/CookieTest.php |
Adds regression coverage. |
user_guide_src/source/libraries/cookies.rst |
Documents attribute validation. |
user_guide_src/source/changelogs/v4.7.5.rst |
Records the fix. |
Review details
Suppressed comments (1)
system/Cookie/Cookie.php:458
withPrefix()has the same non-raw bypass: an invalid prefix is stored unchanged and later causes nativesetcookie()to throw because prefixes are not URL-encoded bygetPrefixedName(). Prefix character validation must run regardless of the cookie's raw mode.
$this->validateName($prefix, $this->raw);
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
NUL-containing prefixes still bypass validation and may reach PHP’s native cookie functions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Balanced
michalsn
reviewed
Sep 7, 2026
- Prohibit only PHP-rejected characters and NUL in cookie prefixes to preserve compatibility with separators like ':' and '/' - Update cookie prefix validation documentation in User Guide - Separate Cookie raw value fix and path/domain/prefix validation entries in changelog and remove RFC 6265 reference - Add test coverage for PHP-prohibited prefix characters and allowed separators
gr8man
force-pushed
the
fix/cookie-validate-path-domain
branch
from
September 7, 2026 18:38
6ed2d2f to
ba58d55
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Validates cookie
path,domain, andprefixattributes against reserved characters (",; \t\r\n\v\f\0") to prevent CRLF injection in raw cookies and avoid fatalValueErrors from PHP's nativesetcookie()andsetrawcookie(). Also ensuresnullattribute options safely fall back to defaults in the constructor.Checklist: