Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay signature verification properly #64

Merged
merged 1 commit into from
May 8, 2017
Merged

Conversation

lcobucci
Copy link
Member

@lcobucci lcobucci commented May 7, 2017

As explained on #63 the middleware was always actually trying to verify the signature.
Moving sessionContainer#isEmpty() calls to the end of the expressions delays the initialisation properly.

@lcobucci lcobucci added the bug label May 7, 2017
@lcobucci lcobucci self-assigned this May 7, 2017
@@ -371,8 +372,8 @@ public function testSessionTokenParsingIsDelayedWhenSessionIsNotBeingUsed()
{
/* @var $signer Signer|\PHPUnit_Framework_MockObject_MockObject */
$signer = $this->createMock(Signer::class);

Copy link
Member

Choose a reason for hiding this comment

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

Could you clarify why this test was incorrect without the signature?

Copy link
Member

Choose a reason for hiding this comment

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

Restore this spacing

Copy link
Member Author

@lcobucci lcobucci May 8, 2017

Choose a reason for hiding this comment

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

Could you clarify why this test was incorrect without the signature?

Description of #63

SessionMiddleware#appendToken() always calls SessionInterface#isEmpty() which will initialise the session data.

The test only passes because the token is not signed and then Token#verify() throws an exception that is silently ignored.

Commit message:

Signature verification was never being delayed because an unsecured
token was being used and Token#verify() was throwing an exception
instead.

Do you want me to reword the commit message or is this enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

Restore this spacing

Sure, will do

@@ -248,25 +248,21 @@ public function extractSessionContainer(Token $token = null) : SessionInterface
private function appendToken(SessionInterface $sessionContainer, Response $response, Token $token = null) : Response
{
$sessionContainerChanged = $sessionContainer->hasChanged();
$sessionContainerEmpty = $sessionContainer->isEmpty();
Copy link
Member

Choose a reason for hiding this comment

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

This was cached on purpose to avoid calling isEmpty() twice, since the sessiondata is potentially mutable: can it be restored, or is this removal part of tge fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's part of the fix as described on the PR's decription

Moving sessionContainer#isEmpty() calls to the end of the expressions delays the initialisation properly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically that leads to the question: do we want to keep this lazy initialisation thing or not?

Copy link
Member

Choose a reason for hiding this comment

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

Seen now - this is described in #63

do we want to keep this lazy initialisation thing or not?

Yes, reading/writing to session in each request, as well as running crypto, is otherwise a very good way to keep data-centers warm. Let's not do that :-)

Signature verification was never being delayed because an unsecured
token was being used and `Token#verify()` was throwing an exception
instead.

Closes #63
@lcobucci
Copy link
Member Author

lcobucci commented May 8, 2017

@Ocramius space reverted... do you want me to change anything else?

@Ocramius Ocramius assigned Ocramius and unassigned lcobucci May 8, 2017
@Ocramius Ocramius added this to the 3.0.1 milestone May 8, 2017
@Ocramius
Copy link
Member

Ocramius commented May 8, 2017

🚢

@Ocramius Ocramius merged commit 04844d7 into master May 8, 2017
@Ocramius Ocramius deleted the fix/delay-verification branch May 8, 2017 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants