Directory Traversal: Attacker-controlled Data Used in File Path via request in CustomerController.saveSettings
#2
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.
Qwiet AI AutoFix
This PR was created automatically by the Qwiet AI AutoFix tool.
Some manual intervention might be required before merging this PR.
Fix for Finding 22
Fix Notes
The code fix addresses the directory traversal vulnerability by:
isValidFilename()that uses a whitelist approach to only allow alphanumeric characters, underscores, hyphens, and periods in filenames, and explicitly rejects any filename containing "..".These changes effectively mitigate the CWE-22 (Path Traversal) vulnerability by ensuring files can only be written to the intended directory and preventing any manipulation that would allow writing to sensitive system locations.
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
Looking at the code, I can see a clear directory traversal vulnerability. The application uses attacker-controlled input from a cookie for file paths without proper validation, allowing path traversal outside the intended directory.
Testcases
Commits/Files Changed