feat(traffic,sandbox): add TUN/netstack transparent gateway, egress controls, CAP_NET_RAW hardening, and i18n fixes

- Implement full-traffic transparent gateway (cmd/artex-gateway, traffic/netstack.go, traffic/transparent.go) using Linux TUN + gVisor netstack deferred TCP handshakes (eliminating nmap/nc false-positive open ports), real ICMPv4 Echo proxying, UDP/DNS interception, and per-container upstream proxy overrides.
- Add egress blacklist + asset-intercept sync, non-HTTP flow/DNS SQLite persistence and APIs, and /system/proxy & /function/traffic TCP/UDP/DNS UI panels.
- Fix sandbox Playwright MCP browser loopback --proxy-server rewrite and NODE_EXTRA_CA_CERTS override in server/mcpstdio.go.
- Strip all SUID/SGID binaries in Dockerfile.sandbox, grant minimal cap_net_raw+ep to nmap/nping/ping with ARTEX_SANDBOX_ALLOW_NET_RAW toggle, and enforce IPv4/IPv6 anti-spoofing in iptables and netstack.
- Remove hardcoded Chinese "(全局)" from GET /api/proxy/routes, localize ContainerRoutesTab / NonHTTPTrafficPanel labels, and expose reactive locale/isEn from useLiveTranslation for React Compiler compatibility.
This commit is contained in:
ji ruo committed 2026-12-02 02:51:36 +08:00
1 parent 9c43e694a3
commit d786de90af
69 files changed
+13082 -1433

No files matched your search

+70 -1
View File
@@ -12,8 +12,8 @@ import (
"strings"
"testing"
"time"
"github.com/Autumn-27/artex/db"
"github.com/Autumn-27/artex/internal/sandbox"
)
func TestEnsureBrowserMCPArgs(t *testing.T) {
@@ -178,3 +178,72 @@ func TestDefaultEnabledSettingsAndScreenshotTimestampHeader(t *testing.T) {
t.Fatal("expected X-Report-Screenshot-Timestamp header when setting is unset (default true)")
}
}
func TestAdaptSandboxMCPArgsAndEnv(t *testing.T) {
// 1. Loopback --proxy-server (split and =) rewritten to sandbox-reachable proxy URL.
in := []string{"--browser", "chromium", "--headless", "--no-sandbox", "--proxy-server", "http://127.0.0.1:8788"}
got := adaptSandboxMCPArgs(in, "http://172.30.0.2:8788")
want := []string{"--browser", "chromium", "--headless", "--no-sandbox", "--proxy-server", "http://172.30.0.2:8788"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("adaptSandboxMCPArgs(split) = %v, want %v", got, want)
}
inEq := []string{"--headless", "--proxy-server=http://localhost:8788"}
gotEq := adaptSandboxMCPArgs(inEq, "http://172.30.0.2:8788")
wantEq := []string{"--headless", "--proxy-server=http://172.30.0.2:8788"}
if !reflect.DeepEqual(gotEq, wantEq) {
t.Fatalf("adaptSandboxMCPArgs(=) = %v, want %v", gotEq, wantEq)
}
// 2. Empty sandboxProxyURL strips unusable loopback proxy flag cleanly.
gotStrip := adaptSandboxMCPArgs(in, "")
wantStrip := []string{"--browser", "chromium", "--headless", "--no-sandbox"}
if !reflect.DeepEqual(gotStrip, wantStrip) {
t.Fatalf("adaptSandboxMCPArgs(strip) = %v, want %v", gotStrip, wantStrip)
}
// 3. Explicit non-loopback user proxy passes through untouched.
inCustom := []string{"--headless", "--proxy-server", "http://10.0.0.5:8080"}
gotCustom := adaptSandboxMCPArgs(inCustom, "http://172.30.0.2:8788")
if !reflect.DeepEqual(gotCustom, inCustom) {
t.Fatalf("adaptSandboxMCPArgs(custom) = %v, want %v", gotCustom, inCustom)
}
// 4. stripURLCredentials drops userinfo so Chromium accepts --proxy-server.
if got := stripURLCredentials("http://artexctx_sc=task:[email protected]:8788"); got != "http://172.30.0.2:8788" {
t.Fatalf("stripURLCredentials = %q", got)
}
// 5. buildSandboxMCPEnv never lets host CA path clobber /etc/artex/ca.crt.
caFile := filepath.Join(t.TempDir(), "mitmproxy-ca-cert.pem")
if err := os.WriteFile(caFile, []byte("FAKE-CA"), 0o644); err != nil {
t.Fatal(err)
}
mgr, err := sandbox.New(sandbox.Config{
Mode: sandbox.ModeLocal,
ProxyURL: "http://172.30.0.2:8788",
CACertPath: caFile,
})
if err != nil {
t.Fatal(err)
}
env := buildSandboxMCPEnv(mgr, map[string]string{
"NODE_EXTRA_CA_CERTS": "/app/data/traffic/_ca/mitmproxy-ca-cert.pem",
"CUSTOM_KEY": "custom-val",
})
envMap := map[string]string{}
for _, kv := range env {
if k, v, ok := strings.Cut(kv, "="); ok {
envMap[k] = v
}
}
if envMap["NODE_EXTRA_CA_CERTS"] != sandbox.ContainerCACertPath {
t.Fatalf("NODE_EXTRA_CA_CERTS = %q, want %q", envMap["NODE_EXTRA_CA_CERTS"], sandbox.ContainerCACertPath)
}
if envMap["CUSTOM_KEY"] != "custom-val" {
t.Fatalf("CUSTOM_KEY = %q, want custom-val", envMap["CUSTOM_KEY"])
}
if envMap["HTTP_PROXY"] != "http://172.30.0.2:8788" {
t.Fatalf("HTTP_PROXY = %q, want http://172.30.0.2:8788", envMap["HTTP_PROXY"])
}
}