Skip to content

/models files security audit and fixes and query update - #3136

Open
Anindra123 wants to merge 51 commits into
4.3.0from
chore/models/security-fixes
Open

Anindra123 wants to merge 51 commits into
4.3.0from
chore/models/security-fixes

Conversation

@Anindra123

@Anindra123 Anindra123 commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

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

Description

  • Found out vulnerabilities for classes in models/ folder

  • Updated classes in models folder to use new fluent DB query instead of QueryHelper

  • Added unit tests for several model classes

  • QuizModel.php

    • Added ABSPATH check
    • In get_quiz_answers_by_attempt_id the attempt_id was not type casted to int, further more there was no prepare statement on the query
    • IN get_quiz_attempt_timing @unserialize was calling with error suppressed with no proper flag passed to prevent PHP object injection
    • In get_quiz_count_by_course the query was updated to use query helper instead
  • CourseModel.php

    • Added abspath check
    • In get_courses added check for excludes id array and post status parameter and used prepare in clause
    • Utilized cap manage_options instead of administrator
  • EnrollmentModel.php

    • Added abspath check
    • In get_enrolled_data added check for status and course id post type
  • OrderModel.php

    • Added abspath check
    • In create_order after catch no rollback query was running
    • In get_refunds_by_user the $user_id was placed with direct interpolation with no prepare query check

Testing

  • Tested
  • Not tested

Use of AI Tool

Used: Yes

Used for:
Finding security issues on all the classes in models/

Anindra123 and others added 30 commits October 1, 2026 15:31
`UserModel.php` Fix:  typcast to int before placing it in string interpolation for query
Fix: Query hardened for the several model class
 `QuizModel.php` : Security Fixes
@Anindra123
Anindra123 changed the base branch from dev to 4.2.1 October 28, 2026 05:47
@Anindra123 Anindra123 added 4.2.1 and removed future labels Oct 28, 2026

@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.

A couple of regressions were found in EnrollmentModel and QuizModel. Please see the inline notes.

Comment thread models/EnrollmentModel.php Resolved
Comment thread models/QuizModel.php Outdated
$attempt_duration = '';
$attempt_duration_taken = '';
$attempt_info = @unserialize( $attempt_data->attempt_info );
$raw_info = trim( (string) $attempt_data->attempt_info ?? '' );

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.

Due to operator precedence, type casting (string) binds tighter than ??. If $attempt_data->attempt_info is undefined or null on the object, (string) $attempt_data->attempt_info evaluates first and triggers a PHP Warning: Undefined property: stdClass::$attempt_info.

Wrapping the null coalescing expression in parentheses resolves this:

Suggested change
$raw_info = trim( (string) $attempt_data->attempt_info ?? '' );
$raw_info = trim( (string) ( $attempt_data->attempt_info ?? '' ) );

@Anindra123 Anindra123 added 4.2.2 and removed 4.2.1 labels Nov 11, 2026
@Anindra123
Anindra123 changed the base branch from 4.2.1 to 4.2.2 November 11, 2026 04:21
Comment thread models/CourseModel.php Resolved
Comment thread models/EnrollmentModel.php Resolved
Comment thread models/QuizModel.php Resolved
Comment thread models/EnrollmentModel.php Resolved
@Anindra123
Anindra123 requested a review from shewa12 November 16, 2026 07:17
@Anindra123 Anindra123 removed the 4.2.2 label Nov 18, 2026
@Anindra123
Anindra123 changed the base branch from 4.2.2 to 4.3.0 November 18, 2026 07:34
@Anindra123 Anindra123 added the 4.3.0 Tutor v4.3.0 label Nov 18, 2026
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 future

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants