Skip to main content

Astro CVE-2026-41067

MEDIUM
Cross-site Scripting (XSS) (CWE-79)
2026-04-21 https://github.com/withastro/astro GHSA-j687-52p2-xcff
6.1
CVSS 3.1 · Vendor: https://github.com/withastro/astro
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Recon
    Craft URL with </Script> case-bypass payload
  2. Delivery
    Deliver crafted URL to victim via phishing
  3. Exploit
    Victim loads URL in browser
  4. Install
    SSR page reflects input through defineScriptVars
  5. C2
    Case-sensitive regex fails to sanitize payload
  6. Execute
    Browser closes script block early on </Script>
  7. Impact
    Injected HTML executes attacker JavaScript in victim session

Vulnerability Assessment

Weakness
CWE
OWASP Top 10:2025
A05:2025 - Injection
ASVS 5.0
V1 - Encoding and Sanitization Output encoding, context-aware escaping
MITRE ATT&CK

2 techniques across 2 tactics: Initial Access, Execution

The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up.

Exploitation Conditions

Three conditions must be simultaneously met: (1) The Astro application must be configured with output: 'server' in astro.config.mjs - static builds do not execute defineScriptVars server-side and are not exploitable; (2) at least one page must use the define:vars directive on a <script> tag and pass user-controlled input as a variable value - input sources include Astro.url.searchParams.get(...), request headers, or cookie values; pages that only pass server-side constants to define:vars are not exploitable; (3) a victim user must be induced to load the attacker's crafted URL in their browser, as this is a reflected (not stored) XSS - no server-side persistence is required. The attacker requires no authentication (PR:N per CVSS vector). Exploitation is not automatable at scale per SSVC because each successful attack requires individual victim interaction.

Impact

The official CVSS 3.1 score of 6.1 (AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N) accurately characterizes this as a network-reachable, low-complexity reflected XSS requiring victim interaction. SSVC reinforces this profile: exploitation status is PoC (not active), automatable is no (victim must load a crafted URL), and technical impact is partial. EPSS of 0.03% at the 8th percentile is consistent with the UI:R constraint limiting automated mass exploitation. Despite the low EPSS, the attack surface is wider than a niche misconfiguration: passing URL parameters to define:vars is a documented and expected Astro SSR pattern, so a meaningful fraction of SSR Astro applications are realistically exploitable. No KEV listing means active in-the-wild exploitation is not confirmed by CISA; the PoC is detailed and trivially reproducible, so the threat is real but targeted rather than automated. The CVSS S:C scope change is correctly assigned - successful exploitation achieves script execution in the victim's browser origin, enabling cookie theft and credential harvesting beyond the Astro server itself.

Exploit ScenarioDerived

An attacker crafts a URL such as https://victim.example/?name=%3C/Script%3E%3Cimg/src=x%20onerror=alert(document.cookie)%3E and delivers it to a victim via phishing or a malicious link. When the victim loads the URL, the SSR Astro page reflects the name parameter through defineScriptVars into an inline script block; the regex fails to sanitize </Script>, causing the browser to close the script element early and parse the injected <img onerror=...> tag, executing arbitrary JavaScript including exfiltration of session cookies. A detailed proof-of-concept reproducing exactly this scenario is publicly available in GHSA-j687-52p2-xcff, with multiple confirmed bypass payloads.

This Month Plan within 30 days. Why: MEDIUM severity (CVSS 4.0-6.9).
Patch available 0.0% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv1 – Jul 24, 2026

Reflected XSS in Astro's SSR pipeline allows unauthenticated remote attackers to inject and execute arbitrary JavaScript in victims' browsers by bypassing the incomplete </script> tag sanitization in the defineScriptVars function. All Astro versions prior to 6.1.6 running in SSR mode are affected when user-controlled input reaches a define:vars script block - a documented and common usage pattern. A detailed public proof-of-concept is available via GHSA-j687-52p2-xcff; EPSS is low (0.03%, 8th percentile) consistent with the required victim interaction, and no CISA KEV listing indicates no confirmed mass exploitation at time of analysis.

RemediationAI

