[security-fix] Security Fix: Allocation Size Overflow in Bash Tool Merging (Alert #7)#1526
Merged
pelikhan merged 2 commits intosecurity-fix-alert-7-allocation-overflow-faaf2acfe1f8b66efrom Oct 11, 2025
Conversation
7 tasks
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix allocation size overflow in Bash tool merging
[security-fix] Security Fix: Allocation Size Overflow in Bash Tool Merging (Alert #7)
Oct 11, 2025
pelikhan
approved these changes
Oct 11, 2025
c4e59f4
into
security-fix-alert-7-allocation-overflow-faaf2acfe1f8b66e
7 checks passed
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
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: 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 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 and input validation, the fix takes a simpler approach:
var mergedCommands []anyinstead ofmake([]any, 0, capacity)This approach is appropriate because bash tool 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
✅ No artificial limits: Removed arbitrary maxBashCommands limit as it's unnecessary with append
✅ Maintainability: Cleaner code that's easier to review and maintain
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 noreply@anthropic.com
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.