Repository navigation
fix(auth): give the web-UI cookies the __Host- prefix and refuse duplicates - #3338
Open
angela-helios wants to merge 2 commits into
Open
angela-helios wants to merge 2 commits into
angela-helios wants to merge 2 commits into
Conversation
…icates The session and pending-login cookies could be replaced by a page on a sibling subdomain setting a same-named cookie for the parent domain. When the cookie is Secure it is now named __Host-hfs_session / __Host-hfs_login, which a browser accepts only from the host itself. Plain-HTTP local development (HFS_UI_LOGIN_COOKIE_SECURE=false) keeps the unprefixed names, because a browser rejects __Host- without Secure. A request carrying the same cookie name twice is treated as carrying none. Existing sessions are not carried over: users sign in again once after the upgrade. Closes #3181
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
This branch has not been deployed
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.
Closes #3181
Behaviour change to review
HFS_UI_LOGIN_COOKIE_SECURE=true(the default) the web-UI cookies are renamed to__Host-hfs_sessionand__Host-hfs_login. Existing sessions are not carried over: every signed-in user signs in again once after the upgrade. The old name is deliberately not read as a fallback, because a sibling subdomain could plant it for a browser that has no prefixed cookie yet.HFS_UI_LOGIN_COOKIE_SECURE=false(plain-HTTP local development) the names stayhfs_sessionandhfs_login, since a browser rejects a__Host-cookie that is notSecure. That mode keeps the weakness and the README says so./ui/login, the FHIR API answers 401, and/ui/callbackanswers 400.Summary
The session and pending-login cookies had no
__Host-prefix, andcookie_valuereturned the first cookie of a given name. A page on a sibling subdomain could set a same-named cookie for the parent domain with a longerPathand have its value win, putting the victim in the attacker's session or completing a login the attacker started.LoginConfig::session_cookie()andLoginConfig::pending_cookie()choose the name fromcookie_secure. TheSet-Cookieattributes already met the prefix rules (Path=/, noDomain,Secure).session_bearer) and the UI login module (gate,login,callback,logout,session_authorization) take the name from the store's config instead of a constant.helios_auth::cookie_valuereturnsNonewhen the name appears more than once, in oneCookieheader or across several.crates/auth/README.md, the Okta page of the book, and thework-with-auth/work-with-uiskills (both mirrors).No environment variable is added or changed.
AuthConfig::from_envis not touched.Tests
New:
helios-authunit tests: a name sent twice is refused (same header, separate headers, equal values);hfs_sessionand__Host-hfs_sessionare not confused with each other; the names carry the prefix only whencookie_secureis on.helios-restui_session_bearer: the unprefixed name is not a session when the cookie isSecure; an unprefixed cookie beside the real one does not displace it; two session cookies give 401.helios-uilogin_http: the unprefixed cookie does not pass the gate; two session cookies are signed out; a callback with two pending cookies is rejected; the pending cookie hasPath=/and noDomain.helios-uiunit test for theSet-Cookiestring in both modes.Existing tests in those files now send the prefixed name, since their stores are configured with
cookie_secure: true.Results:
cargo test -p helios-auth --lib: 120 passed.cargo test -p helios-rest --test ui_session_bearer: 11 passed.cargo test -p helios-ui --lib: 385 passed.--test login_http: 25 passed.These ran on a branch that also carried seven other pending fixes, so the suites were verified in combination, not on this branch alone. That branch also compiled with the
postgres,mongodb,s3andelasticsearchfeatures.