Skip to content

Quiz attempt security improved - #3282

Open
harunollyo wants to merge 3 commits into
4.3.0from
security/z8zyy1vjmg
Open

harunollyo wants to merge 3 commits into
4.3.0from
security/z8zyy1vjmg

Conversation

@harunollyo

Copy link
Copy Markdown
Collaborator

ClickUp ticket link: https://app.clickup.com/t/9018365849/z8zyy1vjmg

Testing

  • Tested
  • Not tested

Use of AI Tool

Used: Yes

Used for: Identify the issue

@harunollyo
harunollyo requested a review from shewa12 December 2, 2026 11:27
@harunollyo harunollyo self-assigned this Dec 2, 2026
@harunollyo harunollyo added the 4.3.0 Tutor v4.3.0 label Dec 2, 2026
@harunollyo
harunollyo marked this pull request as draft December 3, 2026 05:41
@harunollyo
harunollyo marked this pull request as ready for review December 3, 2026 06:41

@shewa12 shewa12 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-deriving the served questions on the server closes the reported bypass. Total marks now cover every served question, and unanswered ones are scored as wrong. Two things still need fixing before this is complete.

🔴 The instant answer-check endpoint can still inflate the score (Quiz.php around L1395–1470; outside this diff, so noting it here). The endpoint only checks that question_id belongs to the quiz, not that it was served in this attempt. On submit, when committed answers exist, earned marks come from $stats->total_earned_marks, which sums every row in tutor_quiz_attempt_answers. total_marks only covers the served set. So on a quiz that shows 3 of 10 questions, a user can commit answers to questions that weren't shown and push earned marks past the total (above 100%). Please reject question_ids that aren't in get_random_questions_by_quiz() for the attempt, and/or only sum served questions when calculating earned marks.

🟡 Nit: templates/learning-area/quiz/attempt.php:97 and templates/single/quiz/parts/question.php:100 still output the hidden quiz_question_ids[] fields, which nothing reads now. Safe to remove.

Comment thread classes/Quiz.php
->where_in( 'question_id', $question_ids )
->first();

$total_question_marks = intval( $total_question_marks ? $total_question_marks->total_marks : 0 );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question_mark is decimal(9,2), so intval() drops the fraction (7.50 → 7) while earned marks stay decimal. The pass percentage comes out too high, and a perfect score can show above 100%. The old get_var() kept the decimal. Please use (float) here.

Comment thread classes/Quiz.php
$question_ids = tutor_utils()->avalue_dot( 'quiz_question_ids', $attempt_answer );
$question_ids = array_filter( $question_ids, fn ( $id ) => is_numeric( $id ) && intval( $id ) > 0 );
$quiz_answers = tutor_utils()->avalue_dot( 'quiz_question', $attempt_answer );
$served_questions = tutor_utils()->get_random_questions_by_quiz( $attempt->quiz_id );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-picking the served set at submit depends on RAND(attempt_id) + LIMIT returning the same rows as at render. That stops being true if the instructor adds, removes or reorders questions, or changes questions_order, while an attempt is open, or if the result of tutor_filter_unsupported_quiz_question_types changes (e.g. Pro turned on or off). The student then gets scored on questions they never saw.

Saving the served question IDs on the attempt when it starts, and validating against that list here, would be more robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.3.0 Tutor v4.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants