Repository navigation
fix: strip control characters from file names in posix builtins (3.x backport) - #2240
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
gnodet
left a comment
There was a problem hiding this comment.
Security fix is correctly scoped and well-implemented. One gap: the tail command's multi-file header is patched but has no regression test.
What the fix does: stripControlChars() uses Character.isISOControl() which covers C0 (0x00–0x1F) and C1 (0x7F–0x9F) control characters — correct set for terminal injection defense. All 9 filesystem-derived name output sites in the 3.x PosixCommands are covered: wc (1), head (1), tail (1), grep (3), ls display+symlink (2), ls multi-dir header (1).
The gap: The tail multi-file header (==> arg <==) is patched (diff hunk at line 1190), but there is no corresponding tailStripsControlCharsInFileHeader regression test. The other five commands each have at least one test; tail is missing.
Suggested addition to PosixCommandsControlCharTest:
@Test
void tailStripsControlCharsInFileHeader() throws Exception {
Path evil = tempDir.resolve(EVIL);
Files.write(evil, "hello\n".getBytes(StandardCharsets.UTF_8));
Path plain = tempDir.resolve("plain.txt");
Files.write(plain, "world\n".getBytes(StandardCharsets.UTF_8));
// More than one source makes tail emit the "==> name <==" headers.
PosixCommands.tail(context, new String[] {"tail", evil.toString(), plain.toString()});
assertNoControlBytes(output());
}This review was generated by an AI agent, Hermès, on behalf of @gnodet.
|
Added |
|



Backport of 92cb769 from master to jline-3.x.
Wraps filesystem-derived names with
stripControlChars()before writing to the terminal, preventing escape injection via crafted filenames. An entry such asreport<ESC>]0;pwned<BEL>.txtwould otherwise drive the terminal (set window title, write clipboard via OSC 52, etc.).Affected commands:
ls,head,tail,wc,grep.Manually adapted (not cherry-picked) because the 3.x posix builtins differ significantly from master — the
wc,head,tail, andgrepimplementations were refactored on master. Includes the full test suite from master.