DEV: attempts to prevent session object to be retain in csrf init (#7743)

This commit is contained in:
Joffrey JAFFEUX 2019-06-11 09:59:14 +02:00 committed by GitHub
parent c407e32368
commit 62c56b6e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -1,15 +1,16 @@
// Append our CSRF token to AJAX requests when necessary. // Append our CSRF token to AJAX requests when necessary.
export default { export default {
name: "csrf-token", name: "csrf-token",
initialize: function(container) { initialize(container) {
var session = container.lookup("session:main"); const session = container.lookup("session:main");
const csrfToken = $("meta[name=csrf-token]").attr("content");
// Add a CSRF token to all AJAX requests // Add a CSRF token to all AJAX requests
session.set("csrfToken", $("meta[name=csrf-token]").attr("content")); session.set("csrfToken", csrfToken);
$.ajaxPrefilter(function(options, originalOptions, xhr) { $.ajaxPrefilter(function(options, originalOptions, xhr) {
if (!options.crossDomain) { if (!options.crossDomain) {
xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken")); xhr.setRequestHeader("X-CSRF-Token", csrfToken);
} }
}); });
} }