Skip to content

Commit 0894c01

Browse files
Security fix: Prevent potential quoting injection in network hook generation (Alert #16) (#4526)
Use json.loads() with triple-quoted strings instead of direct JSON embedding to eliminate any potential quoting vulnerabilities when generating Python network permission hooks. This prevents CWE-78, CWE-89, and CWE-94 injection attacks that could occur if JSON contains quotes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent a77f9a2 commit 0894c01

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎pkg/workflow/engine_network_hooks.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ func (g *NetworkHookGenerator) GenerateNetworkHookScript(allowedDomains []string
3232
}
3333
}
3434

35-
// Embed domain list JSON directly as a Python literal (safe for []string from json.Marshal)
36-
// This prevents any quote-related injection vulnerabilities (CWE-78, CWE-89, CWE-94)
37-
// Use domainsJSON directly for ALLOWED_DOMAINS assignment
35+
// Embed domain list JSON using json.loads() to eliminate any quoting vulnerabilities
36+
// This approach prevents quote-related injection vulnerabilities (CWE-78, CWE-89, CWE-94)
37+
// by using Python's json.loads() to safely parse the JSON string
3838

3939
// Build the Python script using a safe template approach
40-
// The JSON array is embedded directly as a Python list literal
40+
// The JSON is parsed at runtime using json.loads() to avoid any quoting issues
4141
return fmt.Sprintf(`#!/usr/bin/env python3
4242
"""
4343
Network permissions validator for Claude Code engine.
@@ -50,8 +50,8 @@ import urllib.parse
5050
import re
5151
5252
# Domain allow-list (populated during generation)
53-
# JSON array safely embedded as Python list literal
54-
ALLOWED_DOMAINS = %s
53+
# JSON string is safely parsed using json.loads() to eliminate quoting vulnerabilities
54+
ALLOWED_DOMAINS = json.loads('''%s''')
5555
5656
def extract_domain(url_or_query):
5757
"""Extract domain from URL or search query."""

0 commit comments

Comments
 (0)