Skip to content

Commit b9fd83a

Browse files
committed
DangerousShellChars: Add \r and \f
1 parent 7c36b23 commit b9fd83a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

agent_api/src/main/java/dev/aikido/agent_api/vulnerabilities/shell_injection/DangerousShellChars.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public final class DangerousShellChars {
77
private DangerousShellChars() {}
88
private static final List<String> DANGEROUS_CHARS = Arrays.asList(
99
"#", "!", "\"", "$", "&", "'", "(", ")", "*", ";", "<", "=", ">", "?",
10-
"[", "\\", "]", "^", "`", "{", "|", "}", " ", "\n", "\t", "~"
10+
"[", "\\", "]", "^", "`", "{", "|", "}", " ", "\n", "\t", "~", "\r", "\f"
1111
);
1212

1313
public static boolean containDangerousCharacter(String userInput) {

agent_api/src/test/java/vulnerabilities/shell_injection/ShellInjectionDetectorTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,24 @@ void testItFlagsCommaInLoop() {
439439
void testCarriageReturnAsSeparator() {
440440
// \r (carriage return) as separator before dangerous command
441441
assertIsShellInjection("ls\rrm", "rm");
442+
assertIsShellInjection("sleep\r5", "sleep\r5");
442443
assertIsShellInjection("echo test\rrm -rf /", "rm");
443444
}
444445

445446
@Test
446447
void testFormFeedAsSeparator() {
447448
// \f (form feed) as separator before dangerous command
448449
assertIsShellInjection("ls\frm", "rm");
450+
assertIsShellInjection("sleep\f5", "sleep\f5");
449451
assertIsShellInjection("echo test\frm -rf /", "rm");
450452
}
453+
454+
@Test
455+
void testCommandExactlyMatchesUserInputWithSeparators() {
456+
// When command equals userInput and contains \r or \f separators
457+
assertIsShellInjection("ls\rrm", "ls\rrm");
458+
assertIsShellInjection("ls\frm", "ls\frm");
459+
assertIsShellInjection("echo\rcat /etc/passwd", "echo\rcat /etc/passwd");
460+
assertIsShellInjection("echo\fcat /etc/passwd", "echo\fcat /etc/passwd");
461+
}
451462
}

0 commit comments

Comments
 (0)