Skip to content

Commit 822a68c

Browse files
author
drighetto
committed
Debug UT
1 parent bef4b52 commit 822a68c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/java/eu/righettod/SecurityUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,11 @@ public static boolean isPathSafe(String path) {
11771177
//URL decode the path if case of data coming from a web context
11781178
String decodedPath = applyURLDecoding(path, decodingRoundThreshold);
11791179
//Remove any path escaping sequence
1180-
decodedPath = decodedPath.replace("\\/", "/").replace("\\\\", "\\");
1180+
if (File.separatorChar == '/') {
1181+
decodedPath = decodedPath.replace("\\", "");
1182+
} else {
1183+
decodedPath = decodedPath.replace("\\\\", "");
1184+
}
11811185
//Ensure that no path traversal path is present
11821186
File f = new File(decodedPath);
11831187
String canonicalPath = f.getCanonicalPath();

src/test/java/eu/righettod/TestSecurityUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ public void isPathSafe() {
541541
"%252Fhome%252F%252E%252E%252F%252E%252E%252F%252E%252E%252F%252E%252E%252Fetc%252Fpassword", //URL encoding X2
542542
"%25252525252Fhome%25252525252F%25252525252E%25252525252E%25252525252F%25252525252E%25252525252E%25252525252F%25252525252E%25252525252E%25252525252F%25252525252E%25252525252E%25252525252Fetc%25252525252Fpassword", //URL encoding X6
543543
"/home/..\\/..\\/..\\/..\\/etc/password",
544-
"/home/..\\\\/..\\/..\\\\/..\\/etc/password"
544+
"/home/..\\\\/..\\/..\\\\/..\\/etc/password",
545+
"D:\\test..\\\\\\test"
545546
);
546547
invalidPaths.forEach(p -> {
547548
assertFalse(SecurityUtils.isPathSafe(p), String.format(templateMsgFalseNegative, p));

0 commit comments

Comments
 (0)