5 ms·
I'm starting to wonder if the DRY-uber-alles notion popularized by Rails is turning into a security antipattern. It's just too easy for code like this (intende
by ajross 14y ago
I'm starting to wonder if the DRY-uber-alles notion popularized by Rails is turning into a security antipattern. It's just too easy for code like this (intended to "make things work cleanly") to forget all the needed checks and all the constraints on the design.
The end user ends up repeating themselves less, but that means that the library code ends up getting used in lots of places and for lots of purposes that the author didn't necessarily think through...
- __david__ 14y agoIt also means that when a bug is found in that code that you only have to fix it in one place, not 75,000 random places where it's duplicated, and probably slightly differently each time, making it hard to search for.
- ajross 14y agoThat seems to be belied by this very case, no? Rails had two ways of doing something, one of which forgot where the input could come from...
- __david__ 14y agoHmm... How would copy-pasta code have prevented this?
- ajross 14y agoI fear from your language that you aren't really interested in reasonable argument, but I'll try anyway: ActiveRecord had two variant find() interfaces, one of which tried to make it "easy" on the programmer by avoiding the need to extract an ID to do the lookup. And it went further by adding an overloaded argument syntax that allowed you to elide the first argument entirely. And it forgot that that second argument simultaneously (1) was defined by a remote client and (2) could contain arbitrary SQL. So yes: "copy pasta" of the id boilerplate around an AR find() call would absolutely have prevented this. Rails got slick, and got burned. DRY helped reduce "copy pasta" (sigh) but hurt security.
- __david__ 14y agoIsn't that really the fault of an overloaded (as in doing too much) function API rather than a DRY related problem?
- ajross 14y agoWell, yes, but my point was that I see them as part of the same thing. A function (or whatever) that does lots of related things can be "DRY" if it avoids writing out all the related things longhand, or it can be "too much" if it introduces bugs. DRY as a general philosophy to avoid cut-and-paste code is fine. But it's also an ethic that in my experience prioritizes concision at the expense of clarity. Loss of clarity is a factor in half the security bugs on the internet.
- tptacek 14y agoThe vulnerability here was caused by deliberately introduced complexity --- features for features sake. You're tempted to blame the dynamic finders (which have fallen far out of fashion anyways) but really the issue here is Rails parameter handling, which was not designed to minimize typing for Ruby programmers.