Skip to content

[fix] escape shell metachars in chdir: to prevent injection#9464

Open
kares wants to merge 1 commit into
jruby:jruby-9.4from
kares:fix-chdir-escape-94
Open

[fix] escape shell metachars in chdir: to prevent injection#9464
kares wants to merge 1 commit into
jruby:jruby-9.4from
kares:fix-chdir-escape-94

Conversation

@kares
Copy link
Copy Markdown
Member

@kares kares commented May 27, 2026

PopenExecutor constructs a "cd '

'; ..." for the chdir: option in spawn/system/IO.popen; the directory path was embedded in single quotes without escaping, allowing single-quote breakout and arbitrary command injection:

system('echo hello', chdir: "x'; touch /tmp/pwned; echo '")

MRI uses the POSIX chdir syscall directly and is not affected

(cherry-pick with conflict resolution from #9451)

PopenExecutor constructs a "cd '<dir>'; ..." for the chdir: option in
spawn/system/IO.popen; the directory path was embedded in single quotes
without escaping, allowing single-quote breakout and arbitrary command
injection:

  system('echo hello', chdir: "x'; touch /tmp/pwned; echo '")

MRI uses the POSIX chdir syscall directly and is not affected
@kares kares added this to the JRuby 9.4.15.0 milestone May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant