fix(api): harden /api/swarm SSRF guard for caller-supplied baseUrl#26
Closed
AliaksandrNazaruk wants to merge 1 commit into
Closed
fix(api): harden /api/swarm SSRF guard for caller-supplied baseUrl#26AliaksandrNazaruk wants to merge 1 commit into
AliaksandrNazaruk wants to merge 1 commit into
Conversation
buildModel() only rejected a baseUrl matching /localhost|127.0.0.1/, so a signed-in caller could point baseUrl at other internal targets — IPv6 loopback [::1], 0.0.0.0, the rest of 127.0.0.0/8, cloud metadata 169.254.169.254, RFC1918 ranges, and CGNAT 100.64.0.0/10 — and make the server issue requests there (SSRF). Add ssrf-guard.ts (isBlockedHost) covering loopback/unspecified/link-local/ ULA/private/CGNAT for both IPv4 and IPv6 (incl. IPv4-mapped) plus localhost/ .local/.internal, and apply it in buildModel to the parsed hostname AND to the DNS-resolved addresses (defense against a public name resolving to a private IP). Public provider hosts (api.openai.com, etc.) are unaffected. Adds ssrf-guard.test.ts; logic verified standalone (24 blocked / 12 allowed).
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.
Problem
/api/swarmaccepts a caller-suppliedbaseUrl;buildModelonly rejected/localhost|127.0.0.1/, missing IPv6 loopback,0.0.0.0, the rest of127.0.0.0/8, cloud metadata169.254.169.254, RFC1918 and CGNAT. A signed-in caller could therefore reach internal/metadata endpoints (SSRF) — see #25.Fix
ssrf-guard.tsisBlockedHost()— loopback / unspecified / link-local / ULA / private / CGNAT for IPv4 and IPv6 (incl. IPv4-mapped), pluslocalhost/.local/.internal.buildModelto the parsed hostname and to the DNS-resolved addresses (defense-in-depth vs. a public name resolving to a private IP). Public provider hosts (api.openai.com, …) are unaffected.Tests
ssrf-guard.test.ts; logic verified standalone (24 blocked / 12 allowed).Fixes #25.