Skip to content

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

Merged
Girgias merged 2 commits into
php:masterfrom
jorgsowa:fix/session-samesite-validation
May 2, 2026
Merged

ext/session: Validate SameSite cookie attribute against allowed values#21670
Girgias merged 2 commits into
php:masterfrom
jorgsowa:fix/session-samesite-validation

Conversation

@jorgsowa

Copy link
Copy Markdown
Contributor

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.

Comment threadext/session/tests/session_set_cookie_params_variation6.phpt
Comment threadext/session/tests/session_set_cookie_params_variation6.phpt Outdated
@jorgsowa
jorgsowa requested a review from GirgiasApril 8, 2026 21:49

@GirgiasGirgias 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!

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
jorgsowaforce-pushed the fix/session-samesite-validation branch from a172eb2 to d4ba333CompareApril 29, 2026 18:15
@Girgias
Girgias merged commit c130d42 into php:masterMay 2, 2026
19 checks passed
Girgias pushed a commit that referenced this pull request May 24, 2026
Add NEWS entries for three ext/session changes that were never documented:
- SameSite cookie validation (GH-21670)
- session.cookie_lifetime improved parsing (GH-21704)
- Recursive GC cleanup for nested session directories (GH-21491)
@jorgsowa
jorgsowa deleted the fix/session-samesite-validation branch June 3, 2026 21:39
Sign up for freeto 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

@jorgsowa@Girgias