Skip to content

fix(webhooks): deliver agent and App webhooks only to public addresses - #2188

Merged
lilyshen0722 merged 1 commit into
mainfrom
fix/webhook-public-address-guard
Oct 15, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
fix/webhook-public-address-guard

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Rebased onto main after #2186 and #2187 merged. This branch is now one commit, e49999d0, on top of main at 50383bf8. Its patch is byte-identical to the 92ba7c15 reviewed against #2186's head. It shares no files with #2187.

What this changes

Agent push webhooks and App installation webhooks POST to a URL their owner registered. Neither delivery checked where that URL resolved. Both now go through a new open-destination mode of the outbound guard.

postToPublicAddress (in backend/services/outboundUrlGuard.ts, next to fetchTextFromAllowedHost)

  • http(s) only. Any other scheme, or an unparseable URL, is refused.
  • The host is resolved by the guard, with dns.promises.lookup, all answers. Every answer must be allowed, so a name with one public and one private record is refused. Address literals are checked directly. metadata.google.internal is refused by name before any lookup.
  • The connection is pinned to the address that was checked, through a custom lookup on the http/https request. A second DNS answer cannot move it, and TLS still verifies the certificate against the URL's hostname.
  • Redirects are followed by the guard and each hop is resolved and checked again: 307/308 keep the method and body, 301/302/303 continue as a GET (as fetch does), at most 5 hops.
  • One 10s deadline covers every hop (the timeout both callers already used), and the response body is capped at 1 MB.

classifyAddress (the ranges)

Class Ranges Allowed?
reserved 0.0.0.0/8, 169.254.0.0/16 (incl. 169.254.169.254), 224.0.0.0/4, 240.0.0.0/4 (incl. 255.255.255.255), ::, the IPv4-compatible ::/96, fe80::/10, ff00::/8, anything unparseable never
private 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, ::1, fc00::/7 only with the flag
public everything else yes

IPv4-mapped (::ffff:a.b.c.d, in dotted and hex spellings) and NAT64 (64:ff9b::/96) addresses are classified by the IPv4 address they carry.

Dev and self-host

Local webhook receivers are a real case: commonly agent register --webhook <url> stores whatever URL is given. I looked for an existing convention and followed the *_ALLOW_UNVERIFIED flags (=== 'true', off by default).

  • OUTBOUND_WEBHOOK_ALLOW_PRIVATE_ADDRESSES=true admits the private class.
  • Link-local and the metadata host stay refused even with the flag on.
  • It's documented, commented out, in .env.example and in docs/architecture/WEBHOOK_RUNTIME.md.
  • The documented local dev loop, commonly agent connect, is unaffected: the CLI polls the instance and forwards to localhost itself.

Callers

  • agentEventService.deliverEventViaWebhook: fetch is replaced by postToPublicAddress. A refusal lands in the existing catch, which logs it, and the event is not acked.
  • AppService.deliverWebhookByInstallation: axios.post is replaced by postToPublicAddress. A non-2xx reply is reported as { success: false, reason: 'HTTP <n>', statusCode }.
  • AppService.deliverWebhook had no callers in backend, frontend or CLI, and no tests. It is removed rather than guarded. With it gone, appService no longer imports axios.

docs/security-patterns.md now describes both modes and when to use each.

Tests

Run on Node 22.

outboundUrlGuard.publicAddress.test.js, new, 100 tests.

  • classifyAddress table: public, private and reserved, including the edges of every IPv4 block, IPv4-mapped (dotted and hex) and NAT64 forms, the IPv4-compatible block, and a zone id.

  • Refusals with the flag unset (the default):

    • a name resolving to each refused range, including IPv4-mapped forms;
    • a mixed public/private answer;
    • address literals, including the decimal IPv4 spelling and a mapped IPv6 literal;
    • the metadata host by name;
    • non-http schemes;
    • a name that does not resolve.

    Every refusal arm asserts that no http/https request was made. In those arms the request functions throw instead of connecting, so even a broken guard can't reach the network.

  • Connections, against a local receiver on 127.0.0.1 (flag on), reached through .test names that system DNS can't resolve, so a request arriving proves the pinned address was used:

    • a POST arrives with its body and headers;
    • a later DNS answer pointing at link-local does not move the connection;
    • the flag still refuses link-local and the metadata host, by literal, by name and by resolution;
    • a 307 keeps POST and body and re-resolves the next host;
    • a 302 continues as a GET without a body;
    • redirects to a link-local literal, to a name resolving to link-local, to the metadata host, or to a file: URL are refused after exactly one request;
    • five redirects are followed and the sixth is refused;
    • a non-2xx response is returned, not thrown;
    • the 1 MB body cap holds;
    • with the flag unset, the same receiver is refused.

appService.webhookGuard.test.js, new, 5 tests.

  • A private literal, the metadata address, and a name resolving to loopback are refused with no request made.
  • A signed delivery to an allowed address arrives with the expected headers and body.
  • A non-2xx reply is reported as a failure carrying its status.

agentEventService.lifecycle.test.js

  • The existing webhook arm now asserts delivery goes through postToPublicAddress and still terminates as acked.
  • A new arm runs the real guard against a link-local webhook URL: no request is made and the event is not acked.

Regression: every suite that loads a changed module passes (67 suites, 955 tests), plus service/apps.test.js.

Mutation check. 17 arms, each landing once at a named line. Every arm goes red, and the suite count (4) and test total (176) stay constant in every arm:

Mutation Tests failing
Mapped IPv4 not unwrapped 11
NAT64 not unwrapped 1
Link-local dropped 13
CGNAT dropped 4
ULA treated as public 3
fe80::/10 treated as public 5
Private allowed without the flag 16
Flag cannot admit private 13
Metadata name check removed 1
Only the first DNS answer checked 1
Connection not pinned (no lookup) 13
Redirect hop not re-checked 5
Redirect cap off by one 1
302 keeps POST and body 1
Body cap removed 1
Non-http scheme allowed 4
App non-2xx reported as success 1

Lint: 0 errors on the three changed .ts files. The address arithmetic uses division and range comparisons rather than bitwise operators, so no no-bitwise override is needed. tsc --noEmit -p tsconfig.build.json is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1

Adds an open-destination mode to backend/services/outboundUrlGuard.ts, next
to fetchTextFromAllowedHost, for URLs whose destinations cannot be listed in
advance.

- postToPublicAddress allows http(s) only. It resolves the host itself and
  refuses unless every address the host resolves to is allowed. It connects
  to the address it checked, using a pinned lookup on the http(s) request, so
  a second DNS answer cannot substitute another. Every redirect hop is
  resolved and checked again: 307/308 keep the method and body, 301/302/303
  continue as a GET, at most 5 hops. A 10s deadline and a 1 MB response cap
  apply.
- classifyAddress holds the ranges:
  - reserved: unspecified, link-local (including the metadata endpoint),
    multicast, broadcast and 240/4.
  - private: loopback, RFC 1918, CGNAT, IPv6 unique-local.
  - IPv4-mapped and NAT64 forms are classified by the IPv4 address they
    carry.
  - metadata.google.internal is refused by name.
- OUTBOUND_WEBHOOK_ALLOW_PRIVATE_ADDRESSES=true admits private ranges for a
  local or self-hosted setup, following the existing *_ALLOW_UNVERIFIED
  convention. It is off by default, and reserved ranges stay refused.
- Callers: agent push webhook delivery (agentEventService) and App
  installation webhooks (appService). AppService.deliverWebhook had no
  callers anywhere and is removed rather than guarded.

Tests: outboundUrlGuard.publicAddress (100), appService.webhookGuard (5), and
a refusal arm in agentEventService.lifecycle that runs the real guard.
Connection arms use a local receiver on 127.0.0.1 reached through .test names
that system DNS cannot resolve, so an arriving request proves the pinned
address was used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
@samxu01
samxu01 force-pushed the fix/webhook-public-address-guard branch from f77f0fe to e49999d Compare October 15, 2026 00:34

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review at e49999d (eng lead, code and security gate). One commit on current main, 0 behind.

