You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Cookie.php
+16-3Lines changed: 16 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ class Cookie
27
27
protected$httpOnly;
28
28
private$raw;
29
29
private$sameSite;
30
+
private$secureDefault = false;
30
31
31
32
constSAMESITE_LAX = 'lax';
32
33
constSAMESITE_STRICT = 'strict';
@@ -72,15 +73,19 @@ public static function fromString($cookie, $decode = false)
72
73
* @param int|string|\DateTimeInterface $expire The time the cookie expires
73
74
* @param string $path The path on the server in which the cookie will be available on
74
75
* @param string|null $domain The domain that the cookie is available to
75
-
* @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
76
+
* @param bool|null $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client or null to set it later using {@see setSecureDefault()}
76
77
* @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol
77
78
* @param bool $raw Whether the cookie value should be sent with no url encoding
78
79
* @param string|null $sameSite Whether the cookie will be available for cross-site requests
@trigger_error(sprintf('The default value of the 6th "$secure" argument of "%s"\'s constructor will change from "false" to "null" in Symfony 5.0, you should define its value explicitly when calling it to prevent any unwanted behavior change. Setting it to "null" will auto-enable the "secure" attribute when an HTTPS request comes in.', __METHOD__), E_USER_DEPRECATED);
87
+
}
88
+
84
89
// from PHP source code
85
90
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
86
91
thrownew \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
@@ -232,7 +237,7 @@ public function getPath()
232
237
*/
233
238
publicfunctionisSecure()
234
239
{
235
-
return$this->secure;
240
+
return$this->secure ?? $this->secureDefault;
236
241
}
237
242
238
243
/**
@@ -274,4 +279,12 @@ public function getSameSite()
274
279
{
275
280
return$this->sameSite;
276
281
}
282
+
283
+
/**
284
+
* @param bool $default The default value of the "secure" flag when it is set to null
@trigger_error(sprintf('The default value of the 4th "$secure" argument of method "%s()" will change from "false" to "null" in Symfony 5.0, you should define its value explicitly when calling the method to prevent any unwanted behavior change. Setting it to "null" will auto-enable the "secure" attribute when an HTTPS request comes in.', __METHOD__), E_USER_DEPRECATED);
@@ -176,10 +176,10 @@ public function testToString()
176
176
$cookie = newCookie('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
177
177
$this->assertEquals('foo=bar%20with%20white%20spaces; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly', (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
0 commit comments