Skip to content

Commit f20cc35

Browse files
blink-so[bot]f0ssel
andcommitted
feat: implement comprehensive TCP jailing for macOS
Extended the comprehensive TCP jailing approach to macOS using PF rules. Replaced port-specific rules (80, 443) with comprehensive TCP interception to prevent bypass via non-standard ports. ## macOS Security Improvements - **Before**: Only HTTP (80) and HTTPS (443) intercepted - **After**: ALL TCP traffic from jailed group intercepted ## Key Changes - Removed port-specific PF rules (port 80, port 443) - Added comprehensive TCP redirection for all ports - Routes ALL TCP traffic to HTTPS proxy port - Prevents bypass via database ports, SSH, custom APIs, etc. ## Bypass Prevention (macOS) Applications can no longer escape jail by using: - HTTP on non-standard ports (8080, 3000, etc.) - Database connections (3306, 5432, 27017) - SSH connections (22) - Custom API ports - Any TCP-based protocol on any port This ensures both Linux and macOS provide identical comprehensive network jailing capabilities. Tested: Build succeeds, all tests pass. Co-authored-by: f0ssel <[email protected]>
1 parent 99d1903 commit f20cc35

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

namespace/macos.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,43 +243,42 @@ func (m *MacOSNetJail) getDefaultInterface() (string, error) {
243243
return "en0", nil
244244
}
245245

246-
// createPFRules creates PF rules for traffic diversion
246+
// createPFRules creates PF rules for comprehensive TCP traffic diversion
247247
func (m *MacOSNetJail) createPFRules() (string, error) {
248248
// Get the default network interface
249249
iface, err := m.getDefaultInterface()
250250
if err != nil {
251251
return "", fmt.Errorf("failed to get default interface: %v", err)
252252
}
253253

254-
// Create PF rules following httpjail's working pattern
255-
rules := fmt.Sprintf(`# boundary PF rules for GID %d on interface %s
256-
# First, redirect traffic arriving on lo0 to our proxy ports
257-
rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port %d
258-
rdr pass on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port %d
254+
// Create comprehensive PF rules for ALL TCP traffic interception
255+
// This prevents bypass via non-standard ports (8080, 3306, 22, etc.)
256+
rules := fmt.Sprintf(`# comprehensive TCP jailing PF rules for GID %d on interface %s
257+
# COMPREHENSIVE APPROACH: Intercept ALL TCP traffic from the jailed group
258+
# This ensures NO TCP traffic can bypass the proxy by using alternative ports
259259
260-
# Route boundary group traffic to lo0 where it will be redirected
261-
pass out route-to (lo0 127.0.0.1) inet proto tcp from any to any port 80 group %d keep state
262-
pass out route-to (lo0 127.0.0.1) inet proto tcp from any to any port 443 group %d keep state
260+
# First, redirect ALL TCP traffic arriving on lo0 to our HTTPS proxy port
261+
# The HTTPS proxy can handle both HTTP and HTTPS traffic
262+
rdr pass on lo0 inet proto tcp from any to any -> 127.0.0.1 port %d
263263
264-
# Also handle traffic on the specific interface
265-
pass out on %s route-to (lo0 127.0.0.1) inet proto tcp from any to any port 80 group %d keep state
266-
pass out on %s route-to (lo0 127.0.0.1) inet proto tcp from any to any port 443 group %d keep state
264+
# Route ALL TCP traffic from boundary group to lo0 where it will be redirected
265+
pass out route-to (lo0 127.0.0.1) inet proto tcp from any to any group %d keep state
266+
267+
# Also handle ALL TCP traffic on the specific interface from the group
268+
pass out on %s route-to (lo0 127.0.0.1) inet proto tcp from any to any group %d keep state
267269
268270
# Allow all loopback traffic
269271
pass on lo0 all
270272
`,
271273
m.groupID,
272274
iface,
273-
m.config.HTTPPort,
274-
m.config.HTTPSPort,
275-
m.groupID,
276-
m.groupID,
277-
iface,
275+
m.config.HTTPSPort, // Use HTTPS proxy port for all TCP traffic
278276
m.groupID,
279277
iface,
280278
m.groupID,
281279
)
282280

281+
m.logger.Debug("Comprehensive TCP jailing enabled for macOS", "group_id", m.groupID, "proxy_port", m.config.HTTPSPort)
283282
return rules, nil
284283
}
285284

0 commit comments

Comments
 (0)