diff --git a/server/src/engine/orchestrator.test.ts b/server/src/engine/orchestrator.test.ts index 59c47e5..9aac794 100644 --- a/server/src/engine/orchestrator.test.ts +++ b/server/src/engine/orchestrator.test.ts @@ -76,30 +76,93 @@ describe('orchestrator utility functions', () => { }) describe('isAllowedWebhookUrl — SSRF protection', () => { - it('blocks localhost', () => { + it('blocks localhost variants', () => { expect(isAllowedWebhookUrl('http://localhost/webhook')).toBe(false) expect(isAllowedWebhookUrl('http://127.0.0.1/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://127.0.0.2/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://0.0.0.0/webhook')).toBe(false) }) - it('blocks private IP ranges', () => { + it('blocks private IPv4 ranges', () => { + // 10.x.x.x expect(isAllowedWebhookUrl('http://10.0.0.1/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://10.255.255.255/webhook')).toBe(false) + // 192.168.x.x expect(isAllowedWebhookUrl('http://192.168.1.1/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://192.168.0.1/webhook')).toBe(false) + // 172.16-31.x.x expect(isAllowedWebhookUrl('http://172.16.0.1/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://172.31.255.255/webhook')).toBe(false) + // 172.15 and 172.32 should be ALLOWED (outside private range) + expect(isAllowedWebhookUrl('http://172.15.0.1/webhook')).toBe(true) + expect(isAllowedWebhookUrl('http://172.32.0.1/webhook')).toBe(true) }) - it('blocks .local and .internal TLDs', () => { + it('blocks IPv6 loopback ::1', () => { + expect(isAllowedWebhookUrl('http://[::1]/webhook')).toBe(false) + }) + + it('blocks IPv6 all-zeros [::]', () => { + expect(isAllowedWebhookUrl('http://[::]/webhook')).toBe(false) + }) + + it('blocks IPv6 link-local fe80::', () => { + expect(isAllowedWebhookUrl('http://[fe80::1]/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://[fe80::abcd:1234]/webhook')).toBe(false) + }) + + it('blocks IPv6-mapped IPv4 localhost', () => { + expect(isAllowedWebhookUrl('http://[::ffff:127.0.0.1]/webhook')).toBe(false) + }) + + it('blocks IPv6 private ranges fc/fd', () => { + expect(isAllowedWebhookUrl('http://[fc00::1]/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://[fd00::1]/webhook')).toBe(false) + }) + + it('blocks .local, .internal, .localhost TLDs', () => { expect(isAllowedWebhookUrl('http://myapp.local/webhook')).toBe(false) expect(isAllowedWebhookUrl('http://service.internal/webhook')).toBe(false) + expect(isAllowedWebhookUrl('http://evil.localhost/webhook')).toBe(false) }) - it('allows public URLs', () => { - expect(isAllowedWebhookUrl('https://example.com/webhook')).toBe(true) - expect(isAllowedWebhookUrl('https://api.mybot.dev/fight')).toBe(true) - }) - - it('blocks file:// and other schemes', () => { + it('blocks file:// scheme', () => { expect(isAllowedWebhookUrl('file:///etc/passwd')).toBe(false) }) - // Note: IPv6 loopback (::1) is not currently blocked — tracked for Phase 5 security hardening + it('blocks gopher:// scheme', () => { + expect(isAllowedWebhookUrl('gopher://evil.com/')).toBe(false) + }) + + it('blocks data: scheme', () => { + expect(isAllowedWebhookUrl('data:text/html,