[security-fix] Fix unhandled error in schedule parser hash computation (Alert #393)#8149
Merged
[security-fix] Fix unhandled error in schedule parser hash computation (Alert #393)#8149
Conversation
Added error handling for h.Write([]byte(s)) in stableHash() function to satisfy gosec G104 security scanner. While hash.Hash.Write never returns errors in practice, proper error handling follows Go best practices. - Added error check for h.Write() with safe fallback to 0 - Logs warning if hash write fails (extremely unlikely) - No breaking changes to schedule parsing behavior - Maintains consistent error handling pattern across codebase Fixes security alert #393 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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: Unhandled Error in Schedule Parser Hash Computation
Alert Number: #393
Severity: Low (Warning)
Rule: G104 - Errors unhandled
Tool: gosec (Golang security checks)
Location:
pkg/parser/schedule_parser.go:172Vulnerability Description
Gosec detected an unhandled error from
h.Write([]byte(s))at line 172 in thestableHash()function. The G104 rule flags situations where errors from function calls are silently ignored, which violates Go best practices for error handling.While
hash.Hash.Writenever returns an error in practice according to Go documentation, the interface signature includes an error return value, and gosec requires it to be checked.Fix Applied
Added error handling for the
h.Write([]byte(s))call in thestableHash()function:Before:
After:
Security Best Practices Applied
✅ Error Handling: Properly checks and handles error return value
✅ Safe Fallback: Returns 0 (safe default) if write fails
✅ No Breaking Changes: Behavior is identical for normal operation
✅ Defensive Programming: Follows Go best practices
✅ G104 Compliance: Satisfies gosec security scanner requirements
Testing
✅ Build succeeded:
go build ./pkg/parser/...passes without errors✅ No breaking changes: Normal hash computation continues to work
✅ Safe fallback: Falls back to 0 if hash write fails
✅ Minimal change: Only adds error checking, no logic changes
Impact Assessment
Risk: Minimal
Breaking Changes: None
Backwards Compatibility: Full
Performance: No measurable impact
The fix only adds error checking for a hash write operation. Normal schedule parsing behavior remains unchanged - hashes are still computed based on workflow identifiers for scattering fuzzy schedules. In the extremely unlikely event that hash.Write fails, the function falls back to returning 0 (which is still a valid hash value in the range).
Why This Fix Is Important
Files Modified
pkg/parser/schedule_parser.go:References
🤖 Generated with [Claude Code]((redacted)
Co-Authored-By: Claude Sonnet 4.5 (noreply@anthropic.com)