Skip to content

fixed example to check if the session exists when getting flash messages to avoid starting sessions when not needed #2564

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

Merged
merged 1 commit into from
May 5, 2013

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Apr 26, 2013

Q A
Doc fix? yes
New docs? no
Applies to all
Fixed tickets symfony/symfony#6036

As flash messages use a session to store the messages from one request to
the next one, a session will be automatically started when you read the
flash messages even if none already exists. To avoid that default
behavior, test if there is an existing session first:
Copy link
Member

Choose a reason for hiding this comment

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

: should be ::

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

…ges to avoid starting sessions when not needed
@weaverryan
Copy link
Member

Hey guys!

Before I merge this, I want to make sure I'm not missing something. Why would the following situation not cause a problem:

  1. On one request, you set a value in the flashbag and redirect
  2. On the next request, you check for app.session.started in Twig. There is a flash message in the session, but the session hasn't been started yet, so the message is not displayed.

Is there some mechanism that would avoid this issue?

More broadly, after reading symfony/symfony#6036, it sounds like we might need a small cookbook article on how to avoid starting the session (including the note about the flashbag and perhaps some notes about security). But we can handle that in another issue.

Thanks!

@fabpot
Copy link
Member Author

fabpot commented May 4, 2013

I don't understand how your scenario can happen. If you set something in the session in request 1, the session is going to be started in all sub-sequent requests.

weaverryan added a commit that referenced this pull request May 5, 2013
fixed example to check if the session exists when getting flash messages to avoid starting sessions when not needed
@weaverryan weaverryan merged commit 1501120 into symfony:2.1 May 5, 2013
@weaverryan
Copy link
Member

I've also opened #2607 as a reminder to add a bit more about this topic.

Thanks!

@TerjeBr
Copy link
Contributor

TerjeBr commented Jul 15, 2013

@fabpot is wrong about this. The session is not automatically started in later requests if it has been started before.

@TerjeBr
Copy link
Contributor

TerjeBr commented Jul 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants