Repository navigation
Send no Mercure cookie on a host outside the hub's domain - #616
Merged
Merged
Conversation
symfony/mercure refuses to build the subscriber cookie, and its clear cookie, when the request host shares no registrable domain with the hub's public URL. Login, JWT refresh, logout and a failed /me then 500'd. The bundle now logs a warning and sends no Mercure cookie, so the request carries on without real-time.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #616 +/- ##
=========================================
Coverage 97.24% 97.25%
- Complexity 5587 5604 +17
=========================================
Files 460 461 +1
Lines 14335 14364 +29
=========================================
+ Hits 13940 13969 +29
Misses 395 395
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
symfony/mercure's
AuthorizationthrowsRuntimeException('Unable to create authorization cookie for a hub on the different second-level domain …')from bothcreateCookie()andcreateClearCookie()when the request host and the hub'spublic_urlshare no registrable domain. Once the template anchors its Caddy internal-host matcher, php sees such hosts (a production alias, a tunnel), and login, JWT refresh, logout and a failed/meall 500'd.Now the bundle sends no Mercure cookie on such a host, logs a warning, and lets the request carry on. Login works there and only real-time is unavailable.
MercureAuthorization::getAuthorizationCookie()andgetClearAuthorizationCookie()return?Cookie, and both go through one private helper.JWTEventListener(login, refresh),LogoutListener,JWTClearTokenListenerandAccessDeniedListenerskip anull.RuntimeExceptiononly, and it is rethrown unlessUtility\MercureCookieDomain::isOutside()confirms the host is foreign. That narrowing is needed because the token factory, which runs before the domain check, can throw the same class for another reason (WebTokenFactory's JWKS fetch).isOutside()mirrors the library's privategetCookieDomain()rule, andMercureCookieDomainTestchecks every case against the realAuthorization, so the two can't drift without a failing test.InvalidArgumentException(JWT configuration,__Secure-over plain HTTP) always propagates.MercureAuthorizationtakes theHubRegistry(for the hub's public URL) and an optional logger (NULL_ON_INVALID_REFERENCE).Tests:
Functional\User\ForeignHostMercureCookieTestcovers login, JWT refresh, GET and POST logout, a failed/mewith an expired session, a failed/mecarrying only a Mercure cookie, and an invalid JWT, all onhttps://example.org. Each checks the status, that the JWT cookie is set or cleared, that no Mercure cookie is sent, and that a warning is logged.Functional\User\SecurityTest(test_a_successful_login,test_expired_jwt_tokens_should_be_refreshed, the logout tests, the failed/metests).MercureAuthorization, every listener (a newLogoutListenerTest),MercureCookieDomainand the DI wiring.Docs: components-web-app/docs#345
🤖 Generated with Claude Code