Sha256: 994219e6f2527a4ff50d0e313765ceff7b830fd5b34957b1d203e3cfb69b1116

Contents?: true

Size: 788 Bytes

Versions: 47

Compression:

Stored size: 788 Bytes

Contents

#= require ./dom

{ $ } = Rails

# Up-to-date Cross-Site Request Forgery token
csrfToken = Rails.csrfToken = ->
  meta = document.querySelector('meta[name=csrf-token]')
  meta and meta.content

# URL param that must contain the CSRF token
csrfParam = Rails.csrfParam = ->
  meta = document.querySelector('meta[name=csrf-param]')
  meta and meta.content

# Make sure that every Ajax request sends the CSRF token
Rails.CSRFProtection = (xhr) ->
  token = csrfToken()
  xhr.setRequestHeader('X-CSRF-Token', token) if token?

# Make sure that all forms have actual up-to-date tokens (cached forms contain old ones)
Rails.refreshCSRFTokens = ->
  token = csrfToken()
  param = csrfParam()
  if token? and param?
    $('form input[name="' + param + '"]').forEach (input) -> input.value = token

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
jets-1.9.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.9.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.9.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.9.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.9.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.9.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.9.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.9.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.14 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.13 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.12 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.11 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.10 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee