CE Phoenix Version 1.0.8.20 - Stored XSS

Exploit Author: tmrswrr Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2024-05-13
# Exploit Title: CE Phoenix Version 1.0.8.20  - Stored XSS
# Date: 2023-11-25
# Exploit Author: tmrswrr
# Category : Webapps
# Vendor Homepage: https://phoenixcart.org/
# Version: v3.0.1
# Tested on: https://www.softaculous.com/apps/ecommerce/CE_Phoenix

## POC:

1-Login admin panel , go to this url : https://demos6.softaculous.com/CE_Phoenixx3r6jqi4kl/admin/currencies.php
2-Click edit and write in Title field your payload : <sVg/onLy=1 onLoaD=confirm(1)//
3-Save it and go to this url : https://demos6.softaculous.com/CE_Phoenixx3r6jqi4kl/admin/currencies.php
4-You will be see alert button


CE Phoenix Stored Cross-Site Scripting (XSS) — Technical Overview and Mitigation

Stored XSS in web applications like CE Phoenix arises when untrusted input is saved to the server (database, file, etc.) and later rendered into a page without proper output encoding. An attacker can inject script or markup that executes in the context of other users (often administrators or customers), leading to session theft, account takeover, or administrative control depending on the target.

Summary

Item Details
Application CE Phoenix (e-commerce platform)
Issue Stored Cross-Site Scripting (XSS) in administrative input fields
Impact Execution of attacker-controlled scripts in admin or user browsers
Primary cause Insufficient output encoding when rendering stored values
Recommended actions Patch/upgrade, implement proper encoding, use CSP, validate and sanitize input

Root Cause Analysis

Stored XSS typically occurs when an application accepts HTML-containing input and later injects that input into an HTML document without escaping or sanitizing. In admin-facing pages (for example, editable metadata such as titles, names, or descriptions), unescaped stored values can be rendered inside element content or attributes, allowing execution in the browser of any injected script.

Why this is dangerous in admin panels

  • Admin sessions often have elevated privileges — exploiting an XSS in an admin context can allow full site compromise.
  • Stored XSS persists across requests and can affect multiple users.
  • Automated attacks and chained exploits are possible (e.g., inject script that exfiltrates cookies or triggers backend actions through the admin UI).

Detection and Testing (Non-actionable guidance)

  • Use automated scanners and manual code review to identify unescaped output points that reflect stored fields in admin pages.
  • Inspect templates and server-side code paths that output database-backed fields into HTML without using a safe-encoding function.
  • When testing, prefer benign payload markers that do not perform harmful actions (e.g., unique ASCII markers) instead of active JavaScript execution. The goal is to observe where unescaped characters appear, not to run attacker code.

Secure Development Practices (Fixes and mitigations)

Mitigation is twofold: prevent dangerous input from being saved where possible and ensure all output is encoded correctly for the target context when rendering.

1) Output encoding

Always escape untrusted data at the point of output according to the HTML context:

  • HTML element content: use HTML entities (e.g., & < > " ').
  • Attribute values: use HTML attribute-encoding and quote attributes.
  • JavaScript context: avoid inserting untrusted input into JS; if unavoidable, use JSON encoding routines to safely embed values.
<?php
// Safe output for HTML element content:
echo htmlspecialchars($title, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
// When rendering into attribute:
echo '<input type="text" value="' . htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '">';
?>

Explanation: htmlspecialchars converts special characters (<, >, &, quotes) to HTML entities. ENT_QUOTES ensures both single and double quotes are encoded, preventing injection into attributes. ENT_SUBSTITUTE avoids invalid byte sequences causing output issues.

2) Use a trusted HTML sanitizer if rich text is required

If user input must contain HTML (e.g., rich descriptions), use a well-maintained sanitizer library that whitelists safe tags/attributes and removes scripts, event handlers, and dangerous URL schemes.

// Example: using HTML Purifier (PHP) via Composer
// Installation: composer require ezyang/htmlpurifier
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.SafeIframe', true);
$config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/|player\.vimeo\.com/)%');
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($user_html);

Explanation: HTML Purifier removes malicious markup while allowing a controlled subset of safe HTML. Configure allowed sources carefully and avoid allowing inline event handlers (onload, onclick, etc.).

3) Input validation and whitelisting

Validate incoming data on intent and length. For fields intended to be plain text (titles, currency names, identifiers), enforce character sets (e.g., allow only letters, numbers, common punctuation) or strip HTML before storage.

// Example: strip tags for a field that must be plain text
$clean_title = strip_tags($_POST['title']);
$clean_title = trim($clean_title);
$clean_title = mb_substr($clean_title, 0, 100); // enforce maximum length

Explanation: strip_tags removes HTML elements. Combining trimming and length checks reduces attack surface. However, strip_tags is not a replacement for output encoding — always encode at render time.

4) Content Security Policy (CSP)

Deploy a strong CSP to reduce the impact of XSS by restricting script sources and disallowing inline scripts where feasible. Note: CSP is a mitigation, not a replacement for correct escaping.

// Example HTTP header set in PHP
header("Content-Security-Policy: default-src 'self'; script-src 'self' https://trusted-cdn.example.com; object-src 'none'; base-uri 'self';");

Explanation: This header restricts scripts to the same origin and a trusted CDN. It also disables plugins (object-src 'none') and restricts base URI. A nonce-based CSP can allow specific inline scripts safely, but requires server-side nonce management.

5) Least privilege and session protections

  • Limit admin interface access by IP/2FA where possible.
  • Set cookies with HttpOnly and Secure flags to make cookie stealing via XSS harder:
// PHP example: set cookie with secure flags
setcookie('PHPSESSID', $sessionId, [
  'expires' => 0,
  'path' => '/',
  'domain' => 'example.com',
  'secure' => true,
  'httponly' => true,
  'samesite' => 'Strict'
]);

Explanation: HttpOnly prevents JS from accessing cookies. Secure ensures cookies are sent only over HTTPS. SameSite reduces CSRF risk.

Application Hardening and Admin Guidance

  • Patch and update CE Phoenix to the latest stable release — vendors often release fixes after disclosure.
  • Audit database fields that contain user-editable text (titles, names, descriptions) and ensure output encoding in templates.
  • Review custom or third-party plugins/extensions that may bypass platform sanitization routines.
  • Forensic review: examine recent changes to records and admin logs if exploitation is suspected.
  • Educate admins to avoid clicking unexpected links within the admin UI and to use limited-privilege accounts for day-to-day tasks.

Mitigation Checklist for Developers and Administrators

  • Apply official vendor updates and security patches.
  • Encode output consistently using context-aware escaping (HTML, attribute, JS, URL).
  • Sanitize allowed HTML with a robust library when rich text is required.
  • Implement CSP and secure cookie settings.
  • Limit admin access and enforce multi-factor authentication.
  • Audit templates and third-party code that render stored data.

Conclusion

Stored XSS is a high-risk web vulnerability, especially when it affects administrative interfaces. The safest approach is defense-in-depth: sanitize and validate input, escape all untrusted data at output, deploy CSP and secure cookie settings, and keep the CE Phoenix installation up-to-date. Combined, these measures greatly reduce the likelihood and impact of XSS attacks.