Repository navigation
fix(auth): refuse the UI session cookie on reads from another origin - #3375
Open
angela-helios wants to merge 3 commits into
Open
angela-helios wants to merge 3 commits into
angela-helios wants to merge 3 commits into
Conversation
…usal A request whose web-UI session cookie was refused because the request was cross-site, or a write from another origin, was audited on the FHIR API as a missing token with no user, and not recorded at all on /ui. The REST auth middleware now tells that case apart: it logs a warning, records an AuditEvent described as a cross-origin refusal that carries the Origin and Sec-Fetch-Site values and names the session subject, and says so in the 401 body. The /ui guard logs the refusal and reports it to a recorder the hfs binary installs, which writes the same AuditEvent. Which requests are refused does not change. Closes #3183
A GET or HEAD sent by a page on a sibling subdomain still ran as the signed-in web-UI user: the session cookie is SameSite=Lax, and only cross-site requests and writes from another origin were refused. Such a read could keep the session alive, probe for data and run expensive searches as the user. The REST auth middleware now lets the cookie stand in for a bearer only on a request from this origin, on every method. A refused read is answered 401, logged and audited as a cross-origin refusal, and does not touch the session. Under /ui, a read that carries the session cookie from another origin is answered 403 unless it is a navigation, so a link from another site to a UI page still opens it. Closes #3182
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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 #3182
This branch is stacked on the PR for #3183 (PR #3365). Its diff includes that commit until #3365 merges.
Behaviour change to review
GETorHEADmarkedSec-Fetch-Site: same-site(a page on a sibling subdomain) was authenticated as the signed-in user. It is now answered401, logged and audited as a cross-origin refusal, the same as a write from another origin.401, as a link from an unrelated site already did. Typing the URL, or following a link from the HFS UI itself, is unchanged./ui, aGETorHEADthat carries the session cookie from another origin is answered403unless it is a navigation (Sec-Fetch-Mode: navigate). A link from another site to a UI page still opens it. The login routes and/ui/assets/are not affected.Authorizationheader, requests without the session cookie, and non-browser clients are not affected. The UI's own pages are not affected: their browser calls are same-origin and their server-side calls send an explicit bearer.Summary
session_bearerincrates/rest/src/middleware/auth.rsnow refuses the cookie wheneverhelios_auth::is_cross_originsays the request came from another origin, instead of only forcross-siterequests and foreign writes.Sec-Fetch-Sitemust besame-originornone; without that header,Originmust be absent or name the request'sHostorHFS_BASE_URL./uiguard (crates/ui/src/cross_site.rs, renamedrefuse_cross_site_requests) also refuses a non-navigation read that carries the session cookie from another origin, before the session gate runs. It applies only when a login is installed.crates/auth/README.mdand thework-with-authskill (both mirrors) describe the rule.Not covered:
Sec-Fetch-Siteand noOriginon an<img>or<script>read, so that read cannot be told apart from the page's own and still rides the cookie./uipage as a navigation, including in a frame.GETroutes were not audited for handlers that change state.Tests
crates/rest/tests/ui_session_sibling_reads.rs: asame-siteread, asame-sitenavigation and a read naming anotherOriginare401and leave the session'slast_seenunchanged; reads from this origin (same-origin,none, no browser headers, the public origin behind a proxy that rewritesHost) still authenticate; an explicit bearer is validated whatever the origin.crates/ui/tests/cross_site_reads_http.rs: a sub-resource read from a sibling site and a read naming anotherOriginare403and leave the session alone; a navigation from a sibling site, the page's own reads and an asset request are not refused; a sibling read without the cookie is sent to the login.crates/ui/src/cross_site.rsforis_foreign_session_read.crates/rest/tests/ui_session_bearer.rs: removed the assertion that asame-siteGETrides the cookie.ui_session_origin_audit,login_httpandbulk_import_httpsuites.Results:
cargo test -p helios-rest --lib: 1131 passed.cargo test -p helios-rest --test ui_session_sibling_reads: 5 passed.--test ui_session_bearer: 8 passed.--test ui_session_origin_audit: 6 passed.cargo test -p helios-ui --lib: 396 passed.--test cross_site_reads_http: 6 passed.--test login_http: 26 passed.--test bulk_import_http: 54 passed.cargo test -p helios-hfs --bin hfs env_names: 7 passed, so the binary builds.These ran on a branch that also carried other pending fixes, so the suites were verified in combination, not on this branch alone.