-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[RFC] Add SameSite parameter to cookie setting functions #10317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ function session_cache_limiter(?string $value = null): string|false {} | |
|
||
function session_cache_expire(?int $value = null): int|false {} | ||
|
||
function session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): bool {} | ||
function session_set_cookie_params(array|int $lifetime_or_options, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null, SameSite $sameSite = SameSite::Lax): bool {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just general feeling impression, the camel case feels out of place whereas is mostly lower case with underscore otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK |
||
|
||
function session_start(array $options = []): bool {} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--TEST-- | ||
session_set_cookie_params() SameSite parameter tests | ||
--EXTENSIONS-- | ||
session | ||
--SKIPIF-- | ||
<?php include('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
ob_start(); | ||
|
||
// Check type errors work | ||
try { | ||
session_set_cookie_params(20, sameSite: new stdClass()); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage(), \PHP_EOL; | ||
} | ||
|
||
// Check ValueError when using SameSite::None and the cookie is not secure, see | ||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite#samesitenone_requires_secure | ||
try { | ||
session_set_cookie_params(20, sameSite: SameSite::None); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), \PHP_EOL; | ||
} | ||
try { | ||
session_set_cookie_params(20, sameSite: SameSite::None, secure: false); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), \PHP_EOL; | ||
} | ||
|
||
// Check get argument count error when using an option array | ||
try { | ||
session_set_cookie_params(['secure' => false], sameSite: SameSite::None); | ||
} catch (\ArgumentCountError $e) { | ||
echo $e->getMessage(), \PHP_EOL; | ||
} | ||
|
||
echo "*** Testing session_set_cookie_params(20, sameSite:) ***\n"; | ||
var_dump(session_set_cookie_params(20, sameSite: SameSite::None, secure: true)); | ||
var_dump(ini_get("session.cookie_samesite")); | ||
var_dump(session_set_cookie_params(20, sameSite: SameSite::Lax, secure: true)); | ||
var_dump(ini_get("session.cookie_samesite")); | ||
var_dump(session_set_cookie_params(20, sameSite: SameSite::Strict, secure: true)); | ||
var_dump(ini_get("session.cookie_samesite")); | ||
// After session started | ||
var_dump(session_start()); | ||
var_dump(session_set_cookie_params(20, sameSite: SameSite::None, secure: true)); | ||
var_dump(ini_get("session.cookie_samesite")); | ||
var_dump(session_set_cookie_params(20, sameSite: SameSite::Lax, secure: true)); | ||
var_dump(ini_get("session.cookie_samesite")); | ||
var_dump(session_set_cookie_params(20, sameSite: SameSite::Strict, secure: true)); | ||
|
||
echo "Done"; | ||
ob_end_flush(); | ||
?> | ||
--EXPECTF-- | ||
session_set_cookie_params(): Argument #6 ($sameSite) must be of type SameSite, stdClass given | ||
session_set_cookie_params(): Argument #6 ($sameSite) can only be SameSite::None if argument #6 ($secure) is true | ||
session_set_cookie_params(): Argument #6 ($sameSite) can only be SameSite::None if argument #6 ($secure) is true | ||
session_set_cookie_params(): Expects exactly 1 arguments when argument #1 ($lifetime_or_options) is an array | ||
*** Testing session_set_cookie_params(20, sameSite:) *** | ||
bool(true) | ||
string(4) "None" | ||
bool(true) | ||
string(3) "Lax" | ||
bool(true) | ||
string(6) "Strict" | ||
bool(true) | ||
|
||
Warning: session_set_cookie_params(): Session cookie parameters cannot be changed when a session is active in %s on line %d | ||
bool(false) | ||
string(6) "Strict" | ||
|
||
Warning: session_set_cookie_params(): Session cookie parameters cannot be changed when a session is active in %s on line %d | ||
bool(false) | ||
string(6) "Strict" | ||
|
||
Warning: session_set_cookie_params(): Session cookie parameters cannot be changed when a session is active in %s on line %d | ||
bool(false) | ||
Done |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this passes, this would be the second native enum. Leaving this link here for reference: #9679 (comment)