Conversation
…reviews, Q&A, and orders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves two critical security issues regarding SQL injection, format placeholder injection, and unparameterized query execution identified during the scheduled security audit:
1. SQL Injection & Format Specifier Injection in Reviews and Q&A Queries (
classes/Utils.php)Utils::get_course_reviews()andUtils::get_qa_questions()get_course_reviews():$status_inwas wrapped in double-quotes and concatenated without escaping or sanitize validation ($status_in = '"' . implode( '","', $status_in ) . '"').$include_user_idwas directly imploded without casting elements to integers, leading to unvalidated SQL concatenation into_reviews.user_id IN ({$include_user_id}).$wpdb->prepare().get_qa_questions():$args['date']was passed viaesc_sql()and concatenated directly into the$wpdb->prepare()template:AND DATE(_question.comment_date)='{$date}'. If the date input contains format specifiers (%s,%d,%), the outer$wpdb->prepare()interprets them as placeholders, consuming$search_termand leaving the subsequent placeholders without arguments.$my_course_idsand$question_idswere imploded as raw arrays without strict integer casting orQueryHelper::prepare_in_clause().$args['order']was not checked usingQueryHelper::get_valid_sort_order().%s) causes placeholder shift in$wpdb->prepare(), resulting in query malfunction or syntax errors.$include_user_idallows raw SQL injection into theWHEREclause.get_course_reviews():sanitize_key()andQueryHelper::prepare_in_clause()on$status_in.absint()andQueryHelper::prepare_in_clause()on$include_user_id.$startand$limittoabsint().get_qa_questions():tutor_get_formated_date( 'Y-m-d', $args['date'] )and parameterized the date with%sin the single outer$wpdb->prepare()query.QueryHelper::get_valid_sort_order()on$args['order'].QueryHelper::prepare_in_clause()withabsint()on course IDs and question IDs.2. Double-Prepare Format String Vulnerability & Unparameterized Order Status in User Orders Query (
models/OrderModel.php)OrderModel::get_user_orders()$date_range_clausewas generated using a nested$wpdb->prepare('AND DATE(created_at_gmt) BETWEEN %s AND %s', $start_date, $end_date)call and then interpolated into the SQL template for the outer$wpdb->prepare(...). When user-controlled date strings contain format characters (such as%sor%), outer placeholder counting is corrupted, shifting$user_id,$limit, and$offsetparameters.$order_statuswas concatenated directly into$order_status_clause(AND o.order_status = '{$order_status}') rather than being parameterized with%s.$args['order_type']was escaped withesc_sql()rather than key sanitization.OrderModel::get_user_orders()with date strings containing format specifiers causes outer$wpdb->prepareplaceholder misalignment, displacing the numeric$user_idand limit/offset parameters into unintended clauses.DATE(created_at_gmt) BETWEEN CAST(%s AS DATE) AND CAST(%s AS DATE)directly into the query template and passing validated date strings via the unified$paramsarray.$order_statusas%swithsanitize_key().order_typeusingsanitize_key().$limitand$offsettoabsint().Verification
php -l).$wpdbpreparation guidelines.