Skip to content

Commit

Permalink
Fixed issue #18984: [security] CSRF in Question Themes function (#3459)
Browse files Browse the repository at this point in the history
Function toggleVisibility is now requested via POST.

Co-authored-by: Lapiu Dev <devgit@lapiu.biz>
  • Loading branch information
gabrieljenik and lapiudevgit committed Sep 19, 2023
1 parent 11051a9 commit 454e73c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions application/controllers/admin/QuestionThemes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class QuestionThemes extends SurveyCommonAction
*/
public function toggleVisibility($id)
{
$this->requirePostRequest();

if (!Permission::model()->hasGlobalPermission('templates', 'update')) {
throw new CHttpException(403, gT("We are sorry but you don't have permissions to do this."));
}
Expand Down
12 changes: 8 additions & 4 deletions application/views/themeOptions/installedthemelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ function(id, data){
for (let togglequestiontheme of togglequestionthemes) {
togglequestiontheme.addEventListener("change", () => {
let $url = togglequestiontheme.getAttribute("data-url");
let data = new FormData();
let xhttp = new XMLHttpRequest();
xhttp.open("GET", $url, true);
xhttp.send();
data.append(LS.data.csrfTokenName, LS.data.csrfToken);
xhttp.open("POST", $url, true);
xhttp.send(data);
});
}
}',
Expand All @@ -115,9 +117,11 @@ function(id, data){
for (let togglequestiontheme of togglequestionthemes) {
togglequestiontheme.addEventListener("change", () => {
let $url = togglequestiontheme.getAttribute("data-url");
let data = new FormData();
let xhttp = new XMLHttpRequest();
xhttp.open("GET", $url, true);
xhttp.send();
data.append(LS.data.csrfTokenName, LS.data.csrfToken);
xhttp.open("POST", $url, true);
xhttp.send(data);
});
}
';
Expand Down

0 comments on commit 454e73c

Please sign in to comment.