Skip to content

fix(Security): prevent TypeError when CSRF cookie is an array - #10724

Merged
michalsn merged 2 commits into
codeigniter4:developfrom
gr8man:fix/csrf-cookie-array-typeerror
Nov 5, 2026
Merged

michalsn merged 2 commits into
codeigniter4:developfrom
gr8man:fix/csrf-cookie-array-typeerror

Conversation

@gr8man

@gr8man gr8man commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description
Fixes a TypeError in Security::__construct() when the CSRF cookie contains array data (e.g., Cookie: csrf_cookie_name[malicious]=array).

IncomingRequest::getCookie() can return an array, which caused a fatal TypeError when assigned to typed property private ?string $hashInCookie, resulting in an HTTP 500 response for affected requests. Any non-string cookie value is now safely treated as null, allowing a clean CSRF hash to be generated.

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

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 4, 2026
@gr8man
gr8man force-pushed the fix/csrf-cookie-array-typeerror branch from 50248c5 to 6916525 Compare November 4, 2026 20:03

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please change "unhandled HTTP 500 error / DoS" to "HTTP 500 response for affected requests" in the PR description. The TypeError reaches the framework's exception handler, which returns a 500. A malformed cookie can repeatedly fail requests that initialize the Security service, but this does not establish an application-wide or server-wide DoS.

Please also add a brief entry under Bugs Fixed in the current changelog.

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@michalsn
michalsn merged commit 72451b2 into codeigniter4:develop Nov 5, 2026
60 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.

4 participants