CVE-2026-31859: Craft has Reflective XSS via incomplete return URL sanitization

Published Mar 11, 2026
·
Updated

Summary

The fix for CVE-2025-35939 in craftcms/cms introduced a striptags() call in src/web/User.php to sanitize return URLs before they are stored in the session. However, striptags() only removes HTML tags (angle brackets) -- it does not inspect or filter URL schemes. Payloads like javascript:alert(document.cookie) contain no HTML tags and pass through striptags() completely unmodified, enabling reflected XSS when the return URL is rendered in an href attribute.

Details The patched code in is:

php public function setReturnUrl($url): void { parent::setReturnUrl(striptags($url)); }

striptags() removes HTML tags (e.g., <script>, <img>) from a string, but it is not a URL sanitizer. When the sanitized return URL is subsequently rendered in an href attribute context (e.g., <a href="{{ returnUrl }}">), the following dangerous payloads survive striptags() completely unmodified:

1. javascript: protocol URLs -- javascript:alert(document.cookie) contains no HTML tags, so striptags() returns it verbatim. When placed in an href, clicking the link executes the JavaScript.

2. data: URIs -- data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg== uses Base64 encoding and contains no tags at all, bypassing striptags() entirely.

3. Protocol-relative URLs -- //evil.com/steal contains no tags and is passed through unchanged. When rendered as an href, the browser resolves it relative to the current page’s protocol, redirecting the user to an attacker-controlled domain.

The core issue is that striptags() operates on HTML syntax (angle brackets) while the threat model here requires URL scheme validation. These are fundamentally different security concerns.

Impact

Reflected XSS via crafted return URL. An attacker constructs a malicious link such as https://target.example.com/craft/?returnUrl=javascript:alert(document.cookie) and sends it to a victim. The attack flow is:

1. Victim clicks the link, visiting the Craft CMS site. 2. The application calls setReturnUrl() with the attacker-controlled value. 3. striptags() processes the URL but finds no HTML tags -- it passes through unchanged. 4. The URL is stored in the session and later rendered in an href attribute (e.g., a "Return" or "Continue" link). 5. When the victim clicks that link, javascript:alert(document.cookie) executes in the context of the Craft CMS origin.

This enables: - Session hijacking via cookie theft (document.cookie) - Data exfiltration via fetch() to an attacker-controlled server - Phishing by redirecting to a lookalike domain (protocol-relative URL) - CSRF by performing actions on behalf of the authenticated user

Other sources

Craft is a content management system (CMS). The fix for CVE-2025-35939 in craftcms/cms introduced a striptags() call in src/web/User.php to sanitize return URLs before they are stored in the session. However, striptags() only removes HTML tags (angle brackets) -- it does not inspect or filter URL schemes. Payloads like javascript:alert(document.cookie) contain no HTML tags and pass through striptags() completely unmodified, enabling reflected XSS when the return URL is rendered in an href attribute. This vulnerability is fixed in 5.9.7 and 4.17.3.

MITRE

Affected Software

4 affected componentsFixes available
composer/craftcms/cms>=5.7.5<=5.9.6
5.9.7
composer/craftcms/cms>=4.15.3<=4.17.2
4.17.3
CraftCMS Craft CMS>=4.15.3<4.17.3
CraftCMS Craft CMS>=5.7.5<5.9.7

Event History

Mar 11, 2026
Advisory Published
via GitHub·12:26 AM
Data Sourced
via GitHub·12:26 AM
DescriptionWeaknessAffected Software
CVE Published
via MITRE·05:37 PM
Data Sourced
via MITRE·05:37 PM
DescriptionWeakness
Data Sourced
via NVD·06:16 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·06:16 PM
RemedyAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-31859?

CVE-2026-31859 is categorized as a medium severity vulnerability due to its potential for reflective XSS attacks.

2

How do I fix CVE-2026-31859?

To fix CVE-2026-31859, upgrade to Craft CMS version 5.9.7 or 4.17.3 or later.

3

What types of systems are affected by CVE-2026-31859?

CVE-2026-31859 affects Craft CMS versions between 5.7.5 and 5.9.6 as well as versions between 4.15.3 and 4.17.2.

4

What are the risks associated with CVE-2026-31859?

The risks associated with CVE-2026-31859 include potential reflective XSS exploitation, which can lead to unauthorized access or data manipulation.

5

How does CVE-2026-31859 occur?

CVE-2026-31859 occurs due to incomplete sanitization of return URLs in the Craft CMS session management, exposing the application to XSS attacks.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203