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

Ruby: Add additional sinks to the rb/kernel-open query #11366

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

p-
Copy link
Contributor

@p- p- commented Nov 22, 2022

Hi!

This PR adds following sinks to the rb/kernel-open query:

  • IO.write
  • IO.binread
  • IO.binwrite
  • IO.foreach
  • IO.readlines
  • URI.open

These sinks all belong to the same family as the already implemented Kernel.open and IO.read. (Command injection with a starting pipe (|).

In addition to that I added a sanitizer I encountered in the wild: File.join sanitizes an untrusted user input if the tainted data is not passed in as the first argument (command execution is only possible if the first sign character passed to those sinks is a pipe (|).

@p- p- requested a review from a team as a code owner Nov 22, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 22, 2022

QHelp previews:

@p- p- changed the title Add additional sinks to the rb/kernel-open query Ruby: Add additional sinks to the rb/kernel-open query Nov 22, 2022
Copy link
Contributor

@erik-krogh erik-krogh left a comment

I had my doubt abouts URI.open, but yes that's also vulnerable 🤦

irb(main):001:0> require "open-uri"
=> true
irb(main):002:0> URI
=> URI
irb(main):003:0> URI.open "https://google.com"
=> #<File:/var/folders/qp/rmn5qy357vb70d2sgqv1tt_c0000gn/T/open-uri20221122-8505-omzyyf>
irb(main):004:0> URI.open "| touch pwned"
=> #<IO:fd 11>

LGTM 👍

Copy link
Contributor

@erik-krogh erik-krogh left a comment

I'm sorry, I'm going to need changes.
Can you see the evaluation?

There are bunch of results in opal/opal where the alert is on a safe call to e.g. File.write, but according to the alert message the call is to IO.write, so you'll have to do something about that.
You can see in KernelOpenQuery.qll that I've already done that for IO.read.

I think that happens due to some aliasing 🤷, but I don't know precisely how.
(You can ask the more senior CodeQL Ruby devs on Slack about that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants