-
Notifications
You must be signed in to change notification settings - Fork 185
[security-fix] Security fix: Prevent potential quoting injection in network hook generation (Alert #16) #4526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -32,12 +32,12 @@ func (g *NetworkHookGenerator) GenerateNetworkHookScript(allowedDomains []string | |||
| } | ||||
| } | ||||
|
|
||||
| // Embed domain list JSON directly as a Python literal (safe for []string from json.Marshal) | ||||
| // This prevents any quote-related injection vulnerabilities (CWE-78, CWE-89, CWE-94) | ||||
| // Use domainsJSON directly for ALLOWED_DOMAINS assignment | ||||
| // Embed domain list JSON using json.loads() to eliminate any quoting vulnerabilities | ||||
| // This approach prevents quote-related injection vulnerabilities (CWE-78, CWE-89, CWE-94) | ||||
| // by using Python's json.loads() to safely parse the JSON string | ||||
|
|
||||
| // Build the Python script using a safe template approach | ||||
| // The JSON array is embedded directly as a Python list literal | ||||
| // The JSON is parsed at runtime using json.loads() to avoid any quoting issues | ||||
| return fmt.Sprintf(`#!/usr/bin/env python3 | ||||
| """ | ||||
| Network permissions validator for Claude Code engine. | ||||
|
|
@@ -50,8 +50,8 @@ import urllib.parse | |||
| import re | ||||
|
|
||||
| # Domain allow-list (populated during generation) | ||||
| # JSON array safely embedded as Python list literal | ||||
| ALLOWED_DOMAINS = %s | ||||
| # JSON string is safely parsed using json.loads() to eliminate quoting vulnerabilities | ||||
|
||||
| # JSON string is safely parsed using json.loads() to eliminate quoting vulnerabilities |
Copilot
AI
Nov 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Security Issue: This fix introduces a NEW vulnerability rather than fixing the original issue.
Problem: Python triple-quoted strings (''') can be escaped if the JSON contains three consecutive single quotes. An attacker could inject a domain like test''']; import os; os.system('malicious'); x=[''' which would break out of the triple-quoted string and execute arbitrary Python code.
Why the original code was already safe:
json.Marshalon a[]stringproduces valid JSON like["domain1.com", "domain2.com"]- JSON strings use double quotes and escape special characters properly
- Direct interpolation of this into Python as
ALLOWED_DOMAINS = ["domain1.com", "domain2.com"]is safe because Python list syntax matches JSON array syntax exactly
The actual injection risk is minimal because:
- Domain validation would likely reject domains with quotes
- The input is
[]stringwhich is controlled by workflow configuration, not arbitrary user input - JSON marshaling escapes any special characters
Recommended fix: Revert this change. The original code was already safe for []string marshaled to JSON. If additional defense-in-depth is desired, validate domains against a strict pattern (alphanumeric, dots, hyphens, wildcards only) rather than using json.loads() with triple quotes.
See below for a potential fix:
// Embed domain list JSON directly as a Python list literal.
// This is safe because JSON arrays and Python lists have compatible syntax.
// No need for json.loads() or triple-quoted strings.
// Build the Python script using a safe template approach
return fmt.Sprintf(`#!/usr/bin/env python3
"""
Network permissions validator for Claude Code engine.
Generated by gh-aw from workflow-level network configuration.
"""
import sys
import urllib.parse
import re
# Domain allow-list (populated during generation)
# Embedded directly as a Python list literal (safe: JSON array syntax matches Python list syntax)
ALLOWED_DOMAINS = %s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation Accuracy Issue: These comments claim that using
json.loads()with triple-quoted strings "eliminates" quoting vulnerabilities, but this is incorrect. Triple-quoted strings in Python can still be escaped if the content contains'''(three consecutive single quotes), which could allow code injection.For example, if a domain value somehow contained
''']; malicious_code(); x=[''', it would break out of the triple-quoted string context.The original approach (direct Python list literal) was actually safer for
json.Marshal([]string)output because:These comments should either be removed or corrected to acknowledge that this approach doesn't eliminate injection risks, it only changes them.
See below for a potential fix: