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

+53 -27
View File
@@ -144,8 +144,9 @@ type Server struct {
proxyPoolTickMu sync.Mutex
// proxyProbe is injectable for deterministic reconnect race tests. Production
// servers leave it nil and use probeEgress directly.
proxyProbe func(context.Context, string, string, []string, time.Duration) egressProbeResult
side *sideQuestionState
proxyProbe func(context.Context, string, string, []string, time.Duration) egressProbeResult
proxyRoutes *proxyRouteRuntime
side *sideQuestionState
}
// provEntry is a cached provider + its config for one LLM profile id.
@@ -332,6 +333,15 @@ func New(ctx context.Context, m *Manager, skillDir string, dataDir string, keyDi
func (s *Server) Close() {
if s != nil {
s.proxyPoolWG.Wait()
if s.proxyRoutes != nil {
s.proxyRoutes.mu.Lock()
gw := s.proxyRoutes.embeddedGW
s.proxyRoutes.embeddedGW = nil
s.proxyRoutes.mu.Unlock()
if gw != nil {
_ = gw.Close()
}
}
if mgr := sandbox.Default(); mgr != nil && mgr.Enabled() {
sctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
mgr.Shutdown(sctx)
@@ -998,6 +1008,11 @@ func (s *Server) Handler() http.Handler {
mux.HandleFunc("DELETE /api/traffic/all", s.deleteAllTraffic)
mux.HandleFunc("GET /api/traffic/exchange", s.getTrafficExchange)
mux.HandleFunc("GET /api/traffic/blob", s.getTrafficBlob)
mux.HandleFunc("GET /api/traffic/flows", s.getTrafficFlows)
mux.HandleFunc("GET /api/traffic/flows/{id}", s.getTrafficFlowDetail)
mux.HandleFunc("DELETE /api/traffic/flows", s.deleteTrafficFlows)
mux.HandleFunc("GET /api/traffic/dns", s.getTrafficDNS)
mux.HandleFunc("DELETE /api/traffic/dns", s.deleteTrafficDNS)
mux.HandleFunc("GET /api/commands", s.pgListCommands)
mux.HandleFunc("GET /api/commands/stats", s.pgToolStats) // 按工具聚合调用次数
mux.HandleFunc("GET /api/llm/records", s.pgListLLMRecords)
@@ -1043,8 +1058,19 @@ func (s *Server) Handler() http.Handler {
mux.HandleFunc("DELETE /api/settings/proxy-pool/{id}", s.deleteProxyPool)
mux.HandleFunc("POST /api/settings/proxy-pool/{id}/test", s.testProxyPoolEntry)
mux.HandleFunc("POST /api/settings/proxy-pool/test-all", s.testAllProxyPool)
mux.HandleFunc("GET /api/proxy/blacklist", s.getEgressBlacklist)
mux.HandleFunc("PUT /api/proxy/blacklist/settings", s.updateEgressBlacklistSettings)
mux.HandleFunc("POST /api/proxy/blacklist/rules", s.createEgressBlacklistRule)
mux.HandleFunc("PUT /api/proxy/blacklist/rules/{id}", s.updateEgressBlacklistRule)
mux.HandleFunc("DELETE /api/proxy/blacklist/rules/{id}", s.deleteEgressBlacklistRule)
mux.HandleFunc("DELETE /api/proxy/blacklist/events", s.clearEgressBlockEvents)
mux.HandleFunc("GET /api/proxy/routes", s.getProxyRoutes)
mux.HandleFunc("PUT /api/proxy/routes/{scope}/{owner_id}", s.putProxyRoute)
mux.HandleFunc("DELETE /api/proxy/routes/{scope}/{owner_id}", s.deleteProxyRoute)
mux.HandleFunc("PUT /api/proxy/gateway/settings", s.updateGatewaySettings)
mux.HandleFunc("GET /api/internal/gateway/policy", s.getGatewayPolicy)
mux.HandleFunc("POST /api/internal/gateway/events", s.postGatewayEvents)
mux.HandleFunc("POST /api/settings/proxy-pool/{id}/activate", s.activateProxyPool)
mux.HandleFunc("POST /api/tasks/{id}/proxy/test", s.testTaskProxy)
mux.HandleFunc("GET /api/report", s.getReport)
mux.HandleFunc("GET /api/chat/mentions", s.searchChatMentions)
mux.HandleFunc("POST /api/chat", s.chat)
@@ -3717,8 +3743,9 @@ func (s *Server) getTraffic(w http.ResponseWriter, r *http.Request) {
page := atoiDefault(q.Get("page"), 0)
size := atoiDefault(q.Get("size"), 100)
var taskHosts []string
var rawTaskID string
taskScoped := false
if rawTaskID := strings.TrimSpace(q.Get("task_id")); rawTaskID != "" {
if rawTaskID = strings.TrimSpace(q.Get("task_id")); rawTaskID != "" {
taskScoped = true
taskID, err := strconv.ParseInt(rawTaskID, 10, 64)
if err != nil || taskID <= 0 || s.m.ResolveTask(rawTaskID) == nil {
@@ -3731,25 +3758,25 @@ func (s *Server) getTraffic(w http.ResponseWriter, r *http.Request) {
return
}
}
if taskScoped && len(taskHosts) == 0 {
writeJSON(w, 200, map[string]any{
"enabled": s.m.TrafficEnabled(), "proxy": s.m.ProxyAddr(), "count": 0,
"total": 0, "page": page, "size": size, "exchanges": []any{},
})
return
}
intentID, _ := strconv.ParseInt(strings.TrimSpace(q.Get("intent_id")), 10, 64)
pageQuery := traffic.PageQuery{
Hosts: taskHosts,
Host: q.Get("host"),
Method: q.Get("method"),
Query: q.Get("q"),
Body: q.Get("body"),
Path: q.Get("path"),
Status: q.Get("status"),
RespMin: int64(atoiDefault(q.Get("resp_min"), -1)),
RespMax: int64(atoiDefault(q.Get("resp_max"), -1)),
Sort: q.Get("sort"),
Order: q.Get("order"),
Hosts: taskHosts,
OwnerTaskID: rawTaskID,
SandboxScope: q.Get("scope"),
SandboxOwnerID: q.Get("owner_id"),
ContainerID: q.Get("container_id"),
SessionID: q.Get("session_id"),
IntentID: intentID,
Host: q.Get("host"),
Method: q.Get("method"),
Query: q.Get("q"),
Body: q.Get("body"),
Path: q.Get("path"),
Status: q.Get("status"),
RespMin: int64(atoiDefault(q.Get("resp_min"), -1)),
RespMax: int64(atoiDefault(q.Get("resp_max"), -1)),
Sort: q.Get("sort"),
Order: q.Get("order"),
}
ex, matched, _ := tr.Page(pageQuery, page, size)
count, _ := tr.Count() // global total, for the stat card
@@ -3778,7 +3805,8 @@ func (s *Server) getTrafficHosts(w http.ResponseWriter, r *http.Request) {
return
}
var hosts []string
if rawTaskID := strings.TrimSpace(r.URL.Query().Get("task_id")); rawTaskID != "" {
rawTaskID := strings.TrimSpace(r.URL.Query().Get("task_id"))
if rawTaskID != "" {
taskID, err := strconv.ParseInt(rawTaskID, 10, 64)
if err != nil || taskID <= 0 || s.m.ResolveTask(rawTaskID) == nil {
writeErr(w, http.StatusNotFound, "task not found")
@@ -3792,10 +3820,8 @@ func (s *Server) getTrafficHosts(w http.ResponseWriter, r *http.Request) {
}
var result []traffic.HostCount
var err error
if len(hosts) > 0 {
result, err = tr.HostsForScope(hosts)
} else if r.URL.Query().Get("task_id") != "" {
result = []traffic.HostCount{}
if rawTaskID != "" {
result, err = tr.HostsForTask(rawTaskID, hosts)
} else {
result, err = tr.Hosts()
}