Note that there are some explanatory texts on larger screens.

plurals
  1. PORails, OAuth, and CSRF protection
    primarykey
    data
    text
    <p>I am using REST and OAuth to talk to a Rails app (from an iPhone app, but that should not be relevant). However, I am running into some issues with Rails' CSRF protection (via <code>protects_from_forgery</code>).</p> <p>I understand that CSRF protection only kicks in for regular form submissions (i.e. Content-Type=application/x-www-form-urlencoded), so I would be fine if I was submitting JSON or XML data. Unfortunately, OAuth is currently limited to application/x-www-form-urlencoded requests. There's a <a href="http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/3/spec.html" rel="nofollow noreferrer">draft spec that extends OAuth to non-form-urlencoded data</a>, but this doesn't help me right now.</p> <p>The way I see it, I have the following options:</p> <ol> <li><p>Send the data as JSON, knowing that it would not be part of the OAuth signature and thus subject to man-in-the-middle attacks. Obviously not an attractive solution.</p></li> <li><p>Create special Rails actions (e.g. <code>UsersController#update_oauth</code>) that internally delegate to the regular actions (e.g. <code>UsersController#update</code>). Then exclude these from the forgery protection (<code>protects_from_forgery :only =&gt; [:update]</code>). This should work and might be borderline acceptable for one or two actions, but obviously would be a very messy solution.</p></li> <li><p>Override the Rails CSRF protection to ignore OAuth requests. I have not tried this, but it seems like it should be possible to change one of the hooks (perhaps the <code>verify_authenticity_token</code> filter) to consider OAuth requests successful.</p></li> </ol> <p>Has anybody run into this before? Any recommendations? Or am I perhaps missing something basic?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload