Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/workflow/engine_network_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +35 to +37
Copy link

Copilot AI Nov 22, 2025

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:

  1. JSON arrays map directly to Python list literals
  2. JSON escaping handles all special characters
  3. No additional parsing layer needed

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:

	// Embed domain list JSON using json.loads() to reduce quoting vulnerabilities compared to manual string interpolation.
	// This approach helps mitigate some quote-related injection risks (CWE-78, CWE-89, CWE-94),
	// but does not eliminate them entirely. Care must be taken to ensure the embedding context is secure.

	// Build the Python script using a template approach.
	// The JSON is parsed at runtime using json.loads(), which handles escaping, but the embedding context must still be safe.

Copilot uses AI. Check for mistakes.

// 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.
Expand All @@ -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
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation Accuracy Issue: This comment claims the JSON is "safely parsed" to eliminate quoting vulnerabilities, but using triple-quoted strings with json.loads() doesn't eliminate the risk—it changes it. Python triple-quoted strings can be escaped with ''', creating a potential injection vector.

The comment should be corrected or removed to avoid giving false security assurances.

Suggested change
# JSON string is safely parsed using json.loads() to eliminate quoting vulnerabilities

Copilot uses AI. Check for mistakes.
ALLOWED_DOMAINS = json.loads('''%s''')
Copy link

Copilot AI Nov 22, 2025

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:

  1. json.Marshal on a []string produces valid JSON like ["domain1.com", "domain2.com"]
  2. JSON strings use double quotes and escape special characters properly
  3. 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 []string which 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

Copilot uses AI. Check for mistakes.

def extract_domain(url_or_query):
"""Extract domain from URL or search query."""
Expand Down
Loading