Repository navigation
Quiz attempt security improved - #3282
harunollyo wants to merge 3 commits into
Conversation
…ly during evaluation
shewa12
left a comment
There was a problem hiding this comment.
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.
| ->where_in( 'question_id', $question_ids ) | ||
| ->first(); | ||
|
|
||
| $total_question_marks = intval( $total_question_marks ? $total_question_marks->total_marks : 0 ); |
There was a problem hiding this comment.
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.
| $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 ); |
There was a problem hiding this comment.
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.
ClickUp ticket link: https://app.clickup.com/t/9018365849/z8zyy1vjmg
Testing
Use of AI Tool
Used: Yes
Used for: Identify the issue