Anchor CMS 0.12.7 - Stored Cross Site Scripting (XSS)

Exploit Author: /bin/neko Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2025-06-15
# Exploit Title: Anchor CMS 0.12.7 - Stored Cross Site Scripting (XSS)
# Google Dork: inurl:"/admin/pages/add" "Anchor CMS"
# Date: 2025-06-08
# Exploit Author: /bin/neko
# Vendor Homepage: http://anchorcms.com
# Software Link: https://github.com/anchorcms/anchor-cms
# Version: 0.12.7
# Tested on: Ubuntu 22.04 + Apache2 + PHP 8.1
# CVE: CVE-2025-46041

# Description:
Anchor CMS v0.12.7 suffers from a stored Cross-Site Scripting (XSS) vulnerability
in the `markdown` field of the /admin/pages/add page.
An authenticated user with page creation privileges can inject arbitrary JavaScript,
which is stored and executed when the page is viewed.

# Steps to Reproduce:
1. Login to /admin
2. Navigate to Pages > Add Page
3. In the `Markdown` field, insert:
   <script>alert(document.domain)</script>
4. Save the page.
5. View the created page. The script executes.

# Impact:
- Arbitrary JavaScript execution
- Potential session hijacking or admin impersonation


Anchor CMS 0.12.7 — Stored Cross‑Site Scripting (XSS) (CVE-2025-46041)

Summary: Anchor CMS 0.12.7 contains a stored Cross‑Site Scripting (XSS) vulnerability in the page creation workflow. An authenticated user with permission to create pages can store malicious script content in the page body that will be executed in the browser of anyone who views that page. This article explains the nature and impact of the issue, defensive detection and mitigation strategies, and secure coding fixes that reduce or eliminate the risk.

What is stored XSS and why it matters

Stored XSS occurs when an application accepts unsafe input and persistently stores it (for example, in a database) and later renders that input into pages without sufficient output encoding or sanitization. When other users (or administrators) view the stored content, the browser executes the injected script in the context of the target site. Consequences include session theft, account takeover, unauthorized actions, information disclosure, and pivoting to other parts of the application.

Vulnerability overview

  • Affected component: the page creation form (markdown/body field) in Anchor CMS 0.12.7.
  • Attack vector: authenticated user with page-creation privileges stores HTML/JavaScript in the page body.
  • Execution context: when the stored page is rendered for viewers, the browser executes the injected script.
  • CVE: CVE-2025-46041
  • Typical impact: arbitrary JavaScript execution, session hijacking, admin impersonation, data exfiltration, request forgery.

High-level reproduction (defensive summary)

At a high level, the issue arises because raw HTML or script content supplied through the page editor is persisted and later rendered without proper sanitization or output encoding. The precise reproduction is not presented here; administrators should assume any user-provided HTML in the editable fields is potentially dangerous unless explicitly sanitized or escaped.

Immediate risk mitigation (fast actions)

  • Restrict page creation and editing permissions to a small set of trusted accounts while you investigate.
  • Temporarily disable rendering of raw HTML in user-editable fields (see safe Markdown rendering below).
  • Deploy a Content Security Policy (CSP) to reduce the blast radius of inline script execution.
  • Search the database for suspected script or suspicious HTML and remove or quarantine affected pages.

Detecting existing exploitation or stored payloads

Search content that contains HTML tags (especially <script>, event handlers like onload, or <iframe>). Review access logs for unusual page views and correlate with administrative activity. Examples of detection queries:

-- Example SQL: find pages that contain script tags (adjust field/table names for your schema)
SELECT id, title, body FROM pages WHERE body LIKE '%<script%';

Explanation: This query scans stored page bodies for occurrences of the <script> tag. Use more sophisticated scanning (regular expressions, HTML parsing) to detect other injection forms and obfuscated payloads.

Short-term technical mitigations

  • Enable safe mode in your Markdown renderer so that raw HTML embedded in Markdown is ignored or sanitized.
  • Run a server-side sanitiser (HTMLPurifier or similar) before saving or before rendering stored HTML.
  • Set cookies with Secure, HttpOnly, and SameSite attributes to make session theft via JavaScript harder.
  • Add a strict CSP header to disallow inline scripts and only allow scripts from trusted origins.

Recommended long-term fixes (secure coding)

The most robust resolution is to ensure untrusted content is never rendered as active HTML without explicit, controlled sanitization. Below are code-level recommendations with examples.

1) Use a Markdown renderer in safe mode

// Example: Parsedown safe mode (PHP)
$Parsedown = new Parsedown();
$Parsedown->setSafeMode(true); // disables raw HTML in markdown
$html = $Parsedown->text($markdown_input);

Explanation: Many Markdown libraries provide a "safe mode" that strips or neutralizes embedded HTML. Enabling this prevents users from supplying raw HTML or script tags in Markdown fields. This approach is useful when you want to preserve Markdown features but disallow arbitrary HTML.

2) Sanitize HTML with a proven library (recommended)

// Example: using HTMLPurifier (install via Composer: ezyang/htmlpurifier)
require_once 'vendor/autoload.php';
$config = HTMLPurifier_Config::createDefault();
// configure allowed elements and attributes as needed:
$config->set('HTML.Allowed', 'p,b,i,a[href],ul,ol,li,br,strong,em,img[src|alt|width|height]');
$config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www.youtube.com|player.vimeo.com)%'); // optional
$purifier = new HTMLPurifier($config);

$clean_html = $purifier->purify($user_html_input);

Explanation: HTMLPurifier performs a full DOM-aware sanitization, removing scripts, dangerous attributes (on* handlers), and unsafe elements. Configure allowed tags and attributes conservatively. Use this either at save time or at render time to ensure persisted content is safe.

3) Output encoding and escaping

// Example: encoding a title or any untrusted string before output
echo htmlspecialchars($page_title, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');

Explanation: Even when you sanitize body HTML, other text fields (titles, summaries, metadata) should be escaped on output. Use character-encoding-aware escaping functions (htmlspecialchars in PHP) to prevent reflected XSS in those contexts.

4) Content Security Policy (CSP) example

// Example header to restrict scripts and disallow inline execution
header("Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none'; frame-ancestors 'none';");

Explanation: CSP reduces the impact of injected scripts by restricting where scripts can load from and by disallowing inline scripts when configured properly (e.g., avoid using 'unsafe-inline'). Use nonces or hashes if you must allow some inline scripts. CSP is a defense-in-depth measure and not a replacement for input/output handling.

Data cleanup: removing or neutralizing malicious stored pages

  • Export suspected pages and run them through a sanitizer before re-importing.
  • For immediate cleanup, remove any pages identified as malicious and restore from a clean backup if available.
  • Log and archive the original content for forensic analysis if you are investigating an incident.

Operational and account hygiene

  • Force a password reset and session invalidation for administrative users if an exploit may have executed.
  • Rotate API keys and credentials that may have been exposed.
  • Enable multi-factor authentication (MFA) for administrative accounts.
  • Limit the number of users with high privileges and review permissions regularly.

Testing and verification

  • Use automated security scanners (SAST/DAST) to validate that inputs are sanitized and outputs are encoded.
  • Manually review rendered pages after fixes to confirm scripts no longer execute.
  • Include regression tests that verify malicious input is neutralized before merging changes.

Example remediation checklist

Task Priority Notes
Restrict page creation to trusted users Immediate Reduces attack surface while patching
Enable safe Markdown rendering or sanitize inputs High Prefer HTMLPurifier or equivalent
Deploy CSP and secure cookies High Defense-in-depth
Scan and clean existing content High Quarantine and investigate suspicious pages
Update Anchor CMS to patched version High Follow vendor advisories and GitHub releases

Responsible disclosure and resources

If you discover vulnerable instances of Anchor CMS in production, coordinate with your security team to apply mitigations and report the problem to the site owner or administrator. Check the Anchor CMS project on GitHub and the vendor's site for official patches and release notes. Reference: Anchor CMS on GitHub (https://github.com/anchorcms/anchor-cms) and CVE-2025-46041 for tracking.

Final notes

Stored XSS remains one of the most damaging and common web application vulnerabilities. Mitigating it effectively requires a combination of input sanitization, safe rendering practices, output encoding, least-privilege permissions, and runtime restrictions such as CSP. Apply the short-term mitigations immediately and implement the secure coding practices described here to reduce future risk.