[security-fix] Fix integer overflow vulnerabilities in uint to int conversions (Alerts #413-418) #7908
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: Integer Overflow or Wraparound in Timeout Conversions
Alert Numbers: #413, #414, #415, #416, #417, #418
Severity: HIGH
Rule: G115 - integer overflow conversion uint64 → int64
Tool: gosec (Golang security checks)
Vulnerability Description
Gosec detected 6 HIGH severity integer overflow vulnerabilities where
uintanduint64values were being converted directly tointwithout checking for potential overflow. This can lead to:math.MaxIntAffected Locations:
Fix Applied
Added safe conversion helper functions that check for overflow before converting:
frontmatter_extraction_metadata.go:
safe_inputs_parser.go:
Applied these safe conversions to all 6 problematic conversions.
Security Best Practices Applied
✅ Overflow Detection: Check if value exceeds math.MaxInt before conversion
✅ Safe Fallback: Return 0 (engine default timeout) if overflow would occur
✅ No Breaking Changes: Behavior is identical for valid values
✅ Defensive Programming: Follows Go best practices for type conversions
✅ G115 Compliance: Satisfies gosec security scanner requirements
Testing
✅ All tests pass:
go test ./pkg/workflow/...succeeds✅ Build successful:
go build ./pkg/workflow/...passes without errors✅ No breaking changes: Normal operation unchanged for valid timeout values
✅ Overflow handling: Values that would overflow safely default to 0
Impact Assessment
Risk: Minimal
Breaking Changes: None
Backwards Compatibility: Full
Performance: Negligible overhead (single integer comparison per conversion)
The fix only adds overflow checking before type conversion. For valid timeout values (which will always be well below math.MaxInt in practice), the behavior is identical. For edge cases where overflow would occur, the function now safely returns 0 instead of causing undefined behavior.
Why This Fix Is Important
Files Modified
pkg/workflow/frontmatter_extraction_metadata.go:safeUintToInt()andsafeUint64ToInt()helper functionsextractToolsTimeout()(lines 179, 181)extractToolsStartupTimeout()(lines 207, 209)pkg/workflow/safe_inputs_parser.go:safeUint64ToIntForTimeout()helper functionParseSafeInputsFromFrontmatter()(line 224)MergeSafeInputs()(line 408)References