Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

EZP-25482: Fix exception with CSRF protection disabled #515

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions ApplicationConfig/Providers/SessionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class SessionInfo implements Provider

public function __construct(
SessionInterface $session,
CsrfTokenManagerInterface $csrfTokenManager,
$csrfTokenIntention,
RouterInterface $router
RouterInterface $router,
CsrfTokenManagerInterface $csrfTokenManager = null
) {
$this->session = $session;
$this->csrfTokenManager = $csrfTokenManager;
Expand All @@ -46,11 +46,14 @@ public function getConfig()
$sessionInfo['isStarted'] = true;
$sessionInfo['name'] = $this->session->getName();
$sessionInfo['identifier'] = $this->session->getId();
$sessionInfo['csrfToken'] = $this->csrfTokenManager->getToken($this->csrfTokenIntention)->getValue();
$sessionInfo['href'] = $this->generateUrl(
'ezpublish_rest_deleteSession',
['sessionId' => $this->session->getId()]
);

if ($this->csrfTokenManager instanceof CsrfTokenManagerInterface) {
$sessionInfo['csrfToken'] = $this->csrfTokenManager->getToken($this->csrfTokenIntention)->getValue();
}
}

return $sessionInfo;
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ services:
class: %ezsystems.platformui.application_config.provider.session_info.class%
arguments:
- @session
- @security.csrf.token_manager
- %ezpublish_rest.csrf_token_intention%
- @router
- @?security.csrf.token_manager
tags:
- {name: ezsystems.platformui.application_config_provider, key: 'sessionInfo'}

Expand Down
20 changes: 20 additions & 0 deletions Tests/ApplicationConfig/Providers/SessionInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ public function testGetConfig()
);
}

public function testGetConfigWithoutTokenManager()
{
$provider = new SessionInfo(
$this->createSession(),
null,
'intention',
$this->getRouterMock('/api/ezp/v2/user/sessions/the_session_id')
);

self::assertEquals(
[
'isStarted' => true,
'name' => 'the_session_name',
'identifier' => 'the_session_id',
'href' => '/api/ezp/v2/user/sessions/the_session_id',
],
$provider->getConfig()
);
}

/**
* @return \Symfony\Component\HttpFoundation\Session\SessionInterface|\PHPUnit_Framework_MockObject_MockObject
*/
Expand Down