fix(inspect): validate metadata URI before fetching (SSRF)#12
Open
Nexory wants to merge 1 commit into
Open
Conversation
`inspect` reads `metadataURI` from the on-chain registry, which any registrant can write, and fetched it with no checks. A hostile entry could point the fetch at an internal address (e.g. cloud metadata at 169.254.169.254) from the machine or CI runner that runs `inspect`. - Reject a metadata URI whose host is a private/internal address before fetching, reusing `isPrivateHostname`. - Reject non-http(s) schemes. - Add the link-local range (169.254.0.0/16, which covers the cloud metadata endpoint) to `PRIVATE_HOSTNAME_RE`; it was previously absent, so the endpoint probe did not flag it either. Adds a regression test that a link-local metadata URI is never fetched.
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.
What
inspectfetches the on-chainmetadataURIwith no validation. This validates it first so a hostile registry entry cannot point the fetch at an internal address.Why
metadataURIis read from the tool registry, which any party can write to permissionlessly, andinspectpasses it straight tofetch(src/cli/commands/inspect.ts). A registrant can storehttp://169.254.169.254/latest/meta-data/...and post the tool id; a developer or CI runner that runstool-sdk inspect --tool-id <id>then issues that request to the cloud metadata endpoint from inside the trust boundary. TheisPrivateHostnameguard already exists (it is applied tomanifest.endpoint) but was never applied tometadataURI, and itsPRIVATE_HOSTNAME_REdid not cover the link-local range the metadata endpoint lives in.Change
metadataURIbefore fetching: reject a private/internal host (reusingisPrivateHostname) and reject non-http(s)schemes.169.254.0.0/16(which contains169.254.169.254) toPRIVATE_HOSTNAME_RE, so the endpoint probe flags it too.Tests
Adds a regression test that a link-local
metadataURIis never fetched. Against the current code it fails (the address is fetched):With the fix it passes and the full suite stays green: