mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-04 04:31:51 +08:00
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:
1 parent
9c43e694a3
commit
d786de90af
69 files changed
+13082
-1433
No files matched your search
+133
-5
@@ -8,11 +8,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/Autumn-27/artex/internal/sandbox"
|
||||
"github.com/Autumn-27/norma/llm"
|
||||
"github.com/Autumn-27/norma/mcp"
|
||||
@@ -186,12 +188,14 @@ func newSandboxStdioMCPClient(ctx context.Context, mgr *sandbox.Manager, target
|
||||
if strings.TrimSpace(workDir) != "" {
|
||||
containerWorkDir = sandbox.HostToContainerPath(mgr.Config().LocalRootFor(target), workDir)
|
||||
}
|
||||
envSlice := append([]string{}, mgr.ProxyEnv(true)...)
|
||||
for k, v := range env {
|
||||
envSlice = append(envSlice, k+"="+v)
|
||||
sandboxProxyURL := ""
|
||||
if mgr != nil {
|
||||
sandboxProxyURL = stripURLCredentials(mgr.Config().ProxyURL)
|
||||
}
|
||||
adaptedArgs := adaptSandboxMCPArgs(args, sandboxProxyURL)
|
||||
envSlice := buildSandboxMCPEnv(mgr, env)
|
||||
stream, err := mgr.ExecStream(ctx, target, sandbox.ExecSpec{
|
||||
Cmd: append([]string{command}, args...),
|
||||
Cmd: append([]string{command}, adaptedArgs...),
|
||||
WorkDir: containerWorkDir,
|
||||
Env: envSlice,
|
||||
})
|
||||
@@ -221,6 +225,130 @@ func newSandboxStdioMCPClient(ctx context.Context, mgr *sandbox.Manager, target
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// adaptSandboxMCPArgs rewrites loopback --proxy-server flags (such as
|
||||
// http://127.0.0.1:8788 persisted for local mode by syncBrowserMCPProxy) to the
|
||||
// sandbox-reachable recording proxy URL (e.g. http://172.30.0.2:8788).
|
||||
// Chromium rejects inline credentials in --proxy-server, so sandboxProxyURL must
|
||||
// be credential-free; Layer-1 container source IP provides attribution.
|
||||
func adaptSandboxMCPArgs(args []string, sandboxProxyURL string) []string {
|
||||
out := make([]string, 0, len(args))
|
||||
for i := 0; i < len(args); i++ {
|
||||
arg := args[i]
|
||||
if arg == "--proxy-server" && i+1 < len(args) {
|
||||
val := args[i+1]
|
||||
i++
|
||||
if isLoopbackProxyTarget(val) {
|
||||
if sandboxProxyURL != "" {
|
||||
out = append(out, "--proxy-server", sandboxProxyURL)
|
||||
}
|
||||
continue
|
||||
}
|
||||
out = append(out, "--proxy-server", val)
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(arg, "--proxy-server=") {
|
||||
val := strings.TrimPrefix(arg, "--proxy-server=")
|
||||
if isLoopbackProxyTarget(val) {
|
||||
if sandboxProxyURL != "" {
|
||||
out = append(out, "--proxy-server="+sandboxProxyURL)
|
||||
}
|
||||
continue
|
||||
}
|
||||
out = append(out, arg)
|
||||
continue
|
||||
}
|
||||
out = append(out, arg)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func isLoopbackProxyTarget(raw string) bool {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains(raw, "://") {
|
||||
raw = "http://" + raw
|
||||
}
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
h := strings.ToLower(strings.Trim(strings.TrimSpace(u.Hostname()), "[]"))
|
||||
if h == "localhost" || h == "0.0.0.0" || h == "::" {
|
||||
return true
|
||||
}
|
||||
if ip := net.ParseIP(h); ip != nil && (ip.IsLoopback() || ip.IsUnspecified()) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func stripURLCredentials(raw string) string {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return ""
|
||||
}
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return raw
|
||||
}
|
||||
u.User = nil
|
||||
return u.String()
|
||||
}
|
||||
|
||||
// buildSandboxMCPEnv merges MCP-configured env vars with sandbox proxy/CA env
|
||||
// vars so host-side CA paths (like /app/data/traffic/_ca/mitmproxy-ca-cert.pem)
|
||||
// never clobber the in-container mounted CA path (/etc/artex/ca.crt).
|
||||
func buildSandboxMCPEnv(mgr *sandbox.Manager, userEnv map[string]string) []string {
|
||||
merged := make(map[string]string, len(userEnv)+12)
|
||||
hostCA := ""
|
||||
if mgr != nil {
|
||||
hostCA = strings.TrimSpace(mgr.Config().CACertPath)
|
||||
}
|
||||
for k, v := range userEnv {
|
||||
if isHostCAPathOverride(k, v, hostCA) {
|
||||
continue
|
||||
}
|
||||
merged[k] = v
|
||||
}
|
||||
if mgr != nil {
|
||||
for _, kv := range mgr.ProxyEnv(true) {
|
||||
if k, v, ok := strings.Cut(kv, "="); ok {
|
||||
merged[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
keys := make([]string, 0, len(merged))
|
||||
for k := range merged {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
out := make([]string, 0, len(keys))
|
||||
for _, k := range keys {
|
||||
out = append(out, k+"="+merged[k])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func isHostCAPathOverride(key, val, hostCA string) bool {
|
||||
switch key {
|
||||
case "NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "CURL_CA_BUNDLE", "REQUESTS_CA_BUNDLE", "GIT_SSL_CAINFO":
|
||||
v := strings.TrimSpace(val)
|
||||
if v == "" {
|
||||
return true
|
||||
}
|
||||
if hostCA != "" && v == hostCA {
|
||||
return true
|
||||
}
|
||||
// Persisted control-plane paths do not exist inside sandbox containers.
|
||||
if strings.HasPrefix(v, "/app/data/") || strings.Contains(v, "mitmproxy-ca-cert.pem") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *stdioMCPClient) readLoop(r io.Reader) {
|
||||
br := bufio.NewReaderSize(r, 64*1024)
|
||||
for {
|
||||
|
||||
Reference in new issue
Block a user