46 ms·
SQL Injection Vulnerability in Ruby on Rails; affects all versions
- jtchang 14y agoI am mostly a Django programmer so excuse my ignorance of rails. How does this keep happening? In Django you would do: Post.objects.get(pk=request.GET['id']) There really is no way to do SQL injection this way. This line in rails looks almost exactly like how you would do it in Django: Post.find_by_id(params[:id]) Also this seems really serious. It's not like a edge case where you need to grab a post by id. This is probably a very common use case of that method find_by_id.
- codewright 14y agoBtw, this applies for my (Python) Flask apps using MongoDB ORMs. They escape the inputs. What the hell is going on with ActiveRecord?
- charliesome 14y agoThe main issue stems from Ruby using the last positional parameter to pass a hash representing keyword arguments. This means if there's only one parameter, and someone can sneak a Hash in there where you weren't expecting it (params parsing, request body parsing, etc) then they can end up passing dodgy 'keyword arguments' into your method call.
- elbear 14y agoIn Python, the parameter escaping is done at the level of the database driver not the ORM. Isn't this the case with Ruby? Of course, you could use the driver incorrectly to risk SQL injection, but that is a very obvious mistake that no experienced developer would make.
- riffraff 14y agothe ORM escapes the parameter but it lets you specify bits of SQL by hand (think "select foo, myfunc(bar) as BAZ, joineds.quux as quux"). In theory when you do that you have already given up on letting the framework handle it for you, and you must take care of not feeding raw user input as the select code, for example. The issue here is that the option to do this is exposed in a functionality where people do not expect it (dynamic finders) and thus people may be passing risky input there.
- elbear 14y agoWell, the Django ORM also allows you to write SQL by hand and if you make a mistake you can fall pray to SQL injection, so I'm assuming that there's something different about this exploit. From what I understand the current issue appears because the person who implemented the faulty method uses SQL directly and doesn't pass the parameters separately. In Python, you would do something like this: execute('select name, age from employees where id=?', (params['id'],)) This passes the id as the second argument to the execute function. If you do this, on the other hand, you open yourself to SQL injection, because %s is replaced with params[id] and no escaping is done: execute('select name, age from employees where id=%s' % params['id'])
- riffraff 14y agothe thing that is different is that the raw sql facilities are made explicitly available not through the common methods that expect them, but through something else. The orm supports building the sql piecemeal, e.g find(select: "name, foo(bar) as baz", conditions: 'x=y', limit: 3) this is a small step above a raw execute, and obviously ugly and low level. Also a somewhat obsolete practice, since for a few years you could write it as a composition of calls select("name, foo(bar) as baz"). where('x=y'). limit(3) Anyway the functionality is there to compose SQL via bits using an hash of parameters, moving on. Now remember that ruby <2.0 does not support keyword arguments, so the common practice is to use one normal argument with an hash value wich contains the keyword args. Rails has this (antipattern imo) of accepting arguments in a dozen way for some methods e.g. find(1) find(:first) find([1]) find(1,limit: 1) let us not argue whether this is good, it's there. And AR has dynamically generated finders (which Django does not have AFAIR). One would expect the dynamically generated finder to be doing def find_by_foo arg where(foo, arg).limit(1) end but in reality it does def find_by_foo *args many_options = args.extract_options! opts = combine_with_foo_handling(many_options) find(opts) end and here you get the problem that you may be unknowingly passing an hash object wich builds sql piecemeal. Notice that, as others already pointed out, usually as a user you shouldn't be able to create custom objects of the kind that exploits this issue (an hash with symbols as keys) unless your have other vulnerabilities already.
- codewright 14y agoYou can pass a hash (dictionary) to represent kwargs in Python. This seems like bad engineering fundamentals in the design of ActiveRecord for it to be perpetually subject to this sort of thing.
- charliesome 14y ago> You can pass a hash (dictionary) to represent kwargs in Python. Eh, sure but you need to explicitly pass the dict as a kwarg with a double-asterisk, or else it's just a normal positional parameter. In Ruby prior to 2.0, there is no formal concept of kwargs, so there is no distinction between passing a Hash as the last positional parameter and passing kwargs. This is the root problem, and I look forward to it going away when everyone moves to 2.0.
- andrewcooke 14y agoi don't know ruby, so forgive the dumb question, but doesn't that mean that a single syntax has two different semantics? what if you want to pass a hash to a method as the last parameter? what decides whether it is treated as a hash or keywords?
- charliesome 14y agoThere are no 'keyword arguments', however Ruby does provide syntax sugar for options hashes. For example, this: my_method(1, 2, three: 3, four: 4) Is the same as this: my_method(1, 2, { three: 3, four: 4 }) Which can be picked up by the method like this: def my_method(one, two, opts) three = opts[:three] four = opts[:four] puts one, two, three, four end
- aaronblohowiak 14y agoThis is not a rubyism, it is a Railsism, they wrote a method called extract_options! and use it everywhere to get this kind of behavior. This is not how vanilla ruby works.
- charliesome 14y agoIf it wasn't a rubyism, why is there syntax sugar for passing a hash as the last positional parameter?
- aaronblohowiak 14y agothe sugar exists for passing it, but not for receiving it, and to get around this, rails uses splat (varargs) and extract_options! to get the last positional parameter behavior for vararg methods. vanilla ruby: def find_by_name(name, options = {}) ... end rails: def find_by_name(*args) opts = args.extract_options! name = args.shift ... end (note, this is not how the dynamic finders actually work, i just wanted to illustrate the difference in the calling and definition.) So, ruby doesn't include support for varargs with last positional parameter for options, rails builds that in. The fact that it is variable arity is very important -- in fact, that is the root of the present issue. The patches now check the number of arguments.
- danso 14y agoRails does escape inputs with its finder and scope methods. I think the problem is that the "magic" in these methods allow for some edge cases to be parsed in unexpected ways...for example, when params[:id] contains a nested hash instead of a string or integer.
- sandstrom 14y agoThis pull request is probably what caused the alarm: https://github.com/binarylogic/authlogic/pull/341 https://github.com/binarylogic/authlogic/pull/341 With 3395 stars it seems to be a quite popular.
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]
- jtchang 14y agoI'm sorry but this is braindead. I'm sure there are valid use cases but optimize for the most common one: find_by_id accepts a single argument, the ID of the object you want to find. That is why Python has kwargs. Those two stars stand out like a sore thumb and when you are passing positional arguments in the form of a hash it is pretty apparent.
- steveklabnik 14y agoRuby does not yet have kwargs, but the upcoming Ruby 2.0 has a form of them.
- deleted 14y ago[deleted]
- mattmcknight 14y agothat would be called .find(id) - accepts a single argument of an id. This is the canonical way to retrieve by id. find_by_id, find_by_name, etc. aren't really methods, they trigger calls to method_missing which interprets the code to generate SQL. It's a "neat" feature, but one which I've only used once or twice in 6 years of Rails development.
- numbsafari 14y agoYou are going to have problems with this whenever you are composing SQL statement with any type of user-provided data as part of the raw SQL string passed to the server. This generally happens in one of two says: 1) (most common) You have a SQL statement that takes a user-provided parameter and you compose your SQL statement as a string, including that parameter (eg., sql = "SELECT * FROM person where id = " + form.id, or similar). This is typically solved by using parametric, prepared statements. Basically, you prepare a SQL statement that contains "?" for the parameter values and then bind values to the statement. 2) (Common in ORM frameworks) A user provided string is used to compose some other (non-parameter) piece of the SQL statement, such as a column or table name. This is usually caused by laziness. Rather than combining the string provided by the user (form values, URL components, etc.) you should instead look up the string to use from some internal data source, such as a list of domain classes, etc., and use that instead. In that way, the data that is user provided is kept entirely separate from data that will be executed. You'll hear a lot of people talk about "why isn't this being escaped". And, frankly, it's a good question. But the real question is "why are you trusting data that could come from anywhere on earth?". Don't take it for granted that only your users will be sending queries to your application. The code you write for Django (Post.objects.get(pk=request.GET['id']) is only secure from 1 and 2 if the framework is written in an appropriate manner to avoid trusting user provided data. The fact that this keeps happening on Rails is the #1 reason I haven't bothered to take the time to do anything real with it. I don't have the time to read the code for the framework and I don't trust that it's written with security in mind. ps. This type of problem applies to any kind of "data that is executable", be it strings passed to an "eval" function or strings passed to a web browser. SQL is just a giant eval() function.
- plaguuuuuu 14y ago>You are going to have problems with this whenever you are composing SQL statement with any type of user-provided data as part of the raw SQL string passed to the server. This is still, mathematically-speaking, a bug. The function is supposed to find a post by ID. If its implementation causes side effects or returns unexpected results for a certain subset of possible input data, then it doesn't conform to spec. This becomes a question of trust. Do you trust ActiveRecord/ORM of choice to be bug-free, or do you treat it as untrusted code and basically have to worry about the implementation of data persistence in your non-DB code even though that's what ORMs are supposed to abstract away? Why is that shit running around in your codebase anyway and not part of the ORM?
- Yahivin 14y agoThe standard way to find a post in Rails would be: Post.find(params[:id]) That method is unaffected. The methods that are affected by this are the dynamic finder methods `find_by_*` such as: Post.find_by_id(params[:id]) This would most commonly occur when looking up users by a token or some other piece of data other than the id. User.find_by_token(params[:token]) I'm not sure why they chose to use find_by_id in the example. This is a serious bug, but it's not as serious as one might be lead to believe if one thought it was the standard way to find objects in Rails.
- ultimoo 14y agoTrue, but :find_by_id is closer to :where in that it doesn't raise exceptions upon not finding a record. I've seen it being used in a few places, especially in front another scope, like `current_user.posts.find_by_id`.
- eclipxe 14y agoIf you have an invalid id coming in, wouldn't you generally want an Exception? What is the use case where the app would send an id that does not exist, but you would not want to fail?
- RegEx 14y agononexistent does not necessarily imply invalid. I don't use rails, so take my ignorance into account, but I'd hate to catch exceptions all the time instead of just checking for falsey values. Ex: "Enter your student ID" s = Student.find_by_id(params[:id]) if s # do stuff else # do other stuff end vs begin s = Student.find_by_id(params[:id]) # do stuff rescue # do other stuff end
- eclipxe 14y agoThis is a good example, however I would argue that it is bad design to have a record's ID used for user facing lookups. For other parameters, sure (find_by_name, etc) a false would be okay. Just a matter of taste really.
- zacksjoden 14y agoFor someone just learning RoR and having installed it via http://railsinstaller.org/ http://railsinstaller.org/, how should I upgrade?
- cheald 14y agoRun "bundle update rails" in your project's root directory (where your Gemfile is).
- bonzoesc 14y agoThis won't work if your Gemfile declares a version of Rails (Rails 3.2.9 did this). You have to update the Gemfile and then bundle update.
- danso 14y agoIt should be as easy as 'gem update rails' at your command line (Terminal window). If you're just learning and creating an app for your own edification, this is not really an issue that will affect you. That is, it doesn't affect how you construct the app, so if for some reason the gem update process doesn't work, you won't be hindered from using RoR.
- bonzoesc 14y agoThis won't work. The old version won't be purged, and it'll still be referenced in the Gemfile.
- bonzoesc 14y agoUpdate the version in your project's Gemfile, and run "bundle update rails".
- aerolite 14y agoFirst do a "gem uninstall rails", wait for that to finish, then do a "pip install Django" at the command line.
- danso 14y agoFWIW, this is the third time in seven months that Rails had to issue a patch related to how ActiveRecord handles method parameters. 3.2.6 (June 2012) https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/l4L0TEVAz1k https://groups.google.com/forum/?fromgroups=#!topic/rubyonra... 3.2.4 (May 2012) https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/dUaiOOGWL1k https://groups.google.com/forum/?fromgroups=#!topic/rubyonra...
- dmix 14y agoI've always found Rails to be easy to secure compared to most other frameworks. I think the defaults are all pretty secure. I'd prefer having constant security patches. It shows people are still constantly testing it for vulnerabilities.
- michaelfairley 14y agoThis affects all versions of Rails, not just 3.x. This is a really, really bad hole, and you should patch or upgrade ASAP.
- danso 14y agoThanks, fixed the headline. All versions are affected, only 3.1, 3.2 have official support
- thelarry 14y agoIm not a RoR developer, so forgive my ignorance. But how does this keep happening? I thought ActiveRecord is a mature product by now. I hear about these types of bugs happening with RoR pretty often, is the "magic" of ActiveRecord and hiding SQL from the developer really worth it? I wonder how many RoR developers even understand what SQL injection actually means.
- benlower 14y agoSo does the fact that "Rails is Omakase" (http://david.heinemeierhansson.com/2012/rails-is-omakase.html http://david.heinemeierhansson.com/2012/rails-is-omakase.htm...) mean that the chef tried to serve Fugu (http://en.wikipedia.org/wiki/Fugu http://en.wikipedia.org/wiki/Fugu) but cut it wrong?
- roc 14y agoNo, it just means that any chef serving Fugu can cut it wrong. So when someone offers to do something inherently dangerous on your behalf, you should be incredibly deliberate. There's no shortage of frameworks, platforms and libraries that have been bit (repeatedly) by SQL injection.
- chrismsnz 14y agoTo continue the metaphor, it seems that in their mission to make the meal taste better for the customer they neglected to clear the poison. Lets not pretend that Ruby/Rails doesn't make major architectural decisions in favour of ease of use for the user. e.g. if HTTP params weren't automatically marshalled into non-string data structures this bug wouldn't exist.
- xentronium 14y agoI think this is a correct analogy, but you have to take something else into consideration: there are no chefs that don't cut fugu wrong from time to time. We should cut fellow programmers some slack.
- benlower 14y agoxentronium: i agree on cutting slack. my comment was mostly meant to be fun and to only poke a bit :-)
- threedaymonk 14y ago"there are no chefs that don't cut fugu wrong from time to time" This doesn't seem to be the case: fugu preparation is licensed and regulated, and deaths are very rare indeed. I can't find exact numbers offhand, but according to a paper cited on Japanese Wikipedia, there were 315 fugu poisoning incidents in Japan in the 10 years from 1996 to 2005. Of those, 31 were fatal, and of those, the majority were due to preparation by unqualified individuals (presumably those who had caught fugu themselves). Given the quantity of fugu consumed nationwide, it seems reasonable to say that, in fact, most chefs never cut fugu wrong - or at least that most chefs never serve wrongly cut fugu. https://ja.wikipedia.org/wiki/%E3%83%95%E3%82%B0#.E3.83.95.E3.82.B0.E3.81.AB.E3.82.88.E3.82.8B.E9.A3.9F.E4.B8.AD.E6.AF.92 https://ja.wikipedia.org/wiki/%E3%83%95%E3%82%B0#.E3.83.95.E...
- clamstar 14y agoYou need the contents of secret_token.rb to exploit this (via a forged session). This makes it much more of a danger to OSS projects than to those in the closed source space. It's not just a SQL Injection vulnerability. With that secret token, you can set any session value you like.
- jroes 14y agoThis is how I understand the issue as well. Many people in this thread are commenting about massive dangers, but I don't think anyone has bothered to actually read the references in the CVE. Also, even open source projects typically ensure or recommend that the secret token be regenerated when using in production environments.
- nbpoole 14y agoI think the CVE description is inaccurate in this case. Check out the Rails security email list description, which never mentions sessions. https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/DCNTNp_qjFM https://groups.google.com/forum/?fromgroups=#!topic/rubyonra...
- rst 14y agoDifferent vuln; this one has nothing to do with session cookies.
- jroes 14y agotenderlove mentions it has been assigned CVE-2012-5664. This is that CVE: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-5664 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-5664 It references two articles that require session secrets.
- tenderlove 14y agoYes, the article does mention session secrets. However, this exploit does not require session secrets. The person who wrote the blog post wrote about essentially two vulnerabilities: session forging and SQL injection.
- webjprgm 14y agoThis isn't a problem if you check the type of data you get from a user before you use it. You should be doing that anyway. The article says a work-around is to use .to_s or .to_i on user input. My standard practice is to cast to int for all IDs I get externally (in PHP too). Some projects I work on go so far as to validate type and data ranges of every argument passed in. Those applications would therefore not be vulnerable even though Rails itself is.
- colinsidoti 14y ago"You should be doing that anyway." A huge selling point of Rails, other web frameworks, and ORMs in general, is that you don't have to be doing these checks. You can push the query through without concern of SQL injection, and handle the failure case there. This is convenient because you often have to handle that failure case anyway. Rails' own "Getting Started" guide uses this technique because it's assumed to be secure: http://guides.rubyonrails.org/getting_started.html#showing-an-individual-post http://guides.rubyonrails.org/getting_started.html#showing-a... We know you can "break" the application by tampering with IDs, but you shouldn't be able to pose a security threat. Validating type and data ranges is common with things like dropdowns, where you need to ensure an actual option was selected. This is a very common security flaw, and it's definitely good practice to be checking (especially when it leads to adding/updating database rows).
- Yahivin 14y agoThe getting started guide does not use that technique. It uses `Post.find(parms[:id])` The vulnerability is in `Post.find_by_id(params[:id])` and any other `find_by_*` dynamic finders.
- oomkiller 14y agoIt seems like this is being conflated with the session token issue? How do you submit params with symbolized keys? Hashes are easy enough, but it doesn't work with hashes that have strings as keys, only symbols. EDIT: Just to be clear, tenderlove (Ruby/Rails committer) confirms that you do not need to edit the session to exploit this (http://news.ycombinator.com/item?id=4999767 http://news.ycombinator.com/item?id=4999767). It's still unclear how it is possible otherwise though, I assume he's being purposefully vague.
- latortuga 14y agoRails param parsing automatically converts all param keys to symbols.
- oomkiller 14y agoIf I submit a form where the param is "login[select]=* from users limit 1 --" when I inspect params[:login] I get {"select"=>"* from users limit 1 --"}. Is there a different way of submitting things that converts it to symbols? params[:login] works due to it being a HashWithIndifferentAccess
- mnarayan01 14y agoYea I'm not seeing it either. Maybe if someone explicitly called `params.symbolize_keys!`? If that's the only time its vulnerable it seems like less of a big deal, though still obviously something that should be patched ASAP. edit: Above sandstrom posts the link to https://github.com/binarylogic/authlogic/pull/341 https://github.com/binarylogic/authlogic/pull/341 so I guess maybe you can use the session to do this, though you would need access to the secret_token.
- charliesome 14y agoThe param keys remain strings underneath.
- mnarayan01 14y agoJust to expand on what others have already said...Rails converts params to http://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html http://api.rubyonrails.org/classes/ActiveSupport/HashWithInd... which means that `params[:foo]` and `params["foo"]` will both return the same thing. The function [`assert_valid_keys`](http://api.rubyonrails.org/classes/Hash.html#method-i-assert_valid_keys http://api.rubyonrails.org/classes/Hash.html#method-i-assert...), which is called in [`apply_finder_options`](http://api.rubyonrails.org/classes/ActiveRecord/SpawnMethods.html#method-i-apply_finder_options http://api.rubyonrails.org/classes/ActiveRecord/SpawnMethods...) does not, however, treat symbol and string keys as the same, even if given a `HashWithIndifferentAccess`.
- eranation 14y agoWould appreciate if someone could explain the issue in a little more detail for non RoR developers
- xentronium 14y agoAssuming you have no ruby knowledge: ActiveRecord (rails' default ORM) has a feature called "dynamic finders". When you call a method like `Forum.find_by_url('news.ycombinator.org')` it gets a first forum with such url. This is a sugar over `Forum.where(:url => 'news.ycombinator.org').first`. Normally, you use it like that `Forum.find_by_url(params[:url])` where `params` is a hash of parameters (that is auto-generated from http get/post params). What happens if instead of "normal" value like "news.ycombinator.org" you pass a hash? 1.9.3p327 :018 > Forum.find_by_id({:select => 'id FROM forums --'}) Forum Load (0.5ms) SELECT id FROM forums -- FROM `forums` WHERE `forums`.`id` IS NULL LIMIT 1 Uh-oh. However, not everything is lost. Rails params are converted to a special hash class. It's called HashWithIndifferentAccess, because you can access its values by string keys and symbol keys likewise. So that h = {:a => 1, "b" => 2}.with_indifferent_access h["a"] # => 1 h[:a] # => 1 h["b"] # => 2 h[:b] # => 2 What happens if we pass user-generated params? It seems like not much: 1.9.3p327 :024 > Forum.find_by_id({:select => 'id FROM forums --'}.with_indifferent_access) ArgumentError: Unknown key: select So I guess they are erring on a safe side here.
- MichaelGG 14y agoWhat's the great benefit of these methods? Why not just do find_by("url", x)? I just don't understand the desire to move string parameters into member names.
- xentronium 14y agoThere is slight benefit in readability for cases like find_by_name_and_role("Jack", "admin"), but other than that, no benefit whatsoever. In Rails 4.0, most dynamic finders are deprecated and removed from the source into a separate gem.
- 14y ago
- FuzzyDunlop 14y agoIt seems easy to blame the magic finders for this (because they seem magic), or ActiveRecord alone, but really the problem is that 'secure by default' can trick you into thinking the framework will do it all for you. It probably will most, if not all, of the time for you. But the complexity of such things understandably means there will be obscure vulnerabilities that are hard to track down. Sanitising -- and even validating -- your params at the controller level is a nice way to stop some of these problems before they reach your models.
- hayksaakian 14y agoDoes something similar affect mongodb or am I OK?
- danso 14y agoThis is an ActiveRecord issue...MongoDB uses its own ORM (Mongoid/Mongomapper)
- hayksaakian 14y agoThat's what I was referring to. Do mongomapper and mongoid have this problem?
- amorphid 14y agoOn the bright side you need not fear this bug for your apps using MongoDB. Mongoid and MongoMapper do not use SQL, so there should be no SQL injection problems using those two options.
- hayksaakian 14y agoI'm aware they don't use SQL, but someone on HN once told me there was some kind of JavaScript injection you could do in theory. Was wondering how mongoid would handle this technique.
- nbpoole 14y agoExample: http://www.idontplaydarts.com/2010/07/mongodb-is-vulnerable-to-sql-injection-in-php-at-least/ http://www.idontplaydarts.com/2010/07/mongodb-is-vulnerable-...
- ufo 14y agoThe root cause of the bug here is not sql injection. Its that one of the query functions is overloaded to do different things depending on what datatype you pass to it and that the user can manipulate that datatype (for example, by passing an object in a part of a JSON message that would usully conatin a string). Of course, this is only really serious if one of the overloads gices too much power (in this vulnerability's case it would let you run an arbitrary query)
- simon_kun 14y agoDoes anyone know of a patched version of rails 2.3 series on rubygems?
- rob-anderson 14y agoNo but you could do what we did: http://robanderson123.wordpress.com/2013/01/05/applying-backported-security-patches-to-rails-2-3/ http://robanderson123.wordpress.com/2013/01/05/applying-back...
- NelsonMuntz 14y agoHaw Haw!
- NoPiece 14y agoSo it only the only the dynamic finders (find_by_) that have the vulnerability, not Model.find(params[:id])?
- colinyoung 14y agoYes, it's the dynamic matchers only.
- alberth 14y agoThe irony of this security vulnerability being announced by 37signals on Google Groups on the same day they release a new product called Basecamp Breeze [1] which is a direct competitor to Google Groups (and they compare it to Google Groups) ... hasn't gone unnoticed. [1] http://basecamp.com/breeze/compare#google http://basecamp.com/breeze/compare#google
- dholowiski 14y agoOh. I always figured it was bad coding, but I normally use the workaround anyway. Post.find_by_id(params[:id].to_s) Regardless, I think I have some patching to do tonight.
- mkilling 14y agoDoes this affect friendly_id? edit: friendly_id does not use the dynamic find_by_x methods. I guess it should be safe.
- bonzoesc 14y agoThis particular exploit doesn't either.
- clickonchris 14y agoHaving just finished upgrading my production rails because of today's news I thought I would pass along a how-to for rails 3.x update your Gemfile and set the version you want. In my case: gem 'rails', '3.2.10' locally, run 'bundle update rails' which will update your Gemfile.lock check-in and deploy your code. If you are using capistranso, the default 'deploy' task should handle everything for you. Otherwise, run 'bundle update rails' on your production server.
- mikec3k 14y agoJust wait until you find someone named Robert'); DROP TABLE STUDENTS; --
- venus 14y agoThe overreaction on this page is ridiculous. Has anyone actually read the steps required to exploit this vulnerability? You do know that to be able to exploit it you have to know the application's secret key, so you can create your own malicious encrypted session cookie that includes hashes instead of strings for the auth token lookup? You do know that if someone has your app's secret key they can just write whatever they want into the session cookie, instantly compromising a large number of apps anyway? That's the whole point of the secret key! This is an obscure issue which can be used to get around one layer of defense in rails security. It could never get around all of them. It requires intimate in-depth knowledge of the app to even attempt the exploit. Sure, it's a bug, and it's not to be taken lightly, but the howls of derision here are totally out of proportion.
- chrismsnz 14y agoPlease provide a source for your claims. From looking at it, it seems that ANY HTTP parameter (e.g. POST or GET - which are completely user-controlled) can be manipulated if you know how it's going to be used in the code, e.g. an obvious object ID. EDIT: tenderlove sets it straight below
- venus 14y agoSure. Here is the exploit: https://github.com/binarylogic/authlogic/pull/341 https://github.com/binarylogic/authlogic/pull/341
- chrismsnz 14y agoThat's a bug/exploit in Authlogic, a third party library for rails, not rails. However, that bug/exploit is based on the rails vuln and was patched in authlogic exactly how the Rails report instructed people to work around it (casting the parameter to a string). Reading the actual report linked in the OP you'll see that generic and boilerplate code (e.g. the extremely common pattern: "Post.find_by_id(params[:id])") is going to be vulnerable to this bug.
- 14y ago
- martinced 14y agoOne could lament that the real issue is the (maybe not so) accidental complexity (and hidden deep down complexity lies insecurity) that results when you're using utter non-sense like an ORM. The very concept of an ORM is broken. I know most devs don't know SQL well enough to do more code directly from SQL and I know most devs don't know anything else than SQL... But it's a bit sad to see all these "frameworks" tailored to the masses. dev: "I want objects. I don't really understand set theory but I still want SQL because it's all I know." chef: OK, here's a framework doing nearly everything from you. Seriously guys. Mixing orthogonal concepts and posting provocatively titled blog entries like "OO and SQL aren't orthogonal concepts, there's no mismatch impedance" ain't going to help. The only thing this creates is a lot of needless complexity and, of course, there shall always be major SNAFU like this one. Maybe, just maybe, that we could realize that if the reader is set to "from now on do not eval anymore" code shall not be eval'ed? And maybe, just maybe, that we could realize that if you're not using SQL you're not subject to these monthly SQL injections issues? How far does the SNAFU need to go for you to consider that OO + SQL is actually a very, very poor mix?
- deleted 14y ago[deleted]
- mpchlets 14y agoI believe that its a test of how quickly you can patch your applications when something like this does come out - We did it in 3 hours from time of bulletin - how about you? http://blog.assembla.com/assemblablog/tabid/12618/bid/93731/Continuous-Deployment-is-Secure-Howto-Patch-3rd-Party-Apps-Uber-Fast.aspx http://blog.assembla.com/assemblablog/tabid/12618/bid/93731/...
- gnuvince 14y agoThe more I read these stories (and not just in Rails, though they seem to be the most talked about), the more I seriously consider taking the time to evaluate frameworks such as Yesod where the type system makes these kinds of security flaws impossible.
- FooBarWidget 14y agoI've written a blog post which explains what this vulnerability is, how it works, what the facts and non-facts are: http://blog.phusion.nl/2013/01/03/rails-sql-injection-vulnerability-hold-your-horses-here-are-the-facts/ http://blog.phusion.nl/2013/01/03/rails-sql-injection-vulner...
- timblair 14y agoThanks for that: really clears things up. It would have been really useful if the upgrade notification had included this level of detail to start with so people could make a much more informed decision about when/if to upgrade, rather than having to dive through bug reports, commits etc just to work out if our apps are vulnerable.