{"id":"CVE-2026-31859","aliases":["CVE-2026-31859","GHSA-fvwq-45qv-xvhv"],"related":[],"kind":"vulnerability","state":"published","title":"Craft has Reflective XSS via incomplete return URL sanitization","summary":"Craft is a content management system (CMS). 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. This vulnerability is fixed in  5.9.7 and 4.17.3.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Craft is a content management system (CMS). 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. This vulnerability is fixed in  5.9.7 and 4.17.3.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nThe 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.\n\n### Details\nThe patched code in is:\n\n```php\npublic function setReturnUrl($url): void\n{\n    parent::setReturnUrl(strip_tags($url));\n}\n```\n\n`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:\n\n1. **`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.\n\n2. **`data:` URIs** -- `data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==` uses Base64 encoding and contains no tags at all, bypassing `strip_tags()` entirely.\n\n3. **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.\n\nThe 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.\n\n### Impact\n\n**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:\n\n1. Victim clicks the link, visiting the Craft CMS site.\n2. The application calls `setReturnUrl()` with the attacker-controlled value.\n3. `strip_tags()` processes the URL but finds no HTML tags -- it passes through unchanged.\n4. The URL is stored in the session and later rendered in an `href` attribute (e.g., a \"Return\" or \"Continue\" link).\n5. When the victim clicks that link, `javascript:alert(document.cookie)` executes in the context of the Craft CMS origin.\n\nThis enables:\n- **Session hijacking** via cookie theft (`document.cookie`)\n- **Data exfiltration** via `fetch()` to an attacker-controlled server\n- **Phishing** by redirecting to a lookalike domain (protocol-relative URL)\n- **CSRF** by performing actions on behalf of the authenticated user","format":"markdown","source":"ghsa"},{"lang":"es","text":"Craft es un sistema de gestión de contenidos (CMS). La corrección para CVE-2025-35939 en craftcms/cms introdujo una llamada a strip_tags() en src/web/User.php para depurar las URL de retorno antes de que se almacenen en la sesión. Sin embargo, strip_tags() solo elimina las etiquetas HTML (corchetes angulares); no inspecciona ni filtra los esquemas de URL. Las cargas útiles como javascript:alert(document.cookie) no contienen etiquetas HTML y pasan por strip_tags() sin sufrir ninguna modificación, lo que permite un XSS reflejado cuando la URL de retorno se representa en un atributo href. Esta vulnerabilidad se ha corregido en las versiones 5.9.7 y 4.17.3.","source":"nvd"}],"published":"2026-03-11T00:26:13.000Z","modified":"2026-06-17T10:34:38.860Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","score":6.9,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","score":6.9,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"}],"cwes":["CWE-79","CWE-116"],"affected":[{"ranges":[{"version":">= 4.15.3, < 4.17.3","status":"affected"},{"version":">= 5.7.5, < 5.9.7","status":"affected"}],"vendor":"craftcms","product":"cms","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"4.15.3","status":"affected","fixed":"4.17.3"}],"ecosystem":"Packagist","package":"craftcms/cms","purl":"pkg:composer/craftcms/cms","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"5.7.5","status":"affected","fixed":"5.9.7"}],"ecosystem":"Packagist","package":"craftcms/cms","purl":"pkg:composer/craftcms/cms","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"4.15.3","fixed":"4.17.3"},{"status":"affected","introduced":"5.7.5","fixed":"5.9.7"}],"vendor":"craftcms","product":"craft_cms","cpe":"cpe:2.3:a:craftcms:craft_cms:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/craftcms/cms/security/advisories/GHSA-fvwq-45qv-xvhv","tags":["patch","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-31859","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/craftcms/cms/commit/cc9921c14897ee2b592a431c2356af8a04ce4cfe","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/craftcms/cms","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"yes","technicalImpact":"partial","date":"2026-03-12T14:00:11.429Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-31859","url":"https://www.cve.org/CVERecord?id=CVE-2026-31859","licence":"CVE Terms of Use","modified":"2026-03-12T14:00:23.631Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-fvwq-45qv-xvhv","url":"https://github.com/advisories/GHSA-fvwq-45qv-xvhv","licence":"CC-BY-4.0","modified":"2026-03-13T10:56:24.729Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-31859","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-31859","licence":"Public domain","modified":"2026-06-17T10:34:38.860Z"}],"updatedAt":"2026-11-25T22:59:15.758Z","epss":{"score":0.00216,"percentile":0.12747,"date":"2026-12-01T12:00:22.000Z"}}