Skip to content

Commit

Permalink
Fixed issue #17674: Impossible to add new Menu or New Menu Entry (#2136)
Browse files Browse the repository at this point in the history
* Fixed issue #17674: Impossible to add new Menu or New Menu Entry

* Fixed issue #17674: Impossible to add new Menu or New Menu Entry

- Add comments

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik and encuestabizdevgit committed Nov 15, 2021
1 parent ae5365b commit 9941ccf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions application/extensions/LimeScript/LimeScript.php
Expand Up @@ -26,11 +26,18 @@ function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(jqXHR, settings) {
if(!csrfSafeMethod(settings.type)) {
// Use $.ajaxPrefilter() instead of $.ajaxSetup({beforeSend: ...}) to add the CSRF token because beforeSend is
// executed after the content type is determined. So, if the request had no data when beforeSend is executed,
// the content type is 'text/plain', which is wrong.
$.ajaxPrefilter(function(settings) {
if(!csrfSafeMethod(settings.type)) {
// Data could be passed as string or object, so we add the token depending on the data type
if (typeof settings.data == 'string') {
// NB: This sometimes includes the CSRF token twice, when already added to data.
settings.data += '&" . Yii::app()->request->csrfTokenName . "=" . Yii::app()->request->csrfToken ."';
} else {
settings.data = settings.data || {};
settings.data." . Yii::app()->request->csrfTokenName . " = '" . Yii::app()->request->csrfToken . "';
}
}
});";
Expand Down

0 comments on commit 9941ccf

Please sign in to comment.