Skip to content

Instantly share code, notes, and snippets.

@shotgundebugging
Forked from mctaylorpants/csrf_helper.rb
Created January 5, 2024 12:07
Show Gist options
  • Save shotgundebugging/110b32ba5dc89235804c53bb32486ce6 to your computer and use it in GitHub Desktop.
Save shotgundebugging/110b32ba5dc89235804c53bb32486ce6 to your computer and use it in GitHub Desktop.
CSRF protection in Rails - #csrf_meta_tags
# actionview/lib/action_view/helpers/csrf_helper.rb
def csrf_meta_tags
if defined?(protect_against_forgery?) && protect_against_forgery?
[
tag("meta", name: "csrf-param", content: request_forgery_protection_token),
tag("meta", name: "csrf-token", content: form_authenticity_token)
].join("\n").html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment