Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save samhendley/415780 to your computer and use it in GitHub Desktop.
Save samhendley/415780 to your computer and use it in GitHub Desktop.
# this monkey patch for Rails 2.3.5 means each action has its own token, i'm not
# sure if this actually makes things more secure or worse.
ActionController::RequestForgeryProtection.class_eval do
def form_authenticity_token_with_action(*args)
session_var_name = "_csrf_token_#{controller_name}_#{action_name}"
session[session_var_name.to_sym] ||= ActiveSupport::SecureRandom.base64(32)
end
alias_method_chain :form_authenticity_token, :action
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment