Files
ARTEX-chixuweihu/traffic/ssrf_guard_test.go
T
ji ruo 9c43e694a3 feat(sandbox): isolate worker/chat execution in Docker containers with lifecycle UI
- Add Docker sandbox manager, non-root sandbox image, compose isolation, and host firewall script (#217)
- Route Bash, custom commands/scripts, stdio MCP, chat sessions, MainAgent chat, and task-scoped reporter screenshots into sandbox containers with per-task browser concurrency gate
- Enforce proxy SSRF guard against loopback, metadata, internal services, and admin port
- Add dedicated /system/sandbox management page, /chat session sandbox control, and task detail sandbox popover with progressive stats loading
2026-12-01 21:13:21 +08:00

70 lines
2.1 KiB
Go

package traffic
import (
"net"
"testing"
)
func TestSSRFGuardBlocksLoopbackMetadataProtectedAndOptionalPrivate(t *testing.T) {
_, sbxNet, _ := net.ParseCIDR("172.29.0.0/16")
g := newSSRFGuard(SSRFGuardConfig{
Enabled: true,
BlockPrivate: false,
BlockedHosts: []string{"postgres", "docker-socket-proxy", "10.99.0.2"},
BlockedCIDRs: []*net.IPNet{sbxNet},
})
blocked := []string{
"127.0.0.1:8787",
"127.0.0.2:80",
"[::1]:8787",
"localhost:8787",
"foo.localhost:80",
"169.254.169.254:80",
"metadata.google.internal:80",
"postgres:5432",
"docker-socket-proxy:2375",
"10.99.0.2:5432",
"172.29.0.15:8080",
}
for _, h := range blocked {
if reason := g.Check(h); reason == "" {
t.Fatalf("expected %q to be blocked", h)
}
}
// Authorized internal target allowed when BlockPrivate=false
if reason := g.Check("192.168.110.50:8080"); reason != "" {
t.Fatalf("expected internal target allowed when BlockPrivate=false, got: %s", reason)
}
if reason := g.Check("93.184.216.34:443"); reason != "" {
t.Fatalf("expected public IP allowed, got: %s", reason)
}
// Private targets blocked when BlockPrivate=true
strict := newSSRFGuard(SSRFGuardConfig{Enabled: true, BlockPrivate: true})
if reason := strict.Check("192.168.110.50:8080"); reason == "" {
t.Fatalf("expected private IP blocked when BlockPrivate=true")
}
if reason := strict.Check("10.0.0.1:80"); reason == "" {
t.Fatalf("expected 10/8 blocked when BlockPrivate=true")
}
infra := newSSRFGuard(SSRFGuardConfig{
Enabled: true,
InfraIPs: []net.IP{net.ParseIP("192.168.110.238")},
})
if reason := infra.Check("192.168.110.238:8787"); reason == "" {
t.Fatal("expected admin port on the ARTEX host to be blocked")
}
if reason := infra.Check("192.168.110.238:8788"); reason == "" {
t.Fatal("expected recording proxy port on the ARTEX host to be blocked")
}
if reason := infra.Check("192.168.110.238:18080"); reason != "" {
t.Fatalf("expected ordinary target port on the ARTEX host to stay open, got %s", reason)
}
if reason := infra.Check("192.168.110.50:8787"); reason != "" {
t.Fatalf("expected another LAN host on 8787 to stay open, got %s", reason)
}
}