Repository navigation
fix(egress-proxy): block path traversal, private-IP SSRF, and DNS ID collisions - #1849
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardens
engram-egress-proxyagainst path traversal, SSRF, and UDP DNS reply hijacking:path_globs,RequestPolicy::path_matchesmatches 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.SystemResolver::resolveselects 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::relayandintercept::runbound the upstream TCP connect at 10 s. There is no opt-in: the filter is always on forSystemResolver. OnlyStaticResolver(tests and the--test-resolveflag ofengram-egress-proxyd) reaches local addresses. The guest gateway (metadata server, Cloud SQL) does not use the resolver.QDCOUNT != 1is answered with FORMERR on UDP and TCP. The TCP timeout bounds the full upstream exchange.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 --checkcargo clippy -p engram-egress-proxy --all-targets -- -D warningscargo nextest run -p engram-egress-proxy: 220 passed.🤖 Generated with Claude Code