Skip to content

Read the token untracked in TwoFactorAccessListener, so public responses stay cacheable - #327

Merged
scheb merged 1 commit into
scheb:8.xfrom
guillaume-sainthillier:fix/access-listener-untracked-token-storage
Oct 30, 2026
Merged

scheb merged 1 commit into
scheb:8.xfrom
guillaume-sainthillier:fix/access-listener-untracked-token-storage

Conversation

@guillaume-sainthillier

Copy link
Copy Markdown
Contributor

Hello,

With a lazy firewall, TwoFactorAccessListener reads the token through security.token_storage on every request. This flags the session as used and turns every response into private, max-age=0, even for an anonymous visitor without session (#230).

This PR injects security.untracked_token_storage instead, like Symfony's own ContextListener and LazyFirewallContext. The token is still read, so the 2fa check doesn't change: a user in a 2fa process is still redirected to the 2fa form on paths without access control, unlike the change discussed in #230. Only what the application reads of the token (getUser(), is_granted()) makes the response private, as without the bundle.

The test app gets a /cacheable route without access control:

  1. testAnonymousAccessToPathWithoutAnyAccessControlKeepsResponseCacheable fails without the fix (max-age=0, must-revalidate, private)
  2. test2faProtectsCacheablePathWithoutAnyAccessControl checks that 2fa still protects it

Thanks,
Guillaume

@scheb
scheb merged commit 14e6dac into scheb:8.x Oct 30, 2026
11 checks passed
@scheb

scheb commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Didn't know this existed! Good stuff! Thanks for including the test coverage :)

Released as v8.7.0

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.

2 participants