DEV: prevents csrf-token initializer to leak session object (#7730)
This commit is contained in:
parent
df01249db4
commit
da5255e560
|
@ -1,15 +1,20 @@
|
||||||
// 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) {
|
|
||||||
var session = container.lookup("session:main");
|
initialize(container) {
|
||||||
|
const session = container.lookup("session:main");
|
||||||
|
|
||||||
|
const csrfToken = document
|
||||||
|
.querySelector("meta[name=csrf-token]")
|
||||||
|
.getAttribute("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((options, originalOptions, xhr) => {
|
||||||
if (!options.crossDomain) {
|
if (!options.crossDomain) {
|
||||||
xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken"));
|
xhr.setRequestHeader("X-CSRF-Token", csrfToken);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue