Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9dbde41

Browse files
committed
feature#27976 [Security] Remember me: allow to set the samesite cookie flag (dunglas)
This PR was merged into the 4.2-dev branch.Discussion----------[Security] Remember me: allow to set the samesite cookie flag| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks? | no <!-- seehttps://symfony.com/bc -->| Deprecations? |no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass? | no| Fixed tickets | no| License | MIT| Doc PR |symfony/symfony-docs#10077This PR allows to set the [`samesite`](https://www.owasp.org/index.php/SameSite) cookie flag for remember me token cookies.Commits-------337e8ef [Security] Remember me: allow to set the samesite cookie flag
2 parents7b853bb +337e8ef commit9dbde41

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class RememberMeFactory implements SecurityFactoryInterface
2525
'domain' =>null,
2626
'secure' =>false,
2727
'httponly' =>true,
28+
'samesite' =>null,
2829
'always_remember_me' =>false,
2930
'remember_me_parameter' =>'_remember_me',
3031
);

‎src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ protected function cancelCookie(Request $request)
271271
$this->logger->debug('Clearing remember-me cookie.',array('name' =>$this->options['name']));
272272
}
273273

274-
$request->attributes->set(self::COOKIE_ATTR_NAME,newCookie($this->options['name'],null,1,$this->options['path'],$this->options['domain'],$this->options['secure'],$this->options['httponly']));
274+
$request->attributes->set(self::COOKIE_ATTR_NAME,newCookie($this->options['name'],null,1,$this->options['path'],$this->options['domain'],$this->options['secure'],$this->options['httponly'],false,$this->options['samesite'] ??null));
275275
}
276276

277277
/**

‎src/Symfony/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServices.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ protected function processAutoLoginCookie(array $cookieParts, Request $request)
8484
$this->options['path'],
8585
$this->options['domain'],
8686
$this->options['secure'],
87-
$this->options['httponly']
87+
$this->options['httponly'],
88+
false,
89+
$this->options['samesite'] ??null
8890
)
8991
);
9092

@@ -117,7 +119,9 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
117119
$this->options['path'],
118120
$this->options['domain'],
119121
$this->options['secure'],
120-
$this->options['httponly']
122+
$this->options['httponly'],
123+
false,
124+
$this->options['samesite'] ??null
121125
)
122126
);
123127
}

‎src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
8181
$this->options['path'],
8282
$this->options['domain'],
8383
$this->options['secure'],
84-
$this->options['httponly']
84+
$this->options['httponly'],
85+
false,
86+
$this->options['samesite'] ??null
8587
)
8688
);
8789
}

‎src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Component\Security\Http\Tests\RememberMe;
1313

1414
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\HttpFoundation\Cookie;
1516
useSymfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
1617
useSymfony\Component\Security\Core\Exception\UsernameNotFoundException;
1718
useSymfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
@@ -268,7 +269,7 @@ public function testLoginFail()
268269

269270
publicfunctiontestLoginSuccessSetsCookieWhenLoggedInWithNonRememberMeTokenInterfaceImplementation()
270271
{
271-
$service =$this->getService(null,array('name' =>'foo','domain' =>'myfoodomain.foo','path' =>'/foo/path','secure' =>true,'httponly' =>true,'lifetime' =>3600,'always_remember_me' =>true));
272+
$service =$this->getService(null,array('name' =>'foo','domain' =>'myfoodomain.foo','path' =>'/foo/path','secure' =>true,'httponly' =>true,'samesite' => Cookie::SAMESITE_STRICT,'lifetime' =>3600,'always_remember_me' =>true));
272273
$request =newRequest();
273274
$response =newResponse();
274275

@@ -305,6 +306,7 @@ public function testLoginSuccessSetsCookieWhenLoggedInWithNonRememberMeTokenInte
305306
$this->assertTrue($cookie->getExpiresTime() >time() +3590 &&$cookie->getExpiresTime() <time() +3610);
306307
$this->assertEquals('myfoodomain.foo',$cookie->getDomain());
307308
$this->assertEquals('/foo/path',$cookie->getPath());
309+
$this->assertSame(Cookie::SAMESITE_STRICT,$cookie->getSameSite());
308310
}
309311

310312
protectedfunctionencodeCookie(array$parts)

‎src/Symfony/Component/Security/Http/Tests/RememberMe/TokenBasedRememberMeServicesTest.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Component\Security\Http\Tests\RememberMe;
1313

1414
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\HttpFoundation\Cookie;
1516
useSymfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
1617
useSymfony\Component\Security\Core\Exception\UsernameNotFoundException;
1718
useSymfony\Component\HttpFoundation\Request;
@@ -205,7 +206,7 @@ public function testLoginSuccessIgnoresTokensWhichDoNotContainAnUserInterfaceImp
205206

206207
publicfunctiontestLoginSuccess()
207208
{
208-
$service =$this->getService(null,array('name' =>'foo','domain' =>'myfoodomain.foo','path' =>'/foo/path','secure' =>true,'httponly' =>true,'lifetime' =>3600,'always_remember_me' =>true));
209+
$service =$this->getService(null,array('name' =>'foo','domain' =>'myfoodomain.foo','path' =>'/foo/path','secure' =>true,'httponly' =>true,'samesite' => Cookie::SAMESITE_STRICT,'lifetime' =>3600,'always_remember_me' =>true));
209210
$request =newRequest();
210211
$response =newResponse();
211212

@@ -240,6 +241,7 @@ public function testLoginSuccess()
240241
$this->assertTrue($cookie->getExpiresTime() >time() +3590 &&$cookie->getExpiresTime() <time() +3610);
241242
$this->assertEquals('myfoodomain.foo',$cookie->getDomain());
242243
$this->assertEquals('/foo/path',$cookie->getPath());
244+
$this->assertSame(Cookie::SAMESITE_STRICT,$cookie->getSameSite());
243245
}
244246

245247
protectedfunctiongetCookie($class,$username,$expires,$password)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp