News for hackers. Stuff that matters.
Re:CVE-2019-5418 – File Content Disclosure on Rails by aboutruby on Thursday March 21, 2019 @05:28PM (#19457527)
This was fixed in 6.0.0.beta3, 5.2.2.1, 5.1.6.2, 5.0.7.2, 4.2.11.1 one week ago.

https://weblog.rubyonrails.org/2019/3/13/Rails-4-2-5-1-5-1-6...

The two HN posts didn't get many upvotes though: https://hn.algolia.com/?query=https:%2F%2Fweblog.rubyonrails...

Admittedly there is probably a lot of applications out there running outdated versions.

edit: Kind of surprising this gets upvoted while we rarely see things from exploit-db / fulldisclosure

Re:CVE-2019-5418 – File Content Disclosure on Rails by anitil on Thursday March 21, 2019 @06:33PM (#19458020)
I'm a bit confused here, perhaps because I don't really understand Rails (possibly also the HTML spec).

I was under the impression the 'Accept:' header is a list of media types, so why would that be making filesystem calls? Or does Rails implicitly organize assets in a filesystem structure (something like ~/assets/audio or ~/assets/text)?

Re:CVE-2019-5418 – File Content Disclosure on Rails by archgoon on Thursday March 21, 2019 @06:45PM (#19458107)
The technical analysis (from the article), complete with a step by step trace walkthrough, is here:

https://chybeta.github.io/2019/03/16/Analysis-for%E3%80%90CV...

Also, if interested, direct link to patch fix:

https://github.com/rails/rails/commit/f4c70c2222180b8d9d924f...

Re:CVE-2019-5418 – File Content Disclosure on Rails by anitil on Thursday March 21, 2019 @07:31PM (#19458373)
Thanks for that, I was missing the step that assets are named $filename.$mime-type.erb in Rails. I was missing the high-level view
Re:CVE-2019-5418 – File Content Disclosure on Rails by tptacek on Thursday March 21, 2019 @06:35PM (#19458032)
Because the media types are parsed and used to select layout templates (layout.html.erb vs layout.xml.erb, etc).
Re:CVE-2019-5418 – File Content Disclosure on Rails by Something1234 on Thursday March 21, 2019 @06:45PM (#19458101)
So why wouldn't we just have a mapping between mime-types and extensions for look ups? Why bother examining the accept header beyond splitting and searching within the list? Like in such a way that we're opening arbitrary files with it?
Re:CVE-2019-5418 – File Content Disclosure on Rails by tptacek on Thursday March 21, 2019 @06:48PM (#19458125)
That's essentially what the patch does; the "symbol" call only resolves for known-good mime types.
Re:CVE-2019-5418 – File Content Disclosure on Rails by Something1234 on Thursday March 21, 2019 @06:56PM (#19458188)
Where would this code be in the rails code base? I usually don't touch ruby. I'm mildly curious what was there originally.
Re:CVE-2019-5418 – File Content Disclosure on Rails by tptacek on Thursday March 21, 2019 @06:59PM (#19458211)
In the template resolver in ActionView. It's spread over multiple files and a bit hard to follow, which no doubt contributed to the problem.
Re:CVE-2019-5418 – File Content Disclosure on Rails by lostapathy on Thursday March 21, 2019 @09:47PM (#19459010)
Unfortunately a lot of rails internals are like this :(.
Re:CVE-2019-5418 – File Content Disclosure on Rails by anitil on Thursday March 21, 2019 @06:42PM (#19458082)
Aaaah Thankyou!
Re:CVE-2019-5418 – File Content Disclosure on Rails by xtagon on Friday March 22, 2019 @02:24AM (#19460048)
So it's a problem in ActionView, and fixed in 5.1.6.2...then why does the changelog for ActionView for 5.1.6.2 say "No changes"?

https://github.com/rails/rails/blob/5-1-stable/actionview/CH...

Re:CVE-2019-5418 – File Content Disclosure on Rails by aboutruby on Friday March 22, 2019 @06:48AM (#19461222)
It's actually in ActionPack / Railties but I've raised the issue:

https://github.com/rails/rails/issues/35702

Re:CVE-2019-5418 – File Content Disclosure on Rails by xtagon on Friday March 22, 2019 @12:22PM (#19464071)
Great, thank you! Do most people just follow the blog instead of checking the changelog?
Re:CVE-2019-5418 – File Content Disclosure on Rails by aboutruby on Friday March 22, 2019 @03:53PM (#19466256)
It's kind of all other the place but there is: blog, twitter, mailling list, github, brakeman, and all the little rails communities informing each others.
Re:CVE-2019-5418 – File Content Disclosure on Rails by tptacek on Thursday March 21, 2019 @06:34PM (#19458027)
This is a really bad bug. Arbitrary file read on Rails applications can be pretty close to RCE. Worse still, it's present in all the mainstream versions of Rails, so it'll be lurking in commercial Rails applications for years to come. It's pretty amazing that the bug lasted as long as it did.
Re:CVE-2019-5418 – File Content Disclosure on Rails by aboutruby on Thursday March 21, 2019 @07:49PM (#19458466)
Good call, I went through the top results on Google and edited the answers/posted a comment to signal this vulnerability.

Also as others pointed out, this is a pretty rare use of `render` (but any application large enough might have it).

Re:CVE-2019-5418 – File Content Disclosure on Rails by msbarnett on Thursday March 21, 2019 @06:53PM (#19458160)
Notably, though, this only impacts calls which use the `file:` option on render calls, which in my experience is a relatively little-used feature. Not sure how many commercial Rails app this actually impacts in practice.
Re:CVE-2019-5418 – File Content Disclosure on Rails by tptacek on Thursday March 21, 2019 @07:02PM (#19458230)
I'm not sure why people think this feature is so rare. It's like the Stack Overflow answer for "how do I render a static 404 page that doesn't go through Rails layout templating".

You have to do something wrong to have the bug --- render a file without specifying the format --- but you have to do something extra to avoid that mistake, and the feature works just fine if you don't, so I'm not surprised that we've found it in real applications.

Re:CVE-2019-5418 – File Content Disclosure on Rails by tibbon on Thursday March 21, 2019 @07:08PM (#19458271)
Were I evil, I'd be looking at anyone who has upvoted or commented on such SO posts, and then looking at what companies they work for, and trying to run attacks against every site/repo/app they are linked to to see if they use this technique.

Or just, you know, looking in Github for anyone doing this and open sourcing their site.

Re:CVE-2019-5418 – File Content Disclosure on Rails by mbell on Thursday March 21, 2019 @06:54PM (#19458167)
It requires a specific usage of `render` that is extremely rare. I've never seen it in a real application.
Re:CVE-2019-5418 – File Content Disclosure on Rails by tptacek on Thursday March 21, 2019 @06:57PM (#19458198)
All it requires is "render :file" without the optional format argument. We found it immediately in applications, and other people on our Slack found it in theirs as well (though not necessarily exploitable, situationally).
Re:CVE-2019-5418 – File Content Disclosure on Rails by mbell on Thursday March 21, 2019 @07:56PM (#19458502)
I'm aware of the trigger, `render file:` is, in my experience, extremely rare. I can't recall ever wanting to render a template file located outside the application directory.
Re:CVE-2019-5418 – File Content Disclosure on Rails by MaxGabriel on Thursday March 21, 2019 @07:09PM (#19458278)
Does the code fixing this feel a little too innocuous to other people? Reading the code it seems really unlikely I'd see this and realize that deleting it would create a severe security vulnerability:

    v = v.select do |format|
      format.symbol || format.ref == "*/*"
    end
https://github.com/rails/rails/blob/efb706daad0e2e1039c6abb4...
Re:CVE-2019-5418 – File Content Disclosure on Rails by tenderlove on Thursday March 21, 2019 @07:39PM (#19458418)
Ya, that's one reason I rewrite the commit message to add the CVE. Hopefully people will view the blame before changing.
Re:CVE-2019-5418 – File Content Disclosure on Rails by decasia on Thursday March 21, 2019 @07:56PM (#19458507)
I'm curious — is it not normal to add in-line explanatory comments in the Rails codebase?

I'm thinking if I were writing this code in an application, and it looked this cryptic, I might at least add a comment noting what it was for. Not that people shouldn't look in git. But inline is easier to notice, no?

Re:CVE-2019-5418 – File Content Disclosure on Rails by riffraff on Friday March 22, 2019 @01:50AM (#19459926)
Don't we have tests for this?
Re:CVE-2019-5418 – File Content Disclosure on Rails by progval on Friday March 22, 2019 @04:19AM (#19460452)
Re:CVE-2019-5418 – File Content Disclosure on Rails by tptacek on Thursday March 21, 2019 @07:21PM (#19458330)
Why would you randomly remove code from ActionView? It's some of the least user-serviceable code in Rails.
Re:CVE-2019-5418 – File Content Disclosure on Rails by tenderlove on Thursday March 21, 2019 @07:41PM (#19458428)
We're working to improve it. It's actually why jhawthorn found this issue.
Re:CVE-2019-5418 – File Content Disclosure on Rails by amingilani on Thursday March 21, 2019 @10:57PM (#19459285)
I put on my white hat, found a site that is probably still vulnerable with a bug bounty program, tried to run a modified query, only this time pointed at `/dev/random` and....

"Sorry, you have been blocked"

"This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data."

Apparently, Cloudflare's great at detecting threats. Bummer.

Re:CVE-2019-5418 – File Content Disclosure on Rails by aboutruby on Thursday March 21, 2019 @11:19PM (#19459367)
You could get the origin IP and bypass Cloudflare, there are many many ways to do this.
Re:CVE-2019-5418 – File Content Disclosure on Rails by amingilani on Thursday March 21, 2019 @11:36PM (#19459438)
Thank you for the idea! But in general, it'd nice to be less mysterious when helping people ;) but you're right, there really are many ways to uncover the origin IP[0]

[0]: https://www.secjuice.com/finding-real-ips-of-origin-servers-...

Re:CVE-2019-5418 – File Content Disclosure on Rails by hombre_fatal on Friday March 22, 2019 @08:27AM (#19461854)
They all depend on mistakes. Common ones, sure.
Re:CVE-2019-5418 – File Content Disclosure on Rails by dwheeler on Thursday March 21, 2019 @09:20PM (#19458904)
My thanks to the original reporter of the vulnerability, and to the Rails folks for fixing it.

I strongly recommend using at least one tool to help you know when a publicly known vulnerability is reported in a component you use. Then you can update, run your automated test, and immediately ship. Modern systems are typically mostly reused code. Being unprepared for vulnerabilities in them is a little crazy, because you know that such things will happen.

Re:CVE-2019-5418 – File Content Disclosure on Rails by jonahx on Friday March 22, 2019 @08:13AM (#19461755)
I was looking forward to reading the technical breakdown here:

https://chybeta.github.io/2019/03/16/Analysis-for%E3%80%90CV...

But I could not without my fans blasting and overheating my laptop. The page is using js to continuously render a moving background.

Re:CVE-2019-5418 – File Content Disclosure on Rails by richardwhiuk on Friday March 22, 2019 @08:51AM (#19462033)
The background on https://chybeta.github.io/2019/03/16/Analysis-for%E3%80%90CV... is extremely distracting (especially on mobile).

Having things wandering across the screen draws the eye away from the content you are trying to read.