Skip to content

Commit

Permalink
Check that request is same-origin prior to including CSRF token in XHRs
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMc authored and tenderlove committed May 15, 2020
1 parent 29aa538 commit 47a8dc3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee
Expand Up @@ -52,9 +52,10 @@ createXHR = (options, done) ->
# Sending FormData will automatically set Content-Type to multipart/form-data
if typeof options.data is 'string'
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest') unless options.crossDomain
# Add X-CSRF-Token
CSRFProtection(xhr)
unless options.crossDomain
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
# Add X-CSRF-Token
CSRFProtection(xhr)
xhr.withCredentials = !!options.withCredentials
xhr.onreadystatechange = ->
done(xhr) if xhr.readyState is XMLHttpRequest.DONE
Expand Down

0 comments on commit 47a8dc3

Please sign in to comment.