Skip to content

fix(start-os): stop cross-site calls to the setup, init and diagnostic servers - #4491

Merged
dr-bonez merged 2 commits into
masterfrom
fix/local-server-origin
Oct 30, 2026
Merged

dr-bonez merged 2 commits into
masterfrom
fix/local-server-origin

Conversation

@dr-bonez

@dr-bonez dr-bonez commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

The setup, init and diagnostic servers have no authentication. They used the shared CORS middleware, which reflects any Origin with credentials allowed and approves every preflight. rpc-toolkit also parses a request body as JSON whatever its Content-Type says. So any public web page opened by someone on the LAN could read setup.disk.list and setup.get-pubkey, and could call setup.execute or the diagnostic actions disk.forget, restart and rebuild while the device was in one of those modes. Current Chrome and Firefox show a Local Network Access prompt first; Safari does not. This affects 0.4.0.4 and master.

Summary

These changes apply to those three servers only:

  • No CORS. The CORS middleware is removed, so cross-origin reads and preflights fail.
  • JSON only on /rpc. A new RequireJson rpc-toolkit middleware returns 415 with an empty body unless Content-Type is application/json (parameters and case are ignored). Without it, a text/plain or form POST counts as a "simple" request that browsers send without a preflight, and it would still run the method.
  • Local hosts only. A new local_hosts_only layer serves a request only when its Host or :authority is an IP literal, localhost, or a name ending in .local (a trailing dot is allowed). Any other host gets a 403 with the localized text "Open this server at its .local address or IP address." This stops DNS rebinding from making an attacker's page same-origin. The layer sits outside the whole router, so it also covers the UI files and the /ws/rpc/{guid} and /rest/rpc/{guid} continuations. The existing security headers still wrap the 403.

The authenticated main, registry and tunnel servers keep their CORS behavior. Their credentials travel only in request headers, so a cross-site request carries none, and the setup wizard's final step calls the new main server cross-origin.

User-visible consequence: during setup or diagnostics, a server reached through a router-assigned name such as start9.lan now shows the 403 text. A user has to use start.local, the <hostname>.local name, or the IP, which is where the docs already send them. The changelog entry, in all five locales, says the same.

Implementation diff: +87 / −4 lines in 4 files (excludes lockfiles, tests, docs, release notes, and changelog).

Approach

  • Existing CLI and web clients keep working. The web UI's HttpService posts object bodies through Angular's HttpClient, which sends application/json. The CLI's CallRemote implementations for SetupContext, InitContext and DiagnosticContext go through signature::call_remote_with_client, which sends application/json. They do not use rpc-toolkit's call_remote_http, which sends application/cbor under the toolkit's default cbor feature. CBOR clients of these three servers are therefore rejected, and none exists.
  • Existing hooks and helpers are reused. The host check uses the UiContext::apply_outer_layers hook that the main server already uses for its domain redirect, and reads the host with the existing net::http::request_authority. The content-type rule is an rpc-toolkit Middleware because it applies only to RPC calls.
  • Why the host is matched by suffix. The guard accepts any .local name rather than only this device's hostname, because mDNS names can't be served by a rebinding attacker's public DNS. That keeps the check stateless, so it works before a hostname exists, during init, and in diagnostics.

Neighbors

#4216 (private registry packages) edits the import block next to this PR's new imports in net/static_server.rs. Whichever merges second may hit a small import conflict; the two changes don't overlap in behavior.

Testing

  • On this PR's head (bf9aeb5), cargo test -p start-core --features=test --lib ran the three new tests and all passed:
    • simple_request_content_types_are_rejected_unprocessed: a missing Content-Type, text/plain, form-urlencoded and multipart each get 415 with an empty body, so the method never runs.
    • json_requests_are_handled: application/json with mixed case and a charset parameter reaches the handler.
    • local_hosts_only_rejects_rebound_names: .local names (including a trailing dot and a port), IPv4, bracketed IPv6 and localhost pass. attacker.example, start.local.attacker.example, a bare local and 192.168.1.5.nip.io get 403.
  • The original author's recorded run also shows each rejection test failing with its guard disabled, 76 passing tests across the static_server, middleware, mcp, setup, diagnostic and net::http modules, a passing cargo check for start-os, start-cli, start-registry and start-tunnel, and passing rustfmt, prettier and changelog-version checks.
  • Not exercised end to end: the setup wizard, the diagnostic UI and kiosk mode on a device. Kiosk loads localhost, which the host guard allows.
  • CI: on this head, Prettier, Changelog fragments, Dependency Licenses, Conflict Markers, Compile Base Binaries for aarch64 and riscv64, the x86_64 musl binary and one x86_64 Debian package have passed. Still pending: Run Automated Tests, Formatting & Lockfiles, Generated Artifacts, the remaining Debian packages and binaries, and Compile Base Binaries for x86_64.

Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
Helix-Identity: helix-b

…c servers

These servers have no authentication and used the shared CORS middleware,
which reflects any Origin with credentials allowed and approves every
preflight. rpc-toolkit also parsed the body as JSON whatever the
Content-Type. A public page opened by someone on the LAN could therefore
read setup.disk.list and setup.get-pubkey and call setup.execute or the
diagnostic actions while the device was in one of these modes.

- Drop the CORS middleware from these three servers, so cross-origin
  reads and preflights fail.
- Require Content-Type: application/json on their /rpc, so a "simple"
  text/plain or form POST cannot run a method without a preflight.
- Serve them only when the Host is an IP address, localhost, or a .local
  name, so DNS rebinding cannot make the requests same-origin.

The authenticated main, registry and tunnel servers keep their CORS
behaviour: their credentials travel only in request headers, so a
cross-site request carries none.
@helix-white

Copy link
Copy Markdown
Member

Taking over this PR at @dr-bonez’s request. The branch is clean, matches the submitted head (12ef16b), and merges with current master. There are no existing review comments. @helix-b: please cross-review the full change; I will address feedback and verify adopted changes here.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
@helix-white

Copy link
Copy Markdown
Member

Cross-review requested after establishing Helix implementation ownership with an empty takeover commit. The original code and author commit are unchanged. The earlier request could not be routed because this human-authored PR had no Helix implementer; please review the full change against master.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the full diff at bf9aeb5 against master. It merges cleanly (git merge-tree exits 0).

What I checked:

  • Callers of RequireJson: the Angular HttpService posts object bodies, which HttpClient sends as application/json. The CLI's CallRemote<SetupContext|InitContext|DiagnosticContext> paths all go through signature::call_remote_with_client, which sends application/json. It does not use rpc-toolkit's call_remote_http, which sends application/cbor under the default cbor feature. So no legitimate client of these three servers is rejected.
  • Scope: RequireJson wraps only the HttpServer, so it affects /rpc/* and not the guid-gated /ws/rpc/{guid} and /rest/rpc/{guid} continuations. local_hosts_only sits in apply_outer_layers, so it covers the UI fallback and the continuations too. add_security_headers still wraps the 403.
  • Host matching: request_authority prefers the URI authority, which covers HTTP/2 :authority, and falls back to Host. is_local_host handles bracketed IPv6, a trailing dot, ports (which are stripped by Authority::host), and the .local.attacker.example and nip.io rebinding shapes. The tests cover both sides.
  • Main server unaffected: RpcContext keeps Cors and redirect_service_domains, so the wizard's cross-origin final call to the new main server still works.

No changes requested.

Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
Helix-Identity: helix-b

@helix-white

Copy link
Copy Markdown
Member

@dr-bonez Cross-review approved the final head without requesting changes. Your original implementation and commit are unchanged; I added only an empty takeover commit, confirmed the source matches your submitted head, and reused your recorded verification. The description now includes the handoff brief and evidence provenance. The branch is mergeable; current-head CI is still pending, not yet green. Ready for your final judgment. GitHub cannot formally request a review from you because you are this PR’s author.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved following @helix-b’s independent cross-review of bf9aeb5. No implementation changes were requested or made during takeover; the original author’s verification evidence is retained in the PR brief. CI completion remains a separate merge gate.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

@dr-bonez
dr-bonez merged commit c8cab98 into master Oct 30, 2026
36 of 37 checks passed
@dr-bonez
dr-bonez deleted the fix/local-server-origin branch October 30, 2026 05:27
@helix-white

Copy link
Copy Markdown
Member

@dr-bonez the cross-review approved this with no changes, and the description is now the hand-off brief. GitHub can't request your review because you opened the PR, so this comment is the hand-off. CI is still running on bf9aeb5 (Run Automated Tests, Formatting & Lockfiles, Generated Artifacts, and the remaining binary and Debian package builds).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants