Skip to content

Commit

Permalink
Removed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hr2904 committed Jun 11, 2024
1 parent f88b042 commit 4165f91
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,9 @@ public static boolean validateFilePath(String fileToImport) {
String allowedDirectory = "/var/app/allowed/";

try {
// Decode URL-encoded characters first
String decodedPath = URLDecoder.decode(fileToImport, "UTF-8");

Path normalizedPath = Paths.get(decodedPath).normalize();

// Check for directory traversal attempts after decoding
if (decodedPath.contains("..") || decodedPath.contains("./") || decodedPath.contains(".\\")) {
return false;
}
Expand All @@ -205,7 +202,6 @@ public static boolean validateFilePath(String fileToImport) {
} catch (UnsupportedEncodingException e) {
return false;
} catch (Exception e) {
// Handle other exceptions, such as those thrown by Paths.get() for invalid paths
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,12 @@ private void handleRedirect(HttpServletRequest servletRequest, HttpServletRespon
public static String sanitizeRedirectLocation(String redirectLocation) {
if (redirectLocation == null) return null;
try {
// Remove CR and LF characters to preemptively prevent response splitting
String preProcessedUrl = redirectLocation.replace("\r", "").replace("\n", "");

// Encode any percent signs not already part of a percent-encoded sequence
preProcessedUrl = preProcessedUrl.replaceAll("%(?![0-9a-fA-F]{2})", "%25");

// URL encode the entire string
String encodedUrl = URLEncoder.encode(preProcessedUrl, "UTF-8");

// Normalize encoded sequences that might be affected by double encoding
encodedUrl = encodedUrl.replaceAll("%25([0-9a-fA-F]{2})", "%$1");

return encodedUrl;
Expand Down

0 comments on commit 4165f91

Please sign in to comment.