Skip to content

fix: preserve JSON body when CSRF token is sent in header#10064

Open
michalsn wants to merge 3 commits intocodeigniter4:developfrom
michalsn:fix/csrf-with-header
Open

fix: preserve JSON body when CSRF token is sent in header#10064
michalsn wants to merge 3 commits intocodeigniter4:developfrom
michalsn:fix/csrf-with-header

Conversation

@michalsn
Copy link
Member

Description
This PR fixes a regression in CSRF verification introduced in #9969.

When the CSRF token was sent via the X-CSRF-TOKEN header, the CSRF filter could still parse the raw request body as form data and rewrite valid JSON into a URL-encoded string. As a result, IncomingRequest::getJSON() failed for application/json requests.

I am not sure whether this should be patched in 4.7.1 or included in 4.7.2.

Fixes #10063

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

@michalsn michalsn requested a review from paulbalandan March 23, 2026 07:20
@michalsn michalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label Mar 23, 2026
Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

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

Thanks! I'll release a patch tomorrow at the earliest.

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.

Bug: CSRF filter URL-encodes JSON request body in 4.7.1, breaking IncomingRequest::getJSON()

3 participants