Skip to content

Commit 18c5b30

Browse files
authored
Merge pull request #2728 from kobotoolbox/csrf-ocha-hotfix
pull the 64 character csrftoken from document.cookie
2 parents 8bc3c90 + a0914fc commit 18c5b30

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

jsapp/js/main.es6

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ function csrfSafeMethod(method) {
2525
// these HTTP methods do not require CSRF protection
2626
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
2727
}
28+
29+
let csrfToken = '';
30+
try {
31+
csrfToken = document.cookie.match(/csrftoken=(\w{64})/)[1];
32+
} catch (err) {
33+
console.error('Cookie not matched');
34+
}
35+
2836
$.ajaxSetup({
2937
beforeSend: function(xhr, settings) {
3038
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
31-
xhr.setRequestHeader('X-CSRFToken', cookies.get('csrftoken'));
39+
xhr.setRequestHeader('X-CSRFToken', csrfToken || cookies.get('csrftoken'));
3240
}
3341
}
3442
});

0 commit comments

Comments
 (0)