[security-fix] Security Fix: Allocation Size Overflow in Domain List Merging (Alert #6) #1528
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: Allocation Size Overflow in Domain List Merging
Alert Number: #6
Severity: High (security_severity_level: high)
Rule: go/allocation-size-overflow
File:
pkg/parser/mcp.go:35CWE: CWE-190 (Integer Overflow or Wraparound)
Vulnerability Description
The
EnsureLocalhostDomainsfunction was vulnerable to allocation size overflow when computing the capacity for the merged domain list. The vulnerable pattern was:When computing the size of an allocation based on potentially large values, the result may overflow (for signed integer types) or wraparound (for unsigned types). An overflow causes the result to become negative, while a wraparound results in a small positive number.
If the
domainsslice from user configuration was extremely large (close to max int), adding 4 to it could:make()While the function only adds 4 localhost domains, the
domainsparameter comes from user-provided workflow configuration and could theoretically be very large.Fix Applied
The fix eliminates the overflow risk by removing pre-allocation entirely and relying on Go's append function to handle capacity growth automatically:
Approach
Rather than implementing complex overflow guards, the fix takes a simpler approach:
var result []stringinstead ofmake([]string, 0, capacity)This approach is appropriate because domain arrays are not expected to be large, and Go's append function is optimized for incremental growth.
Security Best Practices Applied
✅ Simplicity over complexity: Removed unnecessary pre-allocation logic that introduced overflow risk
✅ Language built-ins: Relied on Go's append function which handles capacity safely
✅ Maintainability: Cleaner code that's easier to review and maintain
✅ Defense in Depth: Eliminates the vulnerability at its source
Testing Considerations
To validate this fix, please test:
Impact Assessment
Risk Level: Low
Functionality: No Breaking Changes
Related Security Alerts
This PR fixes CodeQL alert #6. There are 8 other open code scanning alerts in the repository:
pkg/workflow/engine_network_hooks.go(PR [security-fix] Security Fix: Unsafe Quoting in Network Hook Generation (Alert #9) #1521)pkg/parser/frontmatter.gopkg/workflow/compiler.go(PRs [security-fix] Security Fix: Allocation Size Overflow in Bash Tool Merging (Alert #7) #1525, [security-fix] Security Fix: Allocation Size Overflow in Bash Tool Merging (Alert #7) #1526)References
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com