Layered security: bash analysis, SSRF prevention, and secret scanning
import type { AddressFamily, LookupAddress as AxiosLookupAddress } from 'axios'import { lookup as dnsLookup } from 'dns'import { isIP } from 'net'/**
* SSRF guard for HTTP hooks.
*
* Blocks private, link-local, and other non-routable address ranges to prevent
* project-configured HTTP hooks from reaching cloud metadata endpoints
* (169.254.169.254) or internal infrastructure.
*
* Loopback (127.0.0.0/8, ::1) is intentionally ALLOWED — local dev policy
* servers are a primary HTTP hook use case.
*
* When a global proxy or the sandbox network proxy is in use, the guard is
* effectively bypassed for the target host because the proxy performs DNS
* resolution. The sandbox proxy enforces its own domain allowlist.
*/
/**
* Returns true if the address is in a range that HTTP hooks should not reach.
*
* Blocked IPv4:
* 0.0.0.0/8 "this" network
* 10.0.0.0/8 private
* 100.64.0.0/10 shared address space / CGNAT (some cloud metadata, e.g. Alibaba 100.100.100.200)
* 169.254.0.0/16 link-local (cloud metadata)
* 172.16.0.0/12 private
* 192.168.0.0/16 private
*
* Blocked IPv6:
* :: unspecified
* fc00::/7 unique local
* fe80::/10 link-local
* ::ffff:<v4> mapped IPv4 in a blocked range
*
* Allowed (returns false):
* 127.0.0.0/8 loopback (local dev hooks)
* ::1 loopback
* everything else
*/
export function isBlockedAddress(address: string): boolean {const v = isIP(address)
if (v === 4) {return isBlockedV4(address)
}
if (v === 6) {return isBlockedV6(address)
}
// Not a valid IP literal — let the real DNS path handle it (this function
// is only called on results from dns.lookup, which always returns valid IPs)
return false
}
function isBlockedV4(address: string): boolean { const parts = address.split('.').map(Number)const [a, b] = parts
if (
parts.length !== 4 ||
a === undefined ||
Security in Claude Code is layered — no single check is trusted to catch everything. For bash execution: the command is AST-parsed for dangerous patterns, classified for safety, checked against permission rules, then sandboxed if configured.
Defense-in-depth: even if one layer fails (e.g., a dangerous pattern slips past the AST parser), the next layer (permission rules, sandbox isolation) catches it. Security is not a single gate — it's a pipeline.
The secretScanner.ts uses gitleaks-based regex rules to detect AWS keys, GitHub PATs, JWT tokens, and other credentials in memory files before they're uploaded to the server. If a match is found, the upload is blocked and the user is warned.
The SSRF guard is specifically designed to prevent hook configs from pointing Claude Code at internal services. A malicious MCP server could inject hook URLs that exfiltrate secrets — the guard prevents this.
Ask anything about Security Defense-in-Depth
Powered by Groq · Enter to send, Shift+Enter for newline