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.5.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
jets-1.5.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee