Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command injection false positive when code is in different files #1323

mo-nathan opened this Issue Mar 3, 2019 · 3 comments


None yet
2 participants
Copy link

mo-nathan commented Mar 3, 2019


Brakeman version: 4.4.0
Rails version: 5.2.2
Ruby version: 2.6.1 (or 2.4.1)

Link to Rails application code: (isolated cases that demonstrates issue)

False Positive

Full warning from Brakeman: Possible command injection

Relevant code:

  def a_cmd
    a =
    result, status = Open3.capture2e("ls",

Why might this be a false positive?
As I understand it, the use of Shellwords.escape should resolve the issue regardless of where the function z is defined. However, it only does when it is defined in the same file. When it is coming from another file the false positive happens.


This comment has been minimized.

Copy link

presidentbeef commented Mar 3, 2019

Hi Nathan,

Thank you for providing a nice full example to reproduce the problem.

What's happening is that A is being considered a model (because its in app/models) and for some reason that is causing a difference. I'll take a look.



This comment has been minimized.

Copy link

mo-nathan commented Mar 4, 2019

Thanks for looking into it and for such a great tool! Is there a reason why actually being a model should make a difference? In the real case the 'A' object is a model.


This comment has been minimized.

Copy link

presidentbeef commented Mar 6, 2019

The only reason it makes a difference is because the code for the command injection check is a bit messy and so shell escaping isn't handling properly everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.