Skip to content

fix(egress-proxy): block path traversal, private-IP SSRF, and DNS ID collisions - #1849

Merged
nikhilunni merged 4 commits into
mainfrom
audit/p0-egress-security
Dec 2, 2026
Merged

nikhilunni merged 4 commits into
mainfrom
audit/p0-egress-security

Conversation

@nikhilunni

@nikhilunni nikhilunni commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens engram-egress-proxy against path traversal, SSRF, and UDP DNS reply hijacking:

  • Path traversal on credential injection: When an injection has path_globs, RequestPolicy::path_matches matches only an unambiguous path. It decodes each segment and rejects dot segments in every spelling (literal, %2e, with ; parameters, or behind an encoded /), backslashes, encoded %, control bytes, empty segments, and fragments. A request that fails the check matches no injection, so the gated host refuses it. An encoded / alone is accepted, because GitLab project IDs and file paths, npm scoped packages, and Cloud Storage object names use it. Hosts without a path policy are not checked: no glob can be bypassed there.
  • SSRF and connect timeouts: SystemResolver::resolve selects only a globally routable IPv4 address. It skips loopback, link-local and metadata (169.254.0.0/16), RFC 1918, CGNAT, unspecified, multicast, documentation, benchmarking, and reserved ranges. IPv6 results (including IPv4-mapped and NAT64) are skipped, as before. The connect uses the vetted address, so there is no resolve-then-connect gap. bypass::relay and intercept::run bound the upstream TCP connect at 10 s. There is no opt-in: the filter is always on for SystemResolver. Only StaticResolver (tests and the --test-resolve flag of engram-egress-proxyd) reaches local addresses. The guest gateway (metadata server, Cloud SQL) does not use the resolver.
  • DNS proxy isolation: UDP upstream transaction IDs are random and unique, with generation-checked reaping. One guest can hold at most 1024 queries in flight. Replies must come from the upstream address and repeat the question. QDCOUNT != 1 is answered with FORMERR on UDP and TCP. The TCP timeout bounds the full upstream exchange.
  • Fixes a registry session-displacement cleanup edge case found during review.

Behavior change for deployments

A session whose allow-listed host resolves only to a private address (for example a self-hosted Git server or package registry inside a VPC) can no longer reach it through the proxy. No in-tree deployment (Helm chart, Tilt dev stack, e2e stack) depends on this.

Validation

  • cargo fmt --check
  • cargo clippy -p engram-egress-proxy --all-targets -- -D warnings
  • cargo nextest run -p engram-egress-proxy: 220 passed.

🤖 Generated with Claude Code

nikhilunni and others added 4 commits December 1, 2026 11:59
The path check rejected every intercepted request with an encoded
slash, an encoded dot, or an empty segment, also on hosts with no path
policy. This broke valid clients: GitLab project IDs and file paths
(`group%2Fproject`, `lib%2Fclass%2Erb`), npm scoped packages
(`@scope%2fname`), and Cloud Storage object names all need `%2F`.

Now only a non-empty `path_globs` list requires an unambiguous path,
because only a glob can be bypassed by normalization. A request that
fails the check does not match the injection, so a gated host refuses
it as before. The check decodes each segment and rejects dot segments
in every spelling (literal, `%2e`, with `;` parameters, or behind an
encoded `/`), backslashes, encoded `%`, control bytes, empty segments,
and fragments. An encoded `/` alone is accepted.

The HTTP/1 adapter keeps its origin-form check.

Review pass: no other change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The proxy allocated upstream transaction IDs in sequence. An off-path
sender could then predict the next ID and forge a reply more easily
than with the guest's own random IDs. The allocator now starts from a
random ID (ring's secure random) and takes the first free one.

One guest could also hold all 65536 IDs for the 5 s reap window and
deny DNS to every other guest on the host. Each guest can now have at
most 1024 queries in flight; more get SERVFAIL.

The TCP timeout now bounds the full upstream exchange, not only the
connect, so a stalled upstream cannot hold a guest connection open.

Review pass: no other change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nikhilunni
nikhilunni marked this pull request as ready for review December 2, 2026 21:51
@nikhilunni
nikhilunni merged commit 1222792 into main Dec 2, 2026
77 of 81 checks passed
@nikhilunni
nikhilunni deleted the audit/p0-egress-security branch December 2, 2026 21:52
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