-
Notifications
You must be signed in to change notification settings - Fork 28
[security-fix] Security Fix: Unsafe Quoting in Network Hook Generation (Alert #9) #1521
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**Alert Number**: #9 **Severity**: Critical (security_severity_level: critical) **Rule**: go/unsafe-quoting **CWE**: CWE-78, CWE-89, CWE-94 ## Vulnerability Description The code was embedding JSON data directly into a Python script template without proper quote escaping. If the JSON contained double quotes, it could break out of the string context and potentially allow code injection when the generated Python script is executed. ## Fix Applied 1. Added `strconv` import to use Go's built-in string quoting function 2. Used `strconv.Quote()` to properly escape the JSON string for safe embedding in Python code 3. Changed the Python template to use `json.loads()` with the properly quoted string instead of direct literal embedding 4. Added clear security comments explaining the fix ## Security Best Practices - Always use proper escaping when embedding dynamic data in code templates - Use `strconv.Quote()` for Go string literals that will be embedded - Validate and sanitize all user-provided data before code generation - Use structured APIs (like json.loads) rather than direct string embedding ## Testing Considerations - Test with domain lists containing special characters (quotes, backslashes) - Verify the generated Python script parses correctly - Ensure network permissions hook functions as expected - Validate no breaking changes to existing functionality 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
pelikhan
approved these changes
Oct 11, 2025
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Contributor
|
@copilot investigate the test failures |
Contributor
4 tasks
5 tasks
* Initial plan * Fix compilation error: use domainsJSON instead of undefined quotedJSON Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
|
@copilot format lint, recompile |
5 tasks
Contributor
7 tasks
7 tasks
Contributor
Author
|
Agentic Changeset Generator triggered by this pull request |
Merged
7 tasks
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
pelikhan
approved these changes
Oct 11, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: Unsafe Quoting in Network Hook Generation
Alert Number: #9
Severity: Critical (security_severity_level: critical)
Rule: go/unsafe-quoting
File:
pkg/workflow/engine_network_hooks.go:104CWE: CWE-78 (OS Command Injection), CWE-89 (SQL Injection), CWE-94 (Code Injection)
Vulnerability Description
The
GenerateNetworkHookScriptfunction was embedding JSON-encoded domain data directly into a Python script template without proper quote escaping. The vulnerable pattern was:If the JSON data contained double quotes or other special characters, it could break out of the intended string context in the generated Python script. While JSON arrays are syntactically compatible with Python literals in most cases, this pattern is flagged as unsafe because:
Fix Applied
The fix implements proper quote escaping using Go's standard library:
strconvimport: Provides access tostrconv.Quote()functionstrconv.Quote(): Safely escapes the JSON string for Python embeddingjson.loads()with the properly quoted stringBefore:
After:
Security Best Practices Applied
✅ Input Sanitization: All dynamic data is properly escaped before embedding
✅ Defense in Depth: Using
json.loads()adds an additional parsing layer✅ Standard Library Functions: Leveraging
strconv.Quote()ensures correct escaping✅ Code Documentation: Clear comments explain the security considerations
Testing Considerations
To validate this fix, please test:
Impact Assessment
Risk Level: Low
Functionality: No Changes
Related Security Alerts
This PR fixes CodeQL alert #9. There are 8 other open code scanning alerts in the repository:
pkg/parser/frontmatter.go🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com