Skip to content

Commit

Permalink
#133 Prevent XSS in response rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastsg committed May 3, 2024
1 parent e2eb59f commit 8513d78
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function get_results(jazzquiz_session $session): array {
$session->load_attempts();
$slot = count($session->questions);
$qtype = $session->get_question_type_by_slot($slot);
$results = $session->get_question_results_list($slot);
$results = $session->get_question_results_list($slot, true);
list($results['responses'], $mergecount) = $session->get_merged_responses($slot, $results['responses']);

// Check if this has been voted on before.
Expand Down
2 changes: 1 addition & 1 deletion classes/exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function export_session_question(jazzquiz_session $session, jazzquiz_atte
$qattempt = $attempt->quba->get_question_attempt($slot);
$question = $qattempt->get_question();
$session->load_attempts();
$responses = $session->get_question_results_list($slot);
$responses = $session->get_question_results_list($slot, false);
$responses = $responses['responses'];
$name = 'session_ ' . $session->data->id . '_' . $session->data->name . '_' . $question->name;
return [$name, $question->questiontext, $responses];
Expand Down
5 changes: 4 additions & 1 deletion classes/jazzquiz_session.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,17 @@ public function get_question_right_response(): string {
* @param int $slot
* @return array
*/
public function get_question_results_list(int $slot): array {
public function get_question_results_list(int $slot, bool $sanitized): array {
$responses = [];
$responded = 0;
foreach ($this->attempts as $attempt) {
if ($attempt->responded != 1) {
continue;
}
$attemptresponses = $attempt->get_response_data($slot);
if ($sanitized) {
$attemptresponses = array_map(fn($attemptresponse) => s($attemptresponse), $attemptresponses);
}
$responses = array_merge($responses, $attemptresponses);
$responded++;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function view_session_report(jazzquiz_session $session, moodle_url $url):
foreach ($attempt->quba->get_slots() as $qubaslot) {
$qattempt = $attempt->quba->get_question_attempt($qubaslot);
$question = $qattempt->get_question();
$results = $session->get_question_results_list($qubaslot);
$results = $session->get_question_results_list($qubaslot, true);
list($results['responses'], $mergecount) = $session->get_merged_responses($qubaslot, $results['responses']);
$slots[] = [
'num' => $qubaslot,
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024032201; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2024032202; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2023100900; // Moodle 4.3 (or above).
$plugin->cron = 0; // Period in seconds for cron to run.
$plugin->component = 'mod_jazzquiz';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '1.3.1 (Build: 2024032201)';
$plugin->release = '1.3.2 (Build: 2024032202)';

0 comments on commit 8513d78

Please sign in to comment.