Upgrade the Astro npm package to version 6.1.6 or later, which corrects the sanitization logic via commit b06eabf to properly handle all closing script tag variants. See the release notes at https://github.com/withastro/astro/releases/tag/astro@6.1.6 and the full security advisory at https://github.com/withastro/astro/security/advisories/GHSA-j687-52p2-xcff. If an immediate upgrade is not possible, the most effective compensating control is to avoid passing any request-derived data (from Astro.url.searchParams, Astro.request.headers, or Astro.cookies) directly to define:vars on <script> tags without prior allowlist validation - this eliminates the attack surface without requiring a framework change, though it requires auditing all SSR pages. A WAF rule blocking case-insensitive </script patterns in query parameters is a lower-fidelity option that may produce false positives for legitimate URL content. There is no known availability impact from upgrading; the fix is a sanitization-only change.

Affected Packages

npm astro fix: 6.1.6

Source: OSV (Open Source Vulnerabilities)

Affects your stack

Affects 1 package in npm

Checking this CVE against your own stacks and servers is part of the Basic plan and up.

Technical ContextAI · show details

Astro is a JavaScript web framework distributed as the astro npm package (pkg:npm/astro) for building server-rendered and static websites. In SSR mode, the defineScriptVars function at packages/astro/src/runtime/server/render/util.ts:42-53 serializes server-side variables into inline <script> blocks by calling JSON.stringify() and then applying a regex substitution. The root cause is CWE-79 (Improper Neutralization of Input During Web Page Generation): the sanitization regex /</script>/g lacks the i flag and does not account for the full HTML tokenizer behavior specified in HTML §13.2.6.4, which closes script elements on case-insensitive tag names (</Script>, </SCRIPT>), tag names followed by whitespace (</script >), and self-closing slash forms (</script/>). Because JSON.stringify() does not escape <, >, or / characters, all three bypass classes pass through serialization and into the HTML response unmodified, where the browser's HTML parser closes the script element early and processes attacker-supplied markup.

Know when the next one hits your stack

  • Watch products and get an email when something new is published
  • Check this CVE against your own stack and servers
  • Exploit and PoC references, threat intelligence from 22 sources

No credit card · 7-day full trial

Severity by source

