Skip to content

ext/session: Validate SameSite cookie attribute against allowed values#21670

Open
jorgsowa wants to merge 2 commits intophp:masterfrom
jorgsowa:fix/session-samesite-validation
Open

ext/session: Validate SameSite cookie attribute against allowed values#21670
jorgsowa wants to merge 2 commits intophp:masterfrom
jorgsowa:fix/session-samesite-validation

Conversation

@jorgsowa
Copy link
Copy Markdown
Contributor

@jorgsowa jorgsowa commented Apr 8, 2026

Applied validation of samesite option in ini, setcookie(), session_set_cookie_params(). Four values are allowed Strict, Lax, None, or empty string. Doc: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value

We can apply similar validation to other values, as a few values are vulnerable to CRLF Injection. I'm not sure it's a security issue, so I will just publish it in the next PRs.

Extract php_is_valid_samesite_value() in ext/standard/head.c as a
shared validation function that enforces the SameSite whitelist
(Strict, Lax, None, or empty string) with case-insensitive matching.

Apply validation in both setcookie()/setrawcookie() (replacing the
existing TODO comment) and the session.cookie_samesite INI handler.
Previously arbitrary strings including CRLF sequences were accepted
and appended verbatim into the Set-Cookie header.
@jorgsowa jorgsowa force-pushed the fix/session-samesite-validation branch from 4bcb52d to d1d79ac Compare April 8, 2026 09:52
@jorgsowa jorgsowa requested a review from Girgias April 8, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants