Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class DangerousShellChars {
private DangerousShellChars() {}
private static final List<String> DANGEROUS_CHARS = Arrays.asList(
"#", "!", "\"", "$", "&", "'", "(", ")", "*", ";", "<", "=", ">", "?",
"[", "\\", "]", "^", "`", "{", "|", "}", " ", "\n", "\t", "~"
"[", "\\", "]", "^", "`", "{", "|", "}", " ", "\n", "\t", "~", "\r", "\f"
);

public static boolean containDangerousCharacter(String userInput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,24 @@ void testItFlagsCommaInLoop() {
void testCarriageReturnAsSeparator() {
// \r (carriage return) as separator before dangerous command
assertIsShellInjection("ls\rrm", "rm");
assertIsShellInjection("sleep\r5", "sleep\r5");
assertIsShellInjection("echo test\rrm -rf /", "rm");
}

@Test
void testFormFeedAsSeparator() {
// \f (form feed) as separator before dangerous command
assertIsShellInjection("ls\frm", "rm");
assertIsShellInjection("sleep\f5", "sleep\f5");
assertIsShellInjection("echo test\frm -rf /", "rm");
}

@Test
void testCommandExactlyMatchesUserInputWithSeparators() {
// When command equals userInput and contains \r or \f separators
assertIsShellInjection("ls\rrm", "ls\rrm");
assertIsShellInjection("ls\frm", "ls\frm");
assertIsShellInjection("echo\rcat /etc/passwd", "echo\rcat /etc/passwd");
assertIsShellInjection("echo\fcat /etc/passwd", "echo\fcat /etc/passwd");
}
}