Checked:

  • Address classification (classifyAddress):
    • IPv4 reserved: 0/8, link-local 169.254/16 (the metadata address included), multicast and 240/4.
    • IPv4 private: 10/8, CGNAT 100.64/10, loopback, 172.16/12 and 192.168/16.
    • IPv6 is classified through the URL parser's canonical form, so IPv4-mapped (::ffff:) and NAT64 (64:ff9b::/96) addresses are judged as the IPv4 address they embed. Loopback, unique-local, link-local and multicast are refused, and an unparsable address reads as reserved.
  • Name and DNS: metadata.google.internal is refused by name, with and without the trailing dot. Every DNS answer must be allowed, not just the first.
  • Pinning: requestPinned connects to the checked address through a custom lookup, while TLS still verifies the certificate against the URL's hostname. A second DNS answer can't swap the destination between check and connect.
  • Redirects: at most 5, each re-resolved and re-checked. A 301, 302 or 303 downgrades to a GET without the body, and a 307 or 308 keeps the method. One 10-second deadline spans every hop, and the response body is capped at 1 MB.
  • Self-host flag: OUTBOUND_WEBHOOK_ALLOW_PRIVATE_ADDRESSES=true admits private ranges only. Reserved ranges and the metadata name stay refused. It's off by default and documented in .env.example.
  • Callers: agent push webhooks (agentEventService) and App installation webhooks (appService.deliverWebhookByInstallation) both deliver through postToPublicAddress. The deleted deliverWebhook has no remaining references, and no other backend code sends a request straight to a stored webhook URL.
  • CI: all checks are green, and the two cancelled runs were superseded by passing ones. No CodeQL alerts are open on the PR's merge ref.
  • Tests at this head: 61 backend suites touching the guard, App webhooks, agent events and the skills catalog pass (838 tests). agentsRuntime.rateLimitTiers passes alone and serially (3), and lint shows 0 errors on the three changed services.

Non-blocking notes:

  1. On a cross-host redirect, X-Commonly-Signature is still sent, and a 307 or 308 also forwards the body. Neither leaks a secret, since the header is an HMAC of the payload and the receiver chose the redirect. Dropping the signature when the origin changes would still be tidy.
  2. A few special-purpose IPv4 ranges classify as public: 192.0.0.0/24, benchmarking 198.18.0.0/15, the TEST-NETs, and the deprecated IPv6 site-local fec0::/10. None routes to cluster-internal addresses here. Worth adding if the table is touched again.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 1259203 Oct 15, 2026
22 of 24 checks passed
samxu01 pushed a commit that referenced this pull request Oct 21, 2026
…d the webhook runtime doc (TASK-005)

ADR-004 says the kernel never POSTs to a driver and delivers at least once.
Push shipped in #73 (2026-04-02), twelve days before the ADR, and every
install with config.runtime.webhookUrl is pushed to. A failed push stays
pending and nothing sends it again: the requeue acts only on delivered
rows, the stranded-pending sweep covers in-process agents only, and the
GC deletes the row after the retention, 168 h by default. Nor is push
at most once: a 307 or 308 replays the same POST within one attempt, up
to six requests in all.

- ADR-004: conformance entry C4, plus an inline marker at each of the six
  sentences it contradicts and at the rejected push alternative. C4
  names the two changes push has had since #73: #822 and #2188.
- ADR-006: pointers at the two non-goals that repeat the claim. The
  second also called webhookSecret unused; it signs each push.
- WEBHOOK_RUNTIME.md: the 30-minute failed-close it described applies
  only to in-process agents. A failed push is never sent again, and a
  redirect can replay one, so a receiver dedupes on X-Commonly-Delivery.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
samxu01 pushed a commit that referenced this pull request Oct 22, 2026
…d the webhook runtime doc (TASK-005)

ADR-004 says the kernel never POSTs to a driver and delivers at least once.
Push shipped in #73 (2026-04-02), twelve days before the ADR, and every
install with config.runtime.webhookUrl is pushed to. A failed push stays
pending and nothing sends it again: the requeue acts only on delivered
rows, the stranded-pending sweep covers in-process agents only, and the
GC deletes the row after the retention, 168 h by default. Nor is push
at most once: a 307 or 308 replays the same POST within one attempt, up
to six requests in all.

- ADR-004: conformance entry C4, plus an inline marker at each of the six
  sentences it contradicts and at the rejected push alternative. C4
  names the two changes push has had since #73: #822 and #2188.
- ADR-006: pointers at the two non-goals that repeat the claim. The
  second also called webhookSecret unused; it signs each push.
- WEBHOOK_RUNTIME.md: the 30-minute failed-close it described applies
  only to in-process agents. A failed push is never sent again, and a
  redirect can replay one, so a receiver dedupes on X-Commonly-Delivery.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
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