Skip to content

fix(hts): refuse writes that a page on another origin sends - #2947

Open
angela-helios wants to merge 1 commit into
mainfrom
fix/hts-cross-origin-writes
Open

angela-helios wants to merge 1 commit into
mainfrom
fix/hts-cross-origin-writes

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Stacked on #2901. This branch starts from #2901's branch so that Test FHIRPath passes against the current fhir-test-cases master; its commit leaves this diff once #2901 merges.

Closes #2946

Summary

The HTS write routes have no authentication (#2878). A page on any origin could import a Bundle with a text/plain POST /import, which needs no preflight. Because CORS defaults to *, it could also pass the preflight for PUT / DELETE. The target is any HTS the visitor's browser reaches, intranet or localhost included.

The new crates/hts/src/cross_origin.rs adds a middleware on the FHIR router. It refuses a write whose request the browser marks as coming from another origin with 403 and an OperationOutcome:

  • Writes: every PUT, DELETE and PATCH, plus POST to /import, /CodeSystem, /ValueSet, /ConceptMap and /ConceptMap/$closure. The other POSTs ($expand, $validate-code, $lookup, $translate, the batch) are read operations and are not affected.
  • Another origin: Sec-Fetch-Site other than same-origin / none, or, without it, an Origin that does not name the Host.
  • Exception: an origin listed explicitly in HTS_CORS_ORIGINS is the operator's choice and stays allowed. The default * lists none.
  • Non-browser clients: the CLI, 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 /ui keeps its own check (#2777). The HTS README and the work-with-hts skill (both mirrors) document the rule next to HTS_CORS_ORIGINS.

Tests

  • Unit tests (cross_origin::tests):
    • which method and path pairs count as writes;
    • which header combinations count as foreign;
    • how the listed origins are parsed.
  • crates/hts/tests/cross_origin_writes.rs, through create_app:
    • a text/plain POST /import with Sec-Fetch-Site: cross-site, or with an Origin that does not match the Host, gets 403;
    • a cross-site DELETE /CodeSystem/{id} gets 403, and a cross-site $expand does not;
    • a same-origin import, an import with neither header, and a cross-site import from a listed origin all go through.

With the layer in server.rs stashed, the two refusal tests fail: the cross-site import answers 200, and the delete reaches the handler (500). With the fix, everything passes.

cargo test -p helios-hts -p helios-hts-ui: 1257 passed. Clippy on helios-hts --all-targets is clean.

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
@claude

claude Bot commented Nov 25, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

This branch has not been deployed

No deployments
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.

HTS accepts writes sent by a web page on any origin

1 participant