Conversation
…lection (Alert #20) Fix CWE-190 allocation size overflow vulnerability in pkg/workflow/mcp-config.go at line 314. The code was computing slice capacity by adding two map lengths (len(mcpConfig.Env)+len(headerSecrets)), which could overflow with extremely large maps. Changed from pre-allocated slice to letting Go's append handle capacity automatically, following the same pattern used in previous fixes (alerts #6, #7). This eliminates the overflow risk while maintaining efficiency for typical use cases where environment variable maps are small. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
pelikhan
approved these changes
Oct 15, 2025
Contributor
Author
|
Agentic Changeset Generator triggered by this pull request |
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 Environment Key Collection
Alert Number: #20
Severity: High (security_severity_level: high)
Rule: go/allocation-size-overflow
File:
pkg/workflow/mcp-config.go:314CWE: CWE-190 (Integer Overflow or Wraparound)
Vulnerability Description
The
renderSharedMCPConfigfunction was vulnerable to allocation size overflow when computing the capacity for the environment keys array. 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 either
mcpConfig.EnvorheaderSecretsmaps were extremely large (close to max int), adding their lengths could:make()While both maps come from MCP server configuration and are typically small, large configurations could theoretically trigger this vulnerability.
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 envKeys []stringinstead ofmake([]string, 0, capacity)This approach is appropriate because environment variable maps 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
✅ Consistent pattern: Follows the same fix pattern used in alerts #6, #7, #28
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 #20. There is also alert #21 in the same file with a similar pattern that should be addressed separately.
Previous similar fixes:
pkg/parser/mcp.go(PR [security-fix] Security Fix: Allocation Size Overflow in Domain List Merging (Alert #6) #1528)pkg/workflow/compiler.go(PR [security-fix] Security Fix: Allocation Size Overflow in Bash Tool Merging (Alert #7) #1526)gh-awis compiled before starting watch mode task #28: Similar pattern (if exists)References
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com