Skip to content

Commit

Permalink
StudentQuiz: can we mitigate the potential XSS risks? #812360
Browse files Browse the repository at this point in the history
  • Loading branch information
Khoa Nguyen committed Aug 19, 2024
1 parent ecd900c commit c9aecb4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ function studentquiz_supports($feature) {
}
}

/**
* Callback immediately after require_login succeeds.
*/
function studentquiz_after_require_login() {
global $PAGE, $CFG, $COURSE;
$forceclean = false;

if ($PAGE->activityname === 'studentquiz') {
$forceclean = true;
} else {
$instanceid = null;
if ($catparam = optional_param('cat', null, PARAM_SEQUENCE)) {
[, $contextid] = explode(',', $catparam);
$instanceid = context::instance_by_id($contextid)->instanceid;
} else if ($questionid = optional_param('id', null, PARAM_INT)) {
$question = question_bank::load_question($questionid);
$instanceid = context::instance_by_id($question->contextid)->instanceid;
}

if ($instanceid && get_course_and_cm_from_cmid($instanceid, 'studentquiz', $COURSE)) {
$forceclean = true;
}
}

if ($forceclean) {
$CFG->forceclean = true;
}
}

/**
* Saves a new instance of the StudentQuiz into the database
*
Expand Down

0 comments on commit c9aecb4

Please sign in to comment.