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.8.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.8.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.7.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.7.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.7.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.6.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.10 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee