3 ms·
What a fantastic bug. Rails routes HEAD to GET, but .get? in a HEAD handler is false. Github uses a postback to /authorize to complete OAuth, distinguishing bet
by tptacek 7y ago
What a fantastic bug. Rails routes HEAD to GET, but .get? in a HEAD handler is false. Github uses a postback to /authorize to complete OAuth, distinguishing between the original GET and the completing POST with .get?. Rails sees the HEAD request and assumes it's a POST (because it's not .get?) --- and also assumes that, because it's a POST, it's CSRF protected, which it is not, because it is not actually a POST.
- eganist 7y agoIt's bad assumptions all the way down. Also easy to bake into basic static analysis going forward. Knowing GitHub, I'd think a bug like this probably won't show up again in the near future.
- jacquesm 7y ago> It's bad assumptions all the way down. It always is. The moment you can shine light between your model of what the code does and what it actually does you have at least a bug and maybe much worse.
- ljm 7y agoIt also looks like a Rails bug, unless Github routed the HEAD requests themselves. In that case, it’s a shortcut that bit them in the ass.
- ryanisnan 7y agoRails is not assuming that it's a POST. The conditional logic in the controller explicitly checks for a get, and then else's otherwise. This is an unfortunate consequence of not having routing go to specific methods, e.g. `def post():`.
- tptacek 7y agoRails routing does go to specific methods ordinarily. What's funny here is, apparently, .get? used to return true for HEAD requests.