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

[Security/Http] don't require the session to be started when tracking its id #36118

Merged
merged 1 commit into from Mar 18, 2020

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

$session->getId() returns the empty string when the session is not yet started.
When this happens, the session tracking logic wrongly detects that a new session was created and thus disables HTTP caching.

This fixes the issue by looking at the value of the session cookie instead.
(the case for true is when using MockArraySessionStorage as done in tests)

@nicolas-grekas nicolas-grekas changed the title [Security/Http] ensure session is started when tracking it [Security/Http] don't require the session to be started when tracking its id Mar 17, 2020
@fabpot
Copy link
Member

fabpot commented Mar 18, 2020

Thank you @nicolas-grekas.

@fabpot fabpot merged commit abefccf into symfony:4.4 Mar 18, 2020
This was referenced Mar 27, 2020
@nicolas-grekas nicolas-grekas deleted the sec-session-start branch April 5, 2020 16:59
nicolas-grekas added a commit that referenced this pull request Apr 18, 2020
This PR was merged into the 5.1-dev branch.

Discussion
----------

[Security] Fixed broken master build

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | n/a

The build failures are caused by these lines (line 100 specically):

https://github.com/symfony/symfony/blob/2460ca59af71e0ce610a3f807ab092436850b487/src/Symfony/Component/Security/Http/Firewall/ContextListener.php#L97-L108

Since #34363, `$request->cookies->get()` is typehinted as `string|null`. On Travis with PHP=7.4, this doc typehint is transformed into PHP return type: `get(): ?string`.

On tests, the session cookie is set to `true`. See #36118 for some background on why this is necessary.

There are a couple possible solutions:

1. Update the `InputBag::get()` PHPdoc to use `@return scalar|null`
2. Use `$request->cookie->all()[$session->getName()]` in `ContextListener`
3. Allow pre-configuring the session ID in `MockArraySessionStorage`.

I've implemented solution (1). The method is actually using `is_scalar()` to check if a deprecation notice should be triggered, so it is expected to return a scalar in Symfony 6.

_I've had to update the `DebugClassLoader` to not convert this to `get(): ?scalar`, as that doesn't exists in PHP. I'm not sure if my changes are correct (but they work)._

Commits
-------

94f4763 Fixed fetching sessionId from InputBag
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.

None yet

3 participants