Skip to content

Update PathTraversalVulnerability.java#471

Open
tidaaartorhem wants to merge 1 commit intoSasanLabs:masterfrom
tidaaartorhem:patch-Issue-448-PathTraversalVulnerability
Open

Update PathTraversalVulnerability.java#471
tidaaartorhem wants to merge 1 commit intoSasanLabs:masterfrom
tidaaartorhem:patch-Issue-448-PathTraversalVulnerability

Conversation

@tidaaartorhem
Copy link
Copy Markdown

Key Changes Explained:

  • Enhanced security checks: Added checks to prevent Path Traversal attacks by verifying that the file name does not contain ".." and is within the list of allowed file names.

  • Improved error handling: Changed the HTTP response codes to more accurately reflect the nature of the error (e.g., returning 404 Not Found for missing files and 403 Forbidden for unauthorized access attempts).

  • Condition validation: Immediately returns a 400 Bad Request if the precondition is not met, which helps in quickly identifying issues with request parameters.

  • Error Logging: Now logs different types of errors distinctly for better diagnostics.

Key Changes Explained:
Enhanced security checks: Added checks to prevent Path Traversal attacks by verifying that the file name does not contain ".." and is within the list of allowed file names.
Improved error handling: Changed the HTTP response codes to more accurately reflect the nature of the error (e.g., returning 404 Not Found for missing files and 403 Forbidden for unauthorized access attempts).
Condition validation: Immediately returns a 400 Bad Request if the precondition is not met, which helps in quickly identifying issues with request parameters.
Error Logging: Now logs different types of errors distinctly for better diagnostics.Key Changes Explained:
Enhanced security checks: Added checks to prevent Path Traversal attacks by verifying that the file name does not contain ".." and is within the list of allowed file names.
Improved error handling: Changed the HTTP response codes to more accurately reflect the nature of the error (e.g., returning 404 Not Found for missing files and 403 Forbidden for unauthorized access attempts).
Condition validation: Immediately returns a 400 Bad Request if the precondition is not met, which helps in quickly identifying issues with request parameters.
Error Logging: Now logs different types of errors distinctly for better diagnostics.
}

// Preventing Path Traversal and ensuring only allowed filenames are processed.
if (fileName.contains("..") || !ALLOWED_FILE_NAMES.contains(fileName)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? we wanted to introduce vulnerability in the application and this will disallow ".." in file name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants