Skip to content

fix(Cookie): validate cookie path and domain attributes - #10527

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/cookie-validate-path-domain
Open

fix(Cookie): validate cookie path and domain attributes#10527
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/cookie-validate-path-domain

Conversation

@gr8man

@gr8man gr8man commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Description
Validates cookie path, domain, and prefix attributes against reserved characters (",; \t\r\n\v\f\0") to prevent CRLF injection in raw cookies and avoid fatal ValueErrors from PHP's native setcookie() and setrawcookie(). Also ensures null attribute options safely fall back to defaults in the constructor.

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

@gr8man
gr8man force-pushed the fix/cookie-validate-path-domain branch from b5e5f79 to a3ad401 Compare September 5, 2026 21:00
@michalsn
michalsn requested a balanced review from Copilot September 6, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 native setcookie() to throw because prefixes are not URL-encoded by getPrefixedName(). 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.

Comment thread system/Cookie/Cookie.php

$this->validateName($name, $raw);
if ($prefix !== '') {
$this->validateName($prefix, $raw);
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