Skip to content

Harden native HTTP Host and Origin validation - #66

Merged
MichaelSchmidle merged 1 commit into
mainfrom
codex/native-http-origin-host
Nov 21, 2026
Merged

MichaelSchmidle merged 1 commit into
mainfrom
codex/native-http-origin-host

Conversation

@MichaelSchmidle

Copy link
Copy Markdown
Contributor

Closes #51.

Changes

  • Validate a single Host header against the listener's configured hostname or the interface that accepted the connection, including its actual port. Keep loopback access available to DSH.
  • Require explicit origins for cross-origin requests and check Host, Origin, and mutation media type before buffering a request body.
  • Document the reverse-proxy policy and cover rejected headers, explicitly configured origins, and successful same-origin requests in regression tests.

Windows DSH verification

Passed the repository's workspace browser test in Windows DSH desktop mode with the rebuilt native API, a scripted model provider through DSH's model service, and native Reverie 0.3.0. The test covered workspace activation, inline authoring, dated episodes, compact routing, scene headings, manual and generated turns, memorization and continued play, workspace export and import, and reopening after a host restart. It exercised four viewport sizes.

Other checks

  • All 51 Rust tests passed.
  • All 19 local API and branch interface regression tests passed, including rejection before the client sends the request body.
  • Native inference startup, manual smoke, native dependency-boundary audit, lint, and TypeScript type checks passed.

@j2msReginaldBot j2msReginaldBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at d1dd6bd (base 7a541b9) against the acceptance criteria in #51. No blocking findings.

Issue #51 acceptance

  • No default origins: allowedOrigins now defaults to empty. Unconfigured http://localhost:3000 and http://127.0.0.1:3000 are rejected with no ACAO header. The CLI passes origins only from --origin.
  • Attacker Host rejected: allowed_host requires a single Host whose port equals the accepted socket's port. The host must be one of: an IP literal equal to the concrete local interface (canonicalised, so IPv4-mapped addresses on a dual-stack wildcard bind still match), the configured hostname, or localhost on a loopback connection. A rebinding page's Host (attacker:port) therefore fails before any dispatch. X-Forwarded-Host is ignored. The following are all rejected: duplicate Host headers, comma-joined values, userinfo, +80, a trailing-colon port, a missing port, and absolute-form targets.
  • Same-origin acceptance: Without explicit config, an Origin passes only when it is http, has the same host as the already-validated Host, and has the same port. This does not widen the rebinding surface.
  • Checks run before the body is read: Host, Origin and media type are all checked before to_bytes. The new node test leaves a declared 20-byte body outstanding, so it would time out if the server read the body.
  • Error responses: Origin rejection no longer echoes the caller's origin. The 413 response and dispatched replies still carry the CORS headers.

Verification (local, Linux, at d1dd6bd)

  • cargo build --locked and cargo test --locked passed (51 tests).
  • The native-boundary audit, lint, tsc --noEmit and node --test tests/*.test.ts all passed: 513 tests, 505 pass, 0 fail. smoke.ts also passed.
  • CI Validate passed.

Non-blocking observations

  • HTTP/2 prior-knowledge (h2c) requests carry no Host, so they are always rejected with 403. This fails closed and browsers don't use h2c, so no change is needed. It may be worth a line in the docs if a proxy ever speaks h2c upstream.
  • Configured origins are compared as exact strings, as documented. A mixed-case --origin value would never match a browser-serialised origin. Optional: normalise or validate --origin at startup.

@MichaelSchmidle
MichaelSchmidle merged commit 4606a46 into main Nov 21, 2026
1 check passed
@MichaelSchmidle
MichaelSchmidle deleted the codex/native-http-origin-host branch November 21, 2026 10:28
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.

Harden native HTTP origin and Host validation

2 participants