Vendor (https://github.com/withastro/astro) PRIMARY 6.1 MEDIUM
AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
vuln.today AI 6.1 MEDIUM

Network-accessible reflected XSS needing no auth (PR:N) but requiring victim to load a crafted URL (UI:R); scope changes to browser context (S:C) with limited C/I impact and no availability impact.

3.1 AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
4.0 AV:N/AC:L/AT:P/PR:N/UI:P/VC:L/VI:L/VA:N/SC:L/SI:L/SA:N

Primary rating from Vendor (https://github.com/withastro/astro).

CVSS VectorVendor: https://github.com/withastro/astro

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
Required
Scope
Changed
Confidentiality
Low
Integrity
Low
Availability
None

Lifecycle Timeline

2
Patch released
Apr 22, 2026 - 02:30 nvd
Patch available
CVE Published
Apr 21, 2026 - 20:39 nvd
MEDIUM 6.1

DescriptionCVE.org

Summary

The defineScriptVars function in Astro's server-side rendering pipeline uses a case-sensitive regex /<\/script>/g to sanitize values injected into inline <script> tags via the define:vars directive. HTML parsers close <script> elements case-insensitively and also accept whitespace or / before the closing >, allowing an attacker to bypass the sanitization with payloads like </Script>, </script >, or </script/> and inject arbitrary HTML/JavaScript.

Details

The vulnerable function is defineScriptVars at packages/astro/src/runtime/server/render/util.ts:42-53:

typescript
export function defineScriptVars(vars: Record<any, any>) {
	let output = '';
	for (const [key, value] of Object.entries(vars)) {
		output += `const ${toIdent(key)} = ${JSON.stringify(value)?.replace(
			/<\/script>/g,       // ← Case-sensitive, exact match only
			'\\x3C/script>',
		)};\n`;
	}
	return markHTMLString(output);
}

This function is called from renderElement at util.ts:172-174 when a <script> element has define:vars:

typescript
if (name === 'script') {
	delete props.hoist;
	children = defineScriptVars(defineVars) + '\n' + children;
}

The regex /<\/script>/g fails to match three classes of closing script tags that HTML parsers accept per the HTML specification §13.2.6.4:

  1. Case variations: </Script>, </SCRIPT>, </sCrIpT> - HTML tag names are case-insensitive but the regex has no i flag.
  2. Whitespace before >: </script >, </script\t>, </script\n> - after the tag name, the HTML tokenizer enters the "before attribute name" state on ASCII whitespace.
  3. Self-closing slash: </script/> - the tokenizer enters "self-closing start tag" state on /.

JSON.stringify() does not escape <, >, or / characters, so all these payloads pass through serialization unchanged.

Execution flow: User-controlled input (e.g., Astro.url.searchParams) → assigned to a variable → passed via define:vars on a <script> tag → renderElement → defineScriptVars → incomplete sanitization → injected into <script> block in HTML response → browser closes the script element early → attacker-controlled HTML parsed and executed.

PoC

Step 1: Create an SSR Astro page (src/pages/index.astro):

astro
---
const name = Astro.url.searchParams.get('name') || 'World';
---
<html>
<body>
  <h1>Hello</h1>
  <script define:vars={{ name }}>
    console.log(name);
  </script>
</body>
</html>

Step 2: Ensure SSR is enabled in astro.config.mjs:

js
export default defineConfig({
  output: 'server'
});

Step 3: Start the dev server and visit:

http://localhost:4321/?name=</Script><img/src=x%20onerror=alert(document.cookie)>

Step 4: View the HTML source. The output contains:

html
<script>const name = "</Script><img/src=x onerror=alert(document.cookie)>";
  console.log(name);
</script>

The browser's HTML parser matches </Script> case-insensitively, closing the script block. The <img onerror=alert(document.cookie)> is then parsed as HTML and the JavaScript in onerror executes.

Alternative bypass payloads:

/?name=</script ><img/src=x onerror=alert(1)>
/?name=</script/><img/src=x onerror=alert(1)>
/?name=</SCRIPT><img/src=x onerror=alert(1)>

Impact

An attacker can execute arbitrary JavaScript in the context of a victim's browser session on any SSR Astro application that passes request-derived data to define:vars on a <script> tag. This is a documented and expected usage pattern in Astro.

Exploitation enables:

  • Session hijacking via cookie theft (document.cookie)
  • Credential theft by injecting fake login forms or keyloggers
  • Defacement of the rendered page
  • Redirection to attacker-controlled domains

The vulnerability affects all Astro versions that support define:vars and is exploitable in any SSR deployment where user input reaches a define:vars script variable.

Recommended Fix

Replace the case-sensitive exact-match regex with a comprehensive escape that covers all HTML parser edge cases. The simplest correct fix is to escape all < characters in the JSON output:

typescript
export function defineScriptVars(vars: Record<any, any>) {
	let output = '';
	for (const [key, value] of Object.entries(vars)) {
		output += `const ${toIdent(key)} = ${JSON.stringify(value)?.replace(
			/</g,
			'\\u003c',
		)};\n`;
	}
	return markHTMLString(output);
}

This is the standard approach used by frameworks like Next.js and Rails. Replacing every < with \u003c is safe inside JSON string contexts (JavaScript treats \u003c as < at runtime) and eliminates all possible </script> variants including case variations, whitespace, and self-closing forms.

Threat Intelligence Overview

EPSS Score
0.0%
Top 92% exploitable
Prevalence
Medium
popular JavaScript SSR framework, growing but not ubiquitous enterprise adoption
Threat Intel
1
1 source
Data Quality
5 sources
Confidence: Medium
NVD CVE.org EPSS Vulnrichment GHSA GitHub

How this decision was reached

The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.

SignalValue
Severity MEDIUM
CISA KEV No
Public POC No
EPSS 0.0%
Patch available Yes
Active threat No
Deciding rule
MEDIUM severity (CVSS 4.0-6.9)
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

SSVC Decision· derived
Scheduled
Exploitation
Poc
System Exposure· derived
Open
Automatable
No
Human Impact· derived
Medium
Technical Impact
Partial

Priority Score

30
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +30
PoC: 0
Weaponized: 0
Threat intel: 0
Gov advisory: 0

Attack Technique

Cross-Site Scripting occurs when an application accepts untrusted data and sends it to a web browser without proper validation or encoding.

Affected Products (CPE)CVE.org

pkg:npm/astro

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy