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

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

Comments

Projects
None yet
2 participants
@mo-nathan
Copy link

mo-nathan commented Mar 3, 2019

Background

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

Link to Rails application code: https://github.com/mo-nathan/brakeman-bug (isolated cases that demonstrates issue)

False Positive

Full warning from Brakeman: Possible command injection

Relevant code:

  def a_cmd
    a = A.new
    result, status = Open3.capture2e("ls",
                                     Shellwords.escape(a.z))
  end

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.

@presidentbeef

This comment has been minimized.

Copy link
Owner

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.

Thanks!

@mo-nathan

This comment has been minimized.

Copy link
Author

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.

@presidentbeef

This comment has been minimized.

Copy link
Owner

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.