Directory Traversal: Attacker-controlled Data Used in File Path via request in CustomerController.saveSettings#61
Open
ongamse wants to merge 1 commit into
Open
Directory Traversal: Attacker-controlled Data Used in File Path via request in CustomerController.saveSettings#61ongamse wants to merge 1 commit into
request in CustomerController.saveSettings#61ongamse wants to merge 1 commit into
Conversation
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.
Harness SAST and SCA AutoFix
This PR was created automatically by the Harness SAST and SCA AutoFix tool.
Some manual intervention might be required before merging this PR.
Fix for Finding 12
Fix Notes
The code has been completely rewritten to eliminate directory traversal vulnerabilities by implementing the approaches suggested in the mitigation notes:
Storage Abstraction Layer: The code now generates secure filenames based on UUIDs, which completely removes user control over the filename. This approach creates randomized, unpredictable filenames.
Content-Addressed Storage: The code also implements a content-addressed approach where the filename is derived from the SHA-256 hash of the content being stored. This creates a deterministic filename based on content, not user input.
User-to-Filename Mapping: A mechanism to store the mapping between user identifiers and generated filenames has been added, allowing for file retrieval later.
Path Security: The code maintains proper path normalization and resolution to ensure all file operations occur within the intended directory.
These changes completely eliminate the root cause of directory traversal by removing user input from the filename determination process. Rather than attempting to validate potentially malicious input, the approach prevents the issue by design. This follows the security principle of using "secure by design" patterns instead of relying on input validation alone.
Vulnerability Description
Attacker-Controlled input data is used as part of a file path to write a file without escaping or validation. This indicates a directory traversal vulnerability.
Attack Payloads
[
Testcases
Commits/Files Changed