Skip to content

Commit 16e5c8b

Browse files
committed
fix: Enforce domain restrictions for WebSearch tool and improve feedback on access blocks
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
1 parent 36f2642 commit 16e5c8b

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

.github/workflows/example-engine-network-permissions.lock.yml

Lines changed: 19 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/workflow/engine_network_hooks.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ try:
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:
8794
func (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
9499
cat > .claude/hooks/network_permissions.py << 'EOF'
95100
%s
96101
EOF
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

Comments
 (0)