Skip to content

[Security][Guard] check if session exist before using it #19218

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

Closed
wants to merge 9 commits into from
Closed

[Security][Guard] check if session exist before using it #19218

wants to merge 9 commits into from

Conversation

pasdeloup
Copy link
Contributor

Q A
Branch? 2.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #18958
License MIT
Doc PR -

As stated by @Shekhovtsovy when the Guard component is used without the Symfony full stack (for instance in Laravel), $request->getSession() may be null.

An additionnal PR will be needed for 3.1 but it may be better to check this one before.

@xabbuh
Copy link
Member

xabbuh commented Jun 29, 2016

Can you please add a test covering the fix?

@pasdeloup
Copy link
Contributor Author

Ok, I will add it.
And I'm surprised to see current tests are not passing on Travis and I don't understand the errors. I'm not sure it's related to this PR, I will check.

@pasdeloup pasdeloup changed the title check if session exist before using it [Security][Guard] check if session exist before using it Jun 29, 2016
@pasdeloup
Copy link
Contributor Author

Ok tests added.
And I rebased to get nicolas-grekas fix for fixtures so tests should pass now.

@pasdeloup
Copy link
Contributor Author

AppVeyor is not passing :(
but seems not related to this PR

@pasdeloup
Copy link
Contributor Author

And now AppVeyor is passing, strange...

/**
* @author Jean Pasdeloup <jpasdeloup@sedona.fr>
*/
class MockFormLoginAuthenticator extends AbstractFormLoginAuthenticator
Copy link
Member

Choose a reason for hiding this comment

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

This class should be moved at the bottom of the test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, moved


if (!$targetPath) {
if (!isset($targetPath) || !$targetPath) {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to explicitly initialize $targetPath to nullabove and make a check on null here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done.
I also improved the tests.


public function testAuthenticateWithoutSession()
{
$authenticator = new MockFormLoginAuthenticator();
Copy link
Member

Choose a reason for hiding this comment

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

Why not use a PHPUnit mock instead?

@fabpot
Copy link
Member

fabpot commented Jun 30, 2016

Thank you @pasdeloup.

fabpot added a commit that referenced this pull request Jun 30, 2016
…pasdeloup)

This PR was squashed before being merged into the 2.8 branch (closes #19218).

Discussion
----------

[Security][Guard] check if session exist before using it

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18958
| License       | MIT
| Doc PR        | -

As stated by @Shekhovtsovy when the Guard component is used without the Symfony full stack (for instance in Laravel), $request->getSession() may be null.

An additionnal PR will be needed for 3.1 but it may be better to check this one before.

Commits
-------

a3f7510 [Security][Guard] check if session exist before using it
@fabpot fabpot closed this Jun 30, 2016
This was referenced Jul 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants