Conversation
The sandboxed fetch validated the SSRF guard against extractUrl(resource)
(which read resource.url) while pinnedFetch independently re-derived the dial
target via new Request(resource).url (which coerces the resource via
toString / Symbol.toPrimitive). For an object resource these two URLs could
diverge, and when the dialed value was an IP literal node:http's net.connect
dials it directly and skips the custom pinned lookup, so the validated address
set was never consulted. User code in a Code node could therefore pass the
guard with an allowed host and still dial a blocked target:
fetch({ url: "http://allowed/", toString() { return "http://169.254.169.254/..." } })
reaching IMDS / ECS / K8s ClusterIPs / loopback. External IMDS is backstopped
by the sandbox NetworkPolicy, but cluster-internal targets are not, and the
app-layer guard added previously was fully bypassed.
Fix:
- Build the WHATWG Request exactly once in sandboxedFetch and validate + dial
that single object (remove the divergent extractUrl helper). A hostile
toString / Symbol.toPrimitive is now invoked once, so it cannot hand one
value to the guard and another to the socket.
- pinnedFetch reads url/method/headers/body from the passed-in Request (no
second construction) and, before dialing, asserts that any IP-literal dial
host is in the validated pinned set - a load-bearing backstop for the
net.connect lookup-skip path that holds even if a future change reintroduces
a divergent URL derivation.
- Redirect hops build the next request from the re-validated Location href, so
no hop's dial URL can diverge from what was just validated.
Adds regression coverage for the exact bypass (toString and Symbol.toPrimitive
divergence), a single-coercion lock, non-canonical IPv4/IPv6 literal forms
(octal/decimal/hex/short/IPv4-mapped), and the redirect path, plus negative
controls that legitimate object-resource fetches still work.
…nding-toctou-between-ssrf-guard-and-host-fetch fix(sandbox): validate the URL the sandboxed fetch actually dials
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
Promote the following merged PRs from staging to prod:
Post-deploy verification
deploy-keeperhubworkflow finishes green, including the@keeperhub/sandboximage rebuild (the fix lives in the sandbox child-source template, executed by the sandbox service)curl -fsS https://app.keeperhub.com/api/healthreturns 200fetch({ url: "http://allowed/", toString() { return "http://169.254.169.254/" } })is rejected with "SSRF blocked" (it never dials IMDS), and a normalfetchto an allowed public host still succeeds