Skip to content
This repository has been 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 1 commit
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
7 changes: 5 additions & 2 deletions ApplicationConfig/Providers/SessionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SessionInfo implements Provider

public function __construct(
SessionInterface $session,
CsrfTokenManagerInterface $csrfTokenManager,
CsrfTokenManagerInterface $csrfTokenManager = null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot have a default value here. If you want to add null as default value, you must move the argument at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn it! Slipped through my fingers!

But then it's a breaking change :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes, but it should be OK IMHO. And btw the service should be marked private

Copy link
Contributor Author

@emodric emodric Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes, but it should be OK IMHO.

Okay, fixed.

And btw the service should be marked private

It already is? Or you meant Symfony DIC service? Any reason why?

$csrfTokenIntention,
RouterInterface $router
) {
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,7 +60,7 @@ services:
class: %ezsystems.platformui.application_config.provider.session_info.class%
arguments:
- @session
- @security.csrf.token_manager
- @?security.csrf.token_manager
- %ezpublish_rest.csrf_token_intention%
- @router
tags:
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