6666 target = tool_input.get('url') or tool_input.get('query', '')
6767 domain = extract_domain(target)
6868
69- # For WebSearch, be more permissive unless specific domain mentioned
69+ # For WebSearch, apply domain restrictions consistently
70+ # Only allow if domain is in allowlist or if no domain detected AND allowlist is empty
7071 if tool_name == 'WebSearch' and not domain:
71- sys.exit(0) # Allow general searches
72+ # Block general searches when domain restrictions are in place
73+ if ALLOWED_DOMAINS:
74+ print(f"Network access blocked for WebSearch: no specific domain detected", file=sys.stderr)
75+ print(f"Allowed domains: {', '.join(ALLOWED_DOMAINS)}", file=sys.stderr)
76+ sys.exit(2) # Block general searches when restrictions exist
77+ else:
78+ sys.exit(0) # Allow general searches only when no restrictions
7279
7380 if not is_domain_allowed(domain):
7481 print(f"Network access blocked for domain: {domain}", file=sys.stderr)
@@ -87,14 +94,12 @@ except Exception as e:
8794func (g * NetworkHookGenerator ) GenerateNetworkHookWorkflowStep (allowedDomains []string ) GitHubActionStep {
8895 hookScript := g .GenerateNetworkHookScript (allowedDomains )
8996
90- // Escape the script content for use in YAML heredoc
91- escapedScript := strings .ReplaceAll (hookScript , "'" , "'\" '\" '" )
92-
97+ // No escaping needed for heredoc with 'EOF' - it's literal
9398 runContent := fmt .Sprintf (`mkdir -p .claude/hooks
9499cat > .claude/hooks/network_permissions.py << 'EOF'
95100%s
96101EOF
97- chmod +x .claude/hooks/network_permissions.py` , escapedScript )
102+ chmod +x .claude/hooks/network_permissions.py` , hookScript )
98103
99104 var lines []string
100105 lines = append (lines , " - name: Generate Network Permissions Hook" )
0 commit comments