Skip to content

fix(serve-api): --net-allow-domains and --net-timeout, shared with run - #2625

Merged
sunholo-voight-kampff merged 1 commit into
devfrom
feat/serve-api-net-allow-domains
Dec 2, 2026
Merged

sunholo-voight-kampff merged 1 commit into
devfrom
feat/serve-api-net-allow-domains

Conversation

@sunholo-voight-kampff

Copy link
Copy Markdown
Collaborator

What

ailang serve-api gains --net-allow-domains, --net-timeout and --stream-allow-domains, matching ailang run. Before, serve-api --caps Net --net-allow-domains www.linkedin.com x.ail exited with "flag provided but not defined": a Net-granted route had no host allowlist and every request ran under the fixed 30s timeout (reported by Daneel, 2026-10-26).

One path, not a copy

  • registerNetDestFlags (cmd/ailang/net_flags.go) registers --net-allow-domains, --net-timeout, --net-max-bytes and --stream-allow-domains for both run and serve-api. Names, help text and meaning can no longer drift.
  • runner.SetupNet (SetupNetHandler + SetupNetLimit) is the one place the --net-* options reach the Net effect, for run, run --batch and serve-api. serve-api used to set Net.AllowHTTP/AllowLocalhost/AllowMetadata (and the Stream equivalents) by hand. It now calls runner.SetupNet / runner.SetupStreamHandler and differs only in its defaults: http://, localhost and the metadata server stay on, so existing deployments don't change. With an allowlist set, those destinations are reachable only when they are listed too (the destination authorizer applies the allowlist before the loopback and metadata rules). Example: metadata.google.internal on Cloud Run.
  • As in run, the allowlist and timeout are inert without --caps Net. --net-max-bytes is still refused without it.

Commands that grant Net: audit

Command Net from CLI Allowlist / timeout flags
run (incl. --batch) --caps already had them; now registered via the shared helper
serve-api (HTTP, --mcp, --mcp-http, --a2a) --caps now accepts. All modes share one effect context, so they are all covered
replay --caps (re-execs ailang run) not passed through: it re-runs with caps only
select-best --caps (re-execs ailang run via bestof) not passed through
package [bin] shims manifest caps → ailang run can be set through run_flags (only caps/entry/package-dir/quiet are reserved)
test, check, ai-check none n/a: they grant no Net
repl grants IO only (WASM host may grant any effect via GrantCapability) no flags; WASM is a different host path

replay and select-best are left as they are in this PR.

Policy-file interplay

serve-api has no --policy. With run --policy, the policy's net_allow is the only authority: --net-allow-domains and --stream-allow-domains are refused by name. The result is neither an intersection nor precedence (refusedWithPolicy in cmd/ailang/run_policy.go). The shared helper doesn't change this, because the refusal list matches flag names.

Tests

  • TestNetDestFlags_Parse: the shared helper parses every flag into runner.NetOptions.
  • TestServeAPINetDestFlags_Defined: serve-api defines the flags, and a bad --net-timeout is refused before the server listens.
  • TestSetupServeAPINetStream_Config: Net allowlist and timeout plus the Stream allowlist land on the effect context, and serve-api's defaults are kept.
  • TestServeAPINetAllowDomains_EndToEnd: the checkout binary's serve-api route goes through a loopback forward proxy (HTTP_PROXY), so no real network is used. With --net-allow-domains a.example, a.example is fetched and b.example gets DisallowedHost and never reaches the proxy. A control run without the allowlist shows b.example is reachable.
  • TestServeAPINetTimeout_EndToEnd: --net-timeout 200ms fails a 1s upstream, and the default timeout serves it.

Mutation check: with serve-api reverted to the old Net setup (no allowlist, no timeout), all four serve-api tests fail.

Gates: make test-changed, make lint, make check-file-sizes, make check-cli-docs, make check-changelog, make check-doc-samples.

🤖 Generated with Claude Code

serve-api gains --net-allow-domains / --net-timeout (and
--stream-allow-domains), matching run. Before, serve-api --caps Net had
neither: --net-allow-domains exited "flag provided but not defined" and
every request ran under the fixed 30s timeout (Daneel, 2026-10-26).

One path, not a copy:
- registerNetDestFlags (cmd/ailang/net_flags.go) registers
  --net-allow-domains, --net-timeout, --net-max-bytes and
  --stream-allow-domains for both run and serve-api.
- runner.SetupNet (SetupNetHandler + SetupNetLimit) is the one place the
  --net-* options reach the Net effect, for run, run --batch and
  serve-api. serve-api no longer sets Net/Stream fields by hand; its
  http/localhost/metadata defaults stay on, and an allowlist governs
  those destinations too.

Tests: flag parsing, serve-api config, and end-to-end serve-api routes
through a loopback forward proxy (no real network): with
--net-allow-domains a.example, a.example is fetched and b.example is
refused before any request; --net-timeout 200ms fails a 1s upstream
that the default timeout serves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sunholo-voight-kampff
sunholo-voight-kampff merged commit 9fde5fb into dev Dec 2, 2026
22 of 23 checks passed
@sunholo-voight-kampff
sunholo-voight-kampff deleted the feat/serve-api-net-allow-domains branch December 2, 2026 16:09
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.

1 participant