跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

0001-outbound-policy.patch

119 行 · 4.5 KB历史下载
1diff -ruN a/pkg/services/forwarder/tcp.go b/pkg/services/forwarder/tcp.go
2--- a/pkg/services/forwarder/tcp.go 2026-10-04 20:14:52.706297344 +0200
3+++ b/pkg/services/forwarder/tcp.go 2026-10-04 20:17:54.018676901 +0200
4@@ -4,8 +4,10 @@
5 "context"
6 "fmt"
7 "net"
8+ "net/netip"
9 "sync"
10
11+ "github.com/containers/gvisor-tap-vsock/pkg/types"
12 "github.com/inetaf/tcpproxy"
13 log "github.com/sirupsen/logrus"
14 "gvisor.dev/gvisor/pkg/tcpip"
15@@ -17,7 +19,7 @@
16
17 const linkLocalSubnet = "169.254.0.0/16"
18
19-func TCP(s *stack.Stack, nat map[tcpip.Address]tcpip.Address, natLock *sync.Mutex, ec2MetadataAccess bool) *tcp.Forwarder {
20+func TCP(s *stack.Stack, nat map[tcpip.Address]tcpip.Address, natLock *sync.Mutex, ec2MetadataAccess bool, outbound types.Outbound) *tcp.Forwarder {
21 return tcp.NewForwarder(s, 0, 10, func(r *tcp.ForwarderRequest) {
22 localAddress := r.ID().LocalAddress
23
24@@ -31,6 +33,10 @@
25 localAddress = replaced
26 }
27 natLock.Unlock()
28+ if dst, ok := netip.AddrFromSlice(localAddress.AsSlice()); !ok || !outbound.Allows("tcp", netip.AddrPortFrom(dst, r.ID().LocalPort)) {
29+ r.Complete(true)
30+ return
31+ }
32 outbound, err := net.Dial("tcp", net.JoinHostPort(localAddress.String(), fmt.Sprint(r.ID().LocalPort)))
33 if err != nil {
34 log.Tracef("net.Dial() = %v", err)
35diff -ruN a/pkg/services/forwarder/udp.go b/pkg/services/forwarder/udp.go
36--- a/pkg/services/forwarder/udp.go 2026-10-04 20:14:52.706297344 +0200
37+++ b/pkg/services/forwarder/udp.go 2026-10-04 20:17:59.454310606 +0200
38@@ -2,9 +2,11 @@
39
40 import (
41 "net"
42+ "net/netip"
43 "strconv"
44 "sync"
45
46+ "github.com/containers/gvisor-tap-vsock/pkg/types"
47 log "github.com/sirupsen/logrus"
48 "gvisor.dev/gvisor/pkg/tcpip"
49 "gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
50@@ -14,7 +16,7 @@
51 "gvisor.dev/gvisor/pkg/waiter"
52 )
53
54-func UDP(s *stack.Stack, nat map[tcpip.Address]tcpip.Address, natLock *sync.Mutex, ec2MetadataAccess bool) *udp.Forwarder {
55+func UDP(s *stack.Stack, nat map[tcpip.Address]tcpip.Address, natLock *sync.Mutex, ec2MetadataAccess bool, outbound types.Outbound) *udp.Forwarder {
56 return udp.NewForwarder(s, func(r *udp.ForwarderRequest) {
57 localAddress := r.ID().LocalAddress
58
59@@ -27,6 +29,9 @@
60 localAddress = replaced
61 }
62 natLock.Unlock()
63+ if dst, ok := netip.AddrFromSlice(localAddress.AsSlice()); !ok || !outbound.Allows("udp", netip.AddrPortFrom(dst, r.ID().LocalPort)) {
64+ return
65+ }
66
67 var wq waiter.Queue
68 ep, tcpErr := r.CreateEndpoint(&wq)
69diff -ruN a/pkg/types/configuration.go b/pkg/types/configuration.go
70--- a/pkg/types/configuration.go 2026-10-04 20:14:52.706297344 +0200
71+++ b/pkg/types/configuration.go 2026-10-04 20:17:45.476413976 +0200
72@@ -2,9 +2,19 @@
73
74 import (
75 "net"
76+ "net/netip"
77 "regexp"
78 )
79
80+// Outbound decides whether the guest may reach dst over network ("tcp" or
81+// "udp"): see Configuration.Outbound.
82+type Outbound func(network string, dst netip.AddrPort) bool
83+
84+// Allows reports whether o lets the guest reach dst: all, when nil.
85+func (o Outbound) Allows(network string, dst netip.AddrPort) bool {
86+ return o == nil || o(network, dst)
87+}
88+
89 type Configuration struct {
90 // Print packets on stderr
91 Debug bool `yaml:"debug,omitempty"`
92@@ -53,6 +63,12 @@
93
94 // EC2 Metadata Service Access
95 Ec2MetadataAccess bool `yaml:"ec2MetadataAccess,omitempty"`
96+
97+ // Outbound, when set, decides whether the virtual network opens a
98+ // connection the guest asks for: network is "tcp" or "udp", dst the
99+ // destination once NAT applied. A refused TCP connection is reset, a
100+ // refused UDP datagram dropped.
101+ Outbound Outbound `yaml:"-"`
102 }
103
104 type Protocol string
105diff -ruN a/pkg/virtualnetwork/services.go b/pkg/virtualnetwork/services.go
106--- a/pkg/virtualnetwork/services.go 2026-10-04 20:14:52.706297344 +0200
107+++ b/pkg/virtualnetwork/services.go 2026-10-04 20:18:02.314615007 +0200
108@@ -24,9 +24,9 @@
109 var natLock sync.Mutex
110 translation := parseNATTable(configuration)
111
112- tcpForwarder := forwarder.TCP(s, translation, &natLock, configuration.Ec2MetadataAccess)
113+ tcpForwarder := forwarder.TCP(s, translation, &natLock, configuration.Ec2MetadataAccess, configuration.Outbound)
114 s.SetTransportProtocolHandler(tcp.ProtocolNumber, tcpForwarder.HandlePacket)
115- udpForwarder := forwarder.UDP(s, translation, &natLock, configuration.Ec2MetadataAccess)
116+ udpForwarder := forwarder.UDP(s, translation, &natLock, configuration.Ec2MetadataAccess, configuration.Outbound)
117 s.SetTransportProtocolHandler(udp.ProtocolNumber, udpForwarder.HandlePacket)
118
119 dnsMux, err := dnsServer(configuration, s)