Skip to content

Commit 03219b9

Browse files
committed
[Security] Fix wrong cache directive when using the new PUBLIC_ACCESS attribute
1 parent 51220b3 commit 03219b9

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Firewall/AccessListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ public function authenticate(RequestEvent $event)
7575
$attributes = $request->attributes->get('_access_control_attributes');
7676
$request->attributes->remove('_access_control_attributes');
7777

78-
if (!$attributes || ([AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY] === $attributes && $event instanceof LazyResponseEvent)) {
78+
if (
79+
!$attributes
80+
|| (
81+
([AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY] === $attributes || [AuthenticatedVoter::PUBLIC_ACCESS] === $attributes)
82+
&& $event instanceof LazyResponseEvent
83+
)
84+
) {
7985
return;
8086
}
8187

Tests/Firewall/AccessListenerTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,41 @@ public function testHandleMWithultipleAttributesShouldBeHandledAsAnd()
360360

361361
$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST));
362362
}
363+
364+
public function testLazyPublicPagesShouldNotAccessTokenStorage()
365+
{
366+
$tokenStorage = $this->createMock(TokenStorageInterface::class);
367+
$tokenStorage->expects($this->never())->method('getToken');
368+
369+
$request = new Request();
370+
$accessMap = $this->createMock(AccessMapInterface::class);
371+
$accessMap->expects($this->any())
372+
->method('getPatterns')
373+
->with($this->equalTo($request))
374+
->willReturn([[AuthenticatedVoter::PUBLIC_ACCESS], null])
375+
;
376+
377+
$listener = new AccessListener($tokenStorage, $this->createMock(AccessDecisionManagerInterface::class), $accessMap, $this->createMock(AuthenticationManagerInterface::class), false);
378+
$listener(new LazyResponseEvent(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST)));
379+
}
380+
381+
/**
382+
* @group legacy
383+
*/
384+
public function testLegacyLazyPublicPagesShouldNotAccessTokenStorage()
385+
{
386+
$tokenStorage = $this->createMock(TokenStorageInterface::class);
387+
$tokenStorage->expects($this->never())->method('getToken');
388+
389+
$request = new Request();
390+
$accessMap = $this->createMock(AccessMapInterface::class);
391+
$accessMap->expects($this->any())
392+
->method('getPatterns')
393+
->with($this->equalTo($request))
394+
->willReturn([[AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY], null])
395+
;
396+
397+
$listener = new AccessListener($tokenStorage, $this->createMock(AccessDecisionManagerInterface::class), $accessMap, $this->createMock(AuthenticationManagerInterface::class), false);
398+
$listener(new LazyResponseEvent(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST)));
399+
}
363400
}

0 commit comments

Comments
 (0)