Security Fix: Path Traversal Vulnerability in logs_parsing.go (Alert #474)#9294
Merged
Security Fix: Path Traversal Vulnerability in logs_parsing.go (Alert #474)#9294
Conversation
…474) Fixed path traversal vulnerability in parseAwInfo function by adding filepath.Clean() sanitization. The cleanPath variable is now used consistently for all file operations, preventing path traversal attacks. 🤖 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: Path Traversal Vulnerability
Alert Number: #474
Severity: MEDIUM
Rule: G304 - Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
File: pkg/cli/logs_parsing.go:57
Vulnerability Description
The
parseAwInfofunction inpkg/cli/logs_parsing.gouses theinfoFilePathparameter directly in file operations (os.ReadFileandos.Stat) without sanitizing it first. This could potentially allow path traversal attacks where a malicious actor could use sequences like../to access files outside the intended directory.The gosec scanner flagged line 57 where
os.ReadFile(infoFilePath)is called with an unsanitized path parameter.Fix Applied
Added path sanitization using
filepath.Clean()at the beginning of theparseAwInfofunction:cleanPath := filepath.Clean(infoFilePath)to sanitize the input pathcleanPathinstead ofinfoFilePathThe
filepath.Clean()function normalizes the path by:.elements..elements to prevent directory traversalSecurity Best Practices
cleanPathis used for all file operations (stat, read) and loggingfilepath.Clean()which is the recommended approach for path normalizationTesting Considerations
.and..components are handled correctly../../../../etc/passwd) are properly sanitizedaw_info.jsonfiles in directories are still found correctlyRelated Alerts
This fix follows the same pattern successfully applied to other path traversal vulnerabilities in the codebase, including: