[security-fix] Security Fix: Allocation Size Overflow in Bash Tool Merging (Alert #7) #1525
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 Bash Tool Merging
Alert Number: #7
Severity: High (security_severity_level: high)
Rule: go/allocation-size-overflow
File:
pkg/workflow/compiler.go:1492CWE: CWE-190 (Integer Overflow or Wraparound)
Vulnerability Description
The workflow compiler's bash tool merging logic was vulnerable to allocation size overflow when computing the capacity for merged command arrays. 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
bashArrayfrom user configuration was extremely large (close to max int), adding it tolen(constants.DefaultBashTools)could:make()While
DefaultBashToolsis a small array (~11 elements),bashArraycomes from user-provided workflow configuration and could theoretically be very large.Fix Applied
The fix implements multiple layers of protection against allocation overflow:
1. Input Validation
Added a reasonable upper limit for bash commands:
2. Overflow Detection
Check the capacity calculation result for overflow:
3. Security Documentation
Added clear comments explaining the CWE-190 mitigation strategy.
Security Best Practices Applied
✅ Input Validation: Limit the size of potentially large user inputs before computation
✅ Overflow Guards: Check calculation results for negative values (overflow indicator)
✅ Reasonable Limits: Define sensible maximum values (10,000 bash commands is more than sufficient)
✅ Defense in Depth: Multiple layers of protection (input validation + result validation)
✅ Graceful Degradation: Silently truncate to maintain functionality rather than panic
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 #7. There are 8 other open code scanning alerts:
pkg/workflow/engine_network_hooks.go(PR [security-fix] Security Fix: Unsafe Quoting in Network Hook Generation (Alert #9) #1521)pkg/parser/frontmatter.go(PR [security-fix] Security Fix: Unsafe Quoting in Import Directive Warning (Alert #8) #1523)pkg/parser/mcp.goReferences
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]