Repository navigation
fix(hts): refuse writes that a page on another origin sends - #2947
Open
angela-helios wants to merge 1 commit into
Open
angela-helios wants to merge 1 commit into
angela-helios wants to merge 1 commit into
Conversation
The HTS write routes have no authentication, a browser sends a text/plain POST /import without a preflight, and CORS defaults to *, so any page could write to an HTS its visitor can reach. A write (import, create, update, delete, $closure) whose request the browser marks as coming from another origin now gets 403, unless that origin is listed in HTS_CORS_ORIGINS. Reads and non-browser clients are unaffected. Closes #2946
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 #2946
Summary
The HTS write routes have no authentication (#2878). A page on any origin could import a Bundle with a
text/plainPOST /import, which needs no preflight. Because CORS defaults to*, it could also pass the preflight forPUT/DELETE. The target is any HTS the visitor's browser reaches, intranet orlocalhostincluded.The new
crates/hts/src/cross_origin.rsadds a middleware on the FHIR router. It refuses a write whose request the browser marks as coming from another origin with403and an OperationOutcome:PUT,DELETEandPATCH, plusPOSTto/import,/CodeSystem,/ValueSet,/ConceptMapand/ConceptMap/$closure. The otherPOSTs ($expand,$validate-code,$lookup,$translate, the batch) are read operations and are not affected.Sec-Fetch-Siteother thansame-origin/none, or, without it, anOriginthat does not name theHost.HTS_CORS_ORIGINSis the operator's choice and stays allowed. The default*lists none.curl, HFS's proxy and other servers send neither header and are unaffected.The guard sits on the FHIR router only. The HTS UI under
/uikeeps its own check (#2777). The HTS README and thework-with-htsskill (both mirrors) document the rule next toHTS_CORS_ORIGINS.Tests
cross_origin::tests):crates/hts/tests/cross_origin_writes.rs, throughcreate_app:text/plainPOST /importwithSec-Fetch-Site: cross-site, or with anOriginthat does not match theHost, gets403;DELETE /CodeSystem/{id}gets403, and a cross-site$expanddoes not;With the layer in
server.rsstashed, the two refusal tests fail: the cross-site import answers200, and the delete reaches the handler (500). With the fix, everything passes.cargo test -p helios-hts -p helios-hts-ui: 1257 passed. Clippy onhelios-hts --all-targetsis clean.