Skip to content

fix(render): accept only plain hosts in --allow-host (#2496) - #4180

Merged
schlessera merged 2 commits into
mainfrom
fix/2496-validate-allow-host
Nov 17, 2026
Merged

schlessera merged 2 commits into
mainfrom
fix/2496-validate-allow-host

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #2496.

What this does

Each allowHosts entry becomes one EXCLUDE <host> in the renderer's Chrome DNS blackhole (--host-resolver-rules), the load-bearing network-denial layer. Nothing validated the entries, so --allow-host '*' exempted every host, and a value with a comma injected another resolver rule.

  • One check, shared: allowHostProblem / normalizeAllowHosts in @schlessera/brain-render-template/internal (packages/render-template/src/allow-hosts.ts). An entry must be lowercase-able labels of letters, digits, - and _, or a bracketed IPv6 literal, and must round-trip unchanged through new URL("http://" + h).hostname. The pattern is load-bearing: the WHATWG URL parser keeps * and , in a host name, so the round trip alone accepts both.
  • Renderer: createRenderer normalizes the list through that check and throws on the first bad entry, before any launch. The resolver rule uses the normalized entries.
  • CLI: brain render --allow-host turns the same check into a UsageError (exit 1) naming the value, before any document is built or rendered. The renderer is an optional peer that core imports dynamically, so the CLI checks on its own, from the shared function.
  • Interception: hostRequestAllowed (extracted from the renderer's hostAllowed) also requires http: or https:.
  • Docs: docs/cli.md and the renderer README state the rule. The render-template API report lists the two new internal exports.

Acceptance criteria

Criterion Proof
*, a.test, MAP * 10.0.0.1, a.test b.test, https://a.test, a.test:8080 each throw before any launch renderer.test.ts "createRenderer refuses … before any launch" (also a,b.test, *.ithaca.test, a.test/path, ""), each asserting zero launches
A valid list gives exactly one EXCLUDE per entry and no other rule "a valid list becomes exactly one EXCLUDE per entry…" compares the whole --host-resolver-rules argument; a second test covers mixed case, IPv4, bracketed IPv6 and _
brain render doc.md --allow-host '*' --json exits with the usage error and names the value packages/core/tests/render.test.ts "--allow-host '*' is a usage error…" for html and pdf, plus the comma-injection value
hostAllowed refuses a non-HTTP(S) URL on an allowed host "an allowed host admits only its http and https requests" (ws:, wss:, ftp:, file:)
Mutation receipt: remove the validation and the * case fails Below

Proof

  • Failing first: with hostRequestAllowed extracted unchanged and no validation, all nine refusal cases failed on "Received function did not throw", the scheme test failed on ws://img.example.test/live, and the three CLI tests failed on the exit code. The launch-args test passed before and after, as a characterization of valid input.
  • Mutation receipts (each restored):
    • Renderer validation removed (plain lowercasing): fails createRenderer refuses "*" before any launch with "Received function did not throw".
    • CLI check removed: fails all three CLI tests.
    • Protocol check removed: fails the http/https test.
    • Pattern dropped, URL round trip kept: fails *, a,b.test and *.ithaca.test.
  • Suites: bun run test packages/ui-render-puppeteer packages/core/tests/render.test.ts: 72 pass. packages/core/tests: 3422 pass, 6 fail. The six are environment-only on this host: two real-Chrome PDF tests ("No Chrome/Chromium executable found"), a real-worker tmpfs test and three paid-provider offline runtime tests. None runs the changed code paths without Chrome. Hosted CI runs them.
  • Typecheck, lint, the API surface check and check:pr pass.

Contract impact

None to the contract surface: the brain render --json envelope, MCP tools, schema_version and frontmatter are unchanged. --allow-host now refuses values such as * that it used to accept and that defeated the network denial. The changeset names the refusal.

Collisions

bun scripts/collisions.ts --json --pr 4180 at head 4471a27: closure reports only (shared test categories and workspaces) with #3054, #3056, #3059, #3069, #3581, #3622, #4002, #4036, #4151, #4157, #4166, #4168, #4172, #4173, #4175, #4177 and #4179. No PR edits the changed source files.

{"version":1,"kind":"brain-check-pr-receipt","head":"7cf0e198ad1a7643561298ee08a622d909ff7034","base":"origin/main","mode":"focused","startedAt":"2026-11-17T11:29:54.245Z","finishedAt":"2026-11-17T11:31:38.846Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12800.032302999998},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":110.83405800000037},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":75.72482799999852},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":21.958631000001333},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":91575.58518699999}]}

🤖 Generated with Claude Code

Each allowHosts entry becomes one EXCLUDE in the renderer's Chrome DNS
blackhole, whose rule list is comma-separated with wildcard patterns.
`*` exempted every host, and a comma injected another rule. A shared
render-template check now accepts only a plain host name or IP literal:
createRenderer throws before any launch, and `brain render
--allow-host` turns it into a usage error naming the value. An allowed
host also admits only http and https requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 17, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 4471a27 against base c26fb22. Reviewer: agent. No findings.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4180,
  "head": "4471a270163d350e0d0978c803571af6f1a72b52",
  "base": "c26fb229fa1ef920ce219e77256e859e9982c263",
  "reviewer": "agent",
  "outcome": "no-findings",
  "findings": []
}

@schlessera
schlessera marked this pull request as ready for review November 17, 2026 11:32
@schlessera
schlessera merged commit df1e105 into main Nov 17, 2026
47 of 60 checks passed
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.

render: unvalidated --allow-host entries can switch off the renderer's DNS blackhole

1 participant