CVE-2026-31859

CVE-2026-31859 is a medium-severity cross-site scripting (XSS) vulnerability in craftcms/cms (composer), affecting versions >= 4.15.3, <= 4.17.2. It is fixed in 4.17.3, 5.9.7.

Does this CVE actually affect you?

Kodem shows which CVEs are reachable and running in your applications, so you fix what's exploitable, not just what's listed.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Runtime intelligence, not another scanner.

Summary

CraftCMS vulnerable to reflective XSS via incomplete return URL sanitization

The fix for CVE-2025-35939 in craftcms/cms introduced a strip_tags() call in src/web/User.php to sanitize return URLs before they are stored in the session. However, strip_tags() 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 strip_tags() completely unmodified, enabling reflected XSS when the return URL is rendered in an href attribute.

Details

The patched code in is:

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

strip_tags() 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 strip_tags() completely unmodified:

  1. javascript: protocol URLs -- javascript:alert(document.cookie) contains no HTML tags, so strip_tags() 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 strip_tags() 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 strip_tags() 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. strip_tags() 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

Untrusted input is rendered as active markup in a victim's browser, which can run script in their session. Typical impact: session or credential theft, and actions taken as the user.

Affected versions

craftcms/cms (>= 4.15.3, <= 4.17.2) craftcms/cms (>= 5.7.5, <= 5.9.6)

Security releases

craftcms/cms → 4.17.3 (composer) craftcms/cms → 5.9.7 (composer)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

Already deployed Kodem?

See it in your environmentNew to Kodem? Get a demo →

Remediation advice

Upgrade the following packages to resolve this vulnerability:

craftcms/cms to 4.17.3 or later; craftcms/cms to 5.9.7 or later

Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.

Frequently Asked Questions

  1. What is CVE-2026-31859? CVE-2026-31859 is a medium-severity cross-site scripting (XSS) vulnerability in craftcms/cms (composer), affecting versions >= 4.15.3, <= 4.17.2. It is fixed in 4.17.3, 5.9.7. Untrusted input is rendered as active markup in a victim's browser, which can run script in their session.
  2. Which versions of craftcms/cms are affected by CVE-2026-31859? craftcms/cms (composer) versions >= 4.15.3, <= 4.17.2 is affected.
  3. Is there a fix for CVE-2026-31859? Yes. CVE-2026-31859 is fixed in 4.17.3, 5.9.7. Upgrade to this version or later.
  4. Is CVE-2026-31859 exploitable, and should I be worried? Whether CVE-2026-31859 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  5. What actually determines whether CVE-2026-31859 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  6. How do I fix CVE-2026-31859?
    • Upgrade craftcms/cms to 4.17.3 or later
    • Upgrade craftcms/cms to 5.9.7 or later

Other vulnerabilities in craftcms/cms

Stop the waste.
Protect your environment with Kodem.