Skip to content

Commit 119b091

Browse files
blanchonvincentfabpot
authored andcommitted
[Security] Don't send remember cookie for sub request
1 parent d2e951b commit 119b091

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class ResponseListener implements EventSubscriberInterface
2727
*/
2828
public function onKernelResponse(FilterResponseEvent $event)
2929
{
30+
if (!$event->isMasterRequest()) {
31+
return;
32+
}
33+
3034
$request = $event->getRequest();
3135
$response = $event->getResponse();
3236

src/Symfony/Component/Security/Tests/Http/RememberMe/ResponseListenerTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Tests\Http\RememberMe;
1313

14+
use Symfony\Component\HttpKernel\HttpKernelInterface;
1415
use Symfony\Component\Security\Http\RememberMe\ResponseListener;
1516
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
1617
use Symfony\Component\HttpFoundation\Request;
@@ -41,7 +42,22 @@ public function testRememberMeCookieIsSentWithResponse()
4142
$listener->onKernelResponse($this->getEvent($request, $response));
4243
}
4344

44-
public function testRemmeberMeCookieIsNotSendWithResponse()
45+
public function testRememberMeCookieIsNotSendWithResponseForSubRequests()
46+
{
47+
$cookie = new Cookie('rememberme');
48+
49+
$request = $this->getRequest(array(
50+
RememberMeServicesInterface::COOKIE_ATTR_NAME => $cookie,
51+
));
52+
53+
$response = $this->getResponse();
54+
$response->headers->expects($this->never())->method('setCookie');
55+
56+
$listener = new ResponseListener();
57+
$listener->onKernelResponse($this->getEvent($request, $response, HttpKernelInterface::SUB_REQUEST));
58+
}
59+
60+
public function testRememberMeCookieIsNotSendWithResponse()
4561
{
4662
$request = $this->getRequest();
4763

@@ -78,13 +94,15 @@ private function getResponse()
7894
return $response;
7995
}
8096

81-
private function getEvent($request, $response)
97+
private function getEvent($request, $response, $type = HttpKernelInterface::MASTER_REQUEST)
8298
{
8399
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
84100
->disableOriginalConstructor()
85101
->getMock();
86102

87103
$event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
104+
$event->expects($this->any())->method('getRequestType')->will($this->returnValue($type));
105+
$event->expects($this->any())->method('isMasterRequest')->will($this->returnValue($type === HttpKernelInterface::MASTER_REQUEST));
88106
$event->expects($this->any())->method('getResponse')->will($this->returnValue($response));
89107

90108
return $event;

0 commit comments

Comments
 (0)