Skip to content

Commit 322dc4e

Browse files
committed
fix(knowledge): block IPv6-mapped IPv4 SSRF bypass and fix ::1 hostname check
1 parent 4571299 commit 322dc4e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

apps/sim/app/api/knowledge/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ const CreateKnowledgeBaseSchema = z.object({
5555
if (hostname === '169.254.169.254' || hostname === 'metadata.google.internal') {
5656
return false
5757
}
58+
// Block IPv6 addresses (except loopback) — prevents IPv6-mapped IPv4 bypass
59+
// URL.hostname keeps brackets for IPv6, e.g. "[::ffff:169.254.169.254]"
60+
if (hostname.startsWith('[') && hostname !== '[::1]') {
61+
return false
62+
}
5863
// Allow localhost, loopback, and private network ranges
5964
if (
6065
hostname === 'localhost' ||
61-
hostname === '::1' ||
66+
hostname === '[::1]' ||
6267
hostname.startsWith('127.') ||
6368
hostname.startsWith('10.') ||
6469
hostname.startsWith('192.168.')

0 commit comments

Comments
 (0)