Rails request forgery protection settings -


please newbie in rails :) have protect_from_forgery call (which given default) no attributes in applicationcontroller class.

basically here's code:

class applicationcontroller < actioncontroller::base   helper :all # include helpers, time   protect_from_forgery   helper_method :current_user_session, :current_user   filter_parameter_logging :password, :password_confirmation 

what assume should is: should prevent post requests without correct authenticity_token. when send post request jquery 1 below, works fine (there's update statement executed in database)!

$.post($(this).attr("href"), { _method: "put", data: { test: true } }); 

i see in console there's no authenticity_token among sent parameters, request still considered valid. why that?

upd found config setting in config/environments/development.rb

config.action_controller.consider_all_requests_local = true 

because of dev environment , local requests, these jquery post requests ok.

there nothing wrong code long request $.post($(this).attr("href"), { _method: "put", data: { test: true } }); executed within app itself. if had app running elsewhere, example on localhost:3001, , sent post there won't work. infact if on firefox > 3.0 has implementation of cross site xhr too. example can send post other site (but works provided protect_from_forgery turned off!). reason why auth token not necessary xhr cross site xhr disabled. safe use xhr without providing auth token. if try else other app, sure raise exception asking auth token. should have crossdomain.xml defined prevent access outside sources.

try doing this: curl -x -d url_endpoint_of_your_app. see if 200 response code. if there fishy.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -