Skip to content

feat: log proxy-blocked connections to system log via logger#216

Open
javabrett wants to merge 1 commit into
anthropic-experimental:mainfrom
javabrett:feat/unconditional-proxy-deny-logging
Open

feat: log proxy-blocked connections to system log via logger#216
javabrett wants to merge 1 commit into
anthropic-experimental:mainfrom
javabrett:feat/unconditional-proxy-deny-logging

Conversation

@javabrett

@javabrett javabrett commented Apr 13, 2026

Copy link
Copy Markdown

Problem

When a network connection is blocked because its domain is not in allowedDomains, srt previously offered no visible signal under normal operation. Users hitting a blocked domain saw only a 403 response or an unexplained tool failure, with no indication of which domain was responsible. SRT_DEBUG=1 was required to see anything, which is not practical during normal use.

Solution

Add logProxyDeny() in src/utils/debug.ts, called from all three proxy handlers (HTTP CONNECT, HTTP request, SOCKS), which writes blocked-connection events to the system log via logger(1) rather than stderr.

Why not stderr? The srt host process shares a terminal with the sandboxed child. Any stderr output from the host interrupts TUI rendering in applications such as Claude Code CLI — the primary use case for srt.

macOS — the message is suffixed with _SBX, the same tag srt uses in its seatbelt deny rules, making proxy-blocks visible in the same log stream as filesystem and mach-lookup denials:

log stream --predicate 'eventMessage ENDSWITH "_SBX"' --style compact

Example output:

srt proxy-blocked: HTTPS-CONNECT api.example.com:443_SBX

Linux — the message is written to syslog without the _SBX suffix (which is macOS seatbelt-specific). Monitor with journalctl -f or tail -f /var/log/syslog.

Example output:

srt proxy-blocked: HTTPS-CONNECT api.example.com:443

The existing logForDebugging() call is retained alongside so SRT_DEBUG=1 users continue to see proxy-block events in the verbose debug stream.

Changes

  • src/utils/debug.ts — add logProxyDeny(protocol, hostname, port)
  • src/sandbox/http-proxy.ts — call logProxyDeny in CONNECT and HTTP handlers before the 403 response
  • src/sandbox/socks-proxy.ts — call logProxyDeny before returning false from setRulesetValidator
  • test/utils/debug.test.ts — new test file verifying no stderr writes and logForDebugging gating

Test plan

  • bun test test/utils/debug.test.ts passes (verifies no stderr write for all three protocol values; logForDebugging remains SRT_DEBUG-gated)
  • Manual macOS: run srt with a domain not in allowedDomains; confirm event appears in log stream --predicate 'eventMessage ENDSWITH "_SBX"' without SRT_DEBUG set
  • Manual macOS: confirm no [srt] output appears in the terminal of the sandboxed child process
  • Manual Linux: confirm message appears in journalctl -f or /var/log/syslog
  • Existing debug output unchanged when SRT_DEBUG=1

🤖 Generated with Claude Code

javabrett added a commit to javabrett/sandbox-runtime that referenced this pull request Apr 13, 2026
Adds PR anthropic-experimental#216 (unconditional stderr logging for proxy-blocked connections).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@javabrett javabrett force-pushed the feat/unconditional-proxy-deny-logging branch 2 times, most recently from 406bcee to 6a13981 Compare April 13, 2026 21:59
When a network connection is blocked because its domain is not in
allowedDomains, srt previously offered no visible signal under normal
operation. Users hitting a blocked domain saw only a 403 or a failed
tool call, with no indication of which domain was responsible. SRT_DEBUG=1
was required to see anything, which is not practical in normal use.

This change adds logProxyDeny(), called from all three proxy handlers
(HTTP CONNECT, HTTP request, SOCKS), which writes blocked-connection
events to the system log via logger(1) rather than stderr:

- Avoids stderr because the srt host process shares a terminal with
  the sandboxed child. stderr output interrupts TUI rendering in
  applications such as Claude Code CLI.

- On macOS the message is suffixed with _SBX - the same tag srt uses
  in its seatbelt deny rules - making proxy-blocks visible in the same
  log stream as filesystem and mach-lookup denials:

    log stream --predicate 'eventMessage ENDSWITH "_SBX"' --style compact

  Example:
    srt proxy-blocked: HTTPS-CONNECT api.example.com:443_SBX

- On Linux the message is written to syslog without the _SBX suffix
  (which is macOS seatbelt-specific). Monitor with journalctl -f or
  tail -f /var/log/syslog.

  Example:
    srt proxy-blocked: HTTPS-CONNECT api.example.com:443

The existing logForDebugging() call is retained alongside so SRT_DEBUG=1
users continue to see proxy-block events in the debug stream.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@javabrett javabrett force-pushed the feat/unconditional-proxy-deny-logging branch from 6a13981 to a6e16ef Compare April 13, 2026 22:13
javabrett added a commit to javabrett/sandbox-runtime that referenced this pull request Apr 13, 2026
PR anthropic-experimental#216 updated: Linux support added (logger to syslog), srt-log-specific
references removed from comments, PR description updated for upstream.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@javabrett javabrett changed the title feat: log proxy-blocked connections unconditionally to stderr feat: log proxy-blocked connections to system log via logger Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant