Skip to content

Commit 64b5669

Browse files
committed
Make path traversal containment check case-insensitive
1 parent 138bf8b commit 64b5669

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

agent_api/src/main/java/dev/aikido/agent_api/vulnerabilities/path_traversal/PathTraversalDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public DetectorResult run(String userInput, String[] arguments) {
3030
// Ignore cases where the user input is longer than the file path.
3131
return new DetectorResult();
3232
}
33-
if (!filePath.contains(userInput)) {
33+
if (!filePath.toLowerCase().contains(userInput.toLowerCase())) {
3434
// Ignore cases where the user input is not part of the file path.
3535
return new DetectorResult();
3636
}

agent_api/src/test/java/vulnerabilities/path_traversal/PathTraversalDetectorTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,11 @@ public void testUserInputWithEmptyFilePath() {
210210
public void testUserInputWithFilePathContainingSpaces() {
211211
assertNotAttack(PathTraversalDetector.INSTANCE.run("test file", new String[]{"directory/test file.txt"}));
212212
}
213+
214+
@Test
215+
public void testCaseInsensitiveContainmentDetectsTraversal() {
216+
assertAttack(PathTraversalDetector.INSTANCE.run("/ETC/passwd", new String[]{"/etc/passwd"}));
217+
assertAttack(PathTraversalDetector.INSTANCE.run("/ETC/PASSWD", new String[]{"/etc/passwd"}));
218+
assertAttack(PathTraversalDetector.INSTANCE.run("/HOME/USER/file.txt", new String[]{"/home/user/file.txt"}));
219+
}
213220
}

0 commit comments

Comments
 (0)