Notinlist
Notinlist

Reputation: 16640

Calling shell command from ruby with proper argument escaping

I want to do the following securely

system "echo '#{params[:message]}' > /dev/log"

What is the proper way for escaping arguments when calling a native command?

(Example evil input: '; rm -Rf *; echo 'I won.)

Upvotes: 10

Views: 1954

Answers (1)

Rob Di Marco
Rob Di Marco

Reputation: 44952

If you do

system "echo", params[:message]

Then the second argument, will be sent as an argument, it will not be executed.

Upvotes: 16

Related Questions