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

Appearance settings

[Security] Fixed PUBLIC_ACCESS in authenticated sessions #37031

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Also check PUBLIC_ACCESS for authenticated tokens
Currently, authenticated users are denied access for pages that have
PUBLIC_ACCESS, as this attribute is only checked when no token was set.
  • Loading branch information
wouterj committed May 31, 2020
commit 0ac530f4608aa773f7db2749a3ec53cdfccaf0a6
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ public function authenticate(RequestEvent $event)
return;
}

if ([self::PUBLIC_ACCESS] === $attributes) {
return;
if ([self::PUBLIC_ACCESS] !== $attributes) {
throw $this->createAccessDeniedException($request, $attributes);
}
}

throw $this->createAccessDeniedException($request, $attributes);
if ([self::PUBLIC_ACCESS] === $attributes) {
return;
}

if (!$token->isAuthenticated()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Http\AccessMapInterface;
use Symfony\Component\Security\Http\Event\LazyResponseEvent;
use Symfony\Component\Security\Http\Firewall\AccessListener;
Expand Down Expand Up @@ -279,6 +281,33 @@ public function testHandleWhenPublicAccessIsAllowedAndExceptionOnTokenIsFalse()
$this->expectNotToPerformAssertions();
}

public function testHandleWhenPublicAccessWhileAuthenticated()
{
$token = new UsernamePasswordToken(new User('Wouter', null, ['ROLE_USER']), null, 'main', ['ROLE_USER']);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
$request = new Request();

$accessMap = $this->createMock(AccessMapInterface::class);
$accessMap->expects($this->any())
->method('getPatterns')
->with($this->equalTo($request))
->willReturn([[AccessListener::PUBLIC_ACCESS], null])
;

$listener = new AccessListener(
$tokenStorage,
$this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock(),
$accessMap,
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
false
);

$listener(new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST));

$this->expectNotToPerformAssertions();
}

public function testHandleMWithultipleAttributesShouldBeHandledAsAnd()
{
$request = new Request();
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.