mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-27 22:33:10 +09:00
Insert CSRF token into every AJAX request
This commit is contained in:
parent
6afa7b3255
commit
14300cbcc3
2 changed files with 13 additions and 4 deletions
|
|
@ -17,7 +17,19 @@
|
|||
($.os.Linux) ? 'Linux' :
|
||||
($.os.Unix) ? 'Unix' :
|
||||
($.os.Mac) ? 'Mac' : '';
|
||||
|
||||
|
||||
/* Intercept jQuery AJAX calls to add CSRF headers */
|
||||
$.ajaxPrefilter(function(options) {
|
||||
var _u1 = $("<a>").attr("href", location.href)[0];
|
||||
var _u2 = $("<a>").attr("href", options.url)[0];
|
||||
if (_u2.hostname && (_u1.hostname !== _u2.hostname)) return;
|
||||
var token = getCSRFToken();
|
||||
if (token) {
|
||||
if (!options.headers) options.headers = {};
|
||||
options.headers["X-CSRF-Token"] = token;
|
||||
}
|
||||
});
|
||||
|
||||
/* Intercept getScript error due to broken minified script URL */
|
||||
$(document).ajaxError(function(event, jqxhr, settings, thrownError) {
|
||||
if(settings.dataType === "script" && (jqxhr.status >= 400 || (jqxhr.responseText && jqxhr.responseText.length < 40))) {
|
||||
|
|
|
|||
|
|
@ -149,7 +149,6 @@
|
|||
$.ajax({
|
||||
url : url,
|
||||
type : "POST",
|
||||
headers: { "X-CSRF-Token": params._rx_csrf_token },
|
||||
dataType : "json",
|
||||
data : params,
|
||||
success : successHandler,
|
||||
|
|
@ -259,7 +258,6 @@
|
|||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
headers: { "X-CSRF-Token": params._rx_csrf_token },
|
||||
url: request_uri,
|
||||
data: params,
|
||||
success : successHandler,
|
||||
|
|
@ -324,7 +322,6 @@
|
|||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "html",
|
||||
headers: { "X-CSRF-Token": params._rx_csrf_token },
|
||||
url: request_uri,
|
||||
data: params,
|
||||
success: successHandler,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue