[security-fix] Security Fix: Prevent unsafe quoting in network hook generation (Alert #16) #2038
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Security Fix: Prevent Unsafe Quoting in Network Hook Generation
Alert Number: #16
Severity: Critical (security_severity_level)
Rule: go/unsafe-quoting (CWE-78, CWE-89, CWE-94)
Vulnerability Description
CodeQL identified an unsafe quoting vulnerability in
pkg/workflow/engine_network_hooks.go:112. The code was directly embedding JSON-serialized domain arrays into a Python script usingfmt.Sprintfwithout proper escaping.While
json.Marshaloutput is typically safe for[]stringtypes, CodeQL correctly flagged this pattern as a potential injection vector. If the JSON content contains double quotes or other special characters, it could theoretically break out of the string context and alter the Python script's structure.Vulnerable Code Pattern:
The issue occurs at:
Fix Applied
Changed the approach from embedding JSON as a Python literal to using Python's
json.loads()to parse the JSON string at runtime:ALLOWED_DOMAINS = json.loads('...')Fixed Code:
Security Best Practices Applied
✅ Never embed serialized data directly into code literals
✅ Always use proper escaping for the target language
✅ Prefer runtime parsing over literal embedding for complex data
✅ Escape backslashes first to prevent escape sequence interference
✅ Make security considerations explicit in code comments
Testing
json.loads()ALLOWED_DOMAINS = json.loads('[]')Changes Made
Modified
pkg/workflow/engine_network_hooks.go:json.loads()(line 45)Updated
pkg/workflow/engine_network_test.go:json.loads()pattern (line 72)Impact
This fix eliminates the CWE-78 (Command Injection), CWE-89 (SQL Injection), and CWE-94 (Code Injection) vulnerabilities identified by CodeQL without changing the functionality of the network permissions system.
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com