CVE-2026-54298: Astro Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-jrpj-wcv7-9fh9
CVSS 4.2
CWE-79
Published
Advisory Summary

CVE-2026-54298 is a MODERATE (CVSS 4.2) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Astro libraries in the npm ecosystem. The issue involves xss via unescaped attribute names in spread props. Remediation is available by upgrading affected packages to version 6.4.6.

CVE-2026-54298 at a Glance

CVE Identifier CVE-2026-54298
GHSA Identifier GHSA-jrpj-wcv7-9fh9
Severity MODERATE
CVSS v3.1 Base Score 4.2
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Astro
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 4.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2026-54298

To remediate this vulnerability, upgrade all affected Astro dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

astro fixed: 6.4.6
npm install astro@6.4.6
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls astro

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-54298, inspect your project dependencies using npm:

npm ls astro

Analyze the terminal output to locate any version of Astro in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.4.6), your application is affected.

Note: The npm ls astro command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Astro, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary The `spreadAttributes` function in Astro's server-side rendering pipeline iterates over object keys and passes them directly to `addAttribute`, which interpolates the key into the HTML output without escaping. When a developer uses the spread syntax `{...props}` on an HTML element and the object keys come from an untrusted source (API, CMS, URL parameters), an attacker can inject arbitrary HTML attributes including event handlers like `onmousemove`, `onclick`, or break out of the attribute context entirely to inject new elements. ## Details The vulnerable function is [`addAttribute`](https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/server/render/util.ts#L81-L141) at `packages/astro/src/runtime/server/render/util.ts:81-141`: ```javascript export function addAttribute(value: any, key: string, shouldEscape = true, tagName = '') { if (value == null) { return ''; } return markHTMLString(` ${key}="${toAttributeString(value, shouldEscape)}"`); // key interpolated not escaped } ``` This function is called from [`spreadAttributes`](https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/server/index.ts#L91-L92) at `packages/astro/src/runtime/server/index.ts:91-92`: ```javascript for (const [key, value] of Object.entries(values)) { output += addAttribute(value, key, true, _name); } ``` The `toAttributeString` function escapes the attribute value, but the attribute name `key` is never validated or escaped. An attacker can craft a JSON object with a key containing " characters to break out of the attribute context and inject event handlers. Execution flow: User controlled object keys (from API, CMS, URL params) are spread onto element via `{...props}`. The compiler generates `spreadAttributes(props)` which iterates with `Object.entries()` and calls `addAttribute(value, key)`. The key is interpolated as `` ` ${key}="${escapedValue}"` ``. A malicious key breaks attribute context, resulting in XSS. ## POC Create an SSR Astro page (`src/pages/index.astro`): ```astro --- const props = JSON.parse(Astro.url.searchParams.get('props') || '{}'); --- <html> <body> <h1>Hello</h1> <div {...props}>Move mouse here</div> </body> </html> ``` Enable SSR in `astro.config.mjs` (for URL based demo): ```javascript export default defineConfig({ output: 'server' }); ``` Note: SSR is not required for the vulnerability to exist. In static builds (default), the attack vector is compromised data sources at build time (API, CMS, database). SSR simply makes the PoC easier to demonstrate via URL parameters. Start the dev server and visit: ``` http://localhost:4321/?props={"x\" onmousemove=\"alert(document.cookie)\" y":""} ``` URL encoded: ``` http://localhost:4321/?props=%7B%22x%5C%22%20onmousemove%3D%5C%22alert(document.cookie)%5C%22%20y%22%3A%22%22%7D ``` View the HTML source. The output contains: ```html <div x" onmousemove="alert(document.cookie)" y="">Move mouse here</div> ``` The key `x" onmousemove="alert(document.cookie)" y` breaks out of the attribute context. Moving the mouse over the div executes the JavaScript. <img width="1919" height="992" alt="Captura de tela 2026-06-02 005906" src="https://github.com/user-attachments/assets/ef69c12e-7edf-472e-97d1-3dfa540e61b4" /> ## Impact An attacker can execute arbitrary JavaScript in the context of a victim's browser session on any Astro application that spreads object props from untrusted sources onto HTML elements. This is a common pattern when integrating with external APIs or CMS systems. Exploitation enables session hijacking via cookie theft, credential theft by injecting fake login forms or keyloggers, defacement of the rendered page, and redirection to attacker controlled domains. The vulnerability affects all Astro versions that support spread syntax on HTML elements and is exploitable in SSR, SSG (if build time data is compromised), and hybrid deployments.

CVE-2026-54298 Affected Astro Versions

1 component(s)
Fixed Versions:
6.4.6
Product / Package Ecosystem Affected Versions Fixed Version
astro
npm
< 6.4.6
6.4.6

References

Frequently Asked Questions

What is CVE-2026-54298?
CVE-2026-54298 is a security vulnerability in Astro involving XSS via Unescaped Attribute Names in Spread Props under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Astro versions are affected?
Affected versions include releases prior to 6.4.6 across affected packages: astro.
What version fixes CVE-2026-54298?
Upgrading to 6.4.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is astro affected?
Yes, astro is affected in releases prior to 6.4.6. Upgrade your dependency to 6.4.6 or later.
What is the CVSS score of CVE-2026-54298?
CVE-2026-54298 has a CVSS v3.1 base score of 4.2 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2026-54298?
CVE-2026-54298 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check npm dependencies for CVE-2026-54298?
Run the dependency tree command: 'npm ls astro'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-jrpj-wcv7-9fh9",
  "modified" : "2026-07-18T17:25:04Z",
  "published" : "2026-06-16T14:57:21Z",
  "aliases" : [ "CVE-2026-54298" ],
  "summary" : "Astro: XSS via Unescaped Attribute Names in Spread Props",
  "details" : "## Summary\n\nThe `spreadAttributes` function in Astro's server-side rendering pipeline iterates over object keys and passes them directly to `addAttribute`, which interpolates the key into the HTML output without escaping. When a developer uses the spread syntax `{...props}` on an HTML element and the object keys come from an untrusted source (API, CMS, URL parameters), an attacker can inject arbitrary HTML attributes including event handlers like `onmousemove`, `onclick`, or break out of the attribute context entirely to inject new elements.\n\n## Details\n\nThe vulnerable function is [`addAttribute`](https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/server/render/util.ts#L81-L141) at `packages/astro/src/runtime/server/render/util.ts:81-141`:\n\n```javascript\nexport function addAttribute(value: any, key: string, shouldEscape = true, tagName = '') {\n    if (value == null) {\n        return '';\n    }\n    \n    return markHTMLString(` ${key}=\"${toAttributeString(value, shouldEscape)}\"`); //  key interpolated not escaped\n}\n```\n\nThis function is called from [`spreadAttributes`](https://github.com/withastro/astro/blob/main/packages/astro/src/runtime/server/index.ts#L91-L92) at `packages/astro/src/runtime/server/index.ts:91-92`:\n\n```javascript\nfor (const [key, value] of Object.entries(values)) {\n    output += addAttribute(value, key, true, _name);\n}\n```\n\nThe `toAttributeString` function escapes the attribute value, but the attribute name `key` is never validated or escaped. An attacker can craft a JSON object with a key containing \" characters to break out of the attribute context and inject event handlers.\n\nExecution flow: User controlled object keys (from API, CMS, URL params) are spread onto element via `{...props}`. The compiler generates `spreadAttributes(props)` which iterates with `Object.entries()` and calls `addAttribute(value, key)`. The key is interpolated as `` ` ${key}=\"${escapedValue}\"` ``. A malicious key breaks attribute context, resulting in XSS.\n\n## POC\n\nCreate an SSR Astro page (`src/pages/index.astro`):\n\n```astro\n---\nconst props = JSON.parse(Astro.url.searchParams.get('props') || '{}');\n---\n<html>\n<body>\n  <h1>Hello</h1>\n  <div {...props}>Move mouse here</div>\n</body>\n</html>\n```\nEnable SSR in `astro.config.mjs` (for URL based demo):\n\n```javascript\nexport default defineConfig({\n  output: 'server'\n});\n```\n\nNote: SSR is not required for the vulnerability to exist. In static builds (default), the attack vector is compromised data sources at build time (API, CMS, database). SSR simply makes the PoC easier to demonstrate via URL parameters.\n\nStart the dev server and visit:\n\n```\nhttp://localhost:4321/?props={\"x\\\" onmousemove=\\\"alert(document.cookie)\\\" y\":\"\"}\n```\n\nURL encoded:\n\n```\nhttp://localhost:4321/?props=%7B%22x%5C%22%20onmousemove%3D%5C%22alert(document.cookie)%5C%22%20y%22%3A%22%22%7D\n```\n\nView the HTML source. The output contains:\n\n```html\n<div x\" onmousemove=\"alert(document.cookie)\" y=\"\">Move mouse here</div>\n```\n\nThe key `x\" onmousemove=\"alert(document.cookie)\" y` breaks out of the attribute context. Moving the mouse over the div executes the JavaScript.\n\n<img width=\"1919\" height=\"992\" alt=\"Captura de tela 2026-06-02 005906\" src=\"https://github.com/user-attachments/assets/ef69c12e-7edf-472e-97d1-3dfa540e61b4\" />\n\n## Impact\n\nAn attacker can execute arbitrary JavaScript in the context of a victim's browser session on any Astro application that spreads object props from untrusted sources onto HTML elements. This is a common pattern when integrating with external APIs or CMS systems. Exploitation enables session hijacking via cookie theft, credential theft by injecting fake login forms or keyloggers, defacement of the rendered page, and redirection to attacker controlled domains.\n\nThe vulnerability affects all Astro versions that support spread syntax on HTML elements and is exploitable in SSR, SSG (if build time data is compromised), and hybrid deployments.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "astro"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "6.4.6"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/withastro/astro/security/advisories/GHSA-jrpj-wcv7-9fh9"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-54298"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/withastro/astro"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-16T14:57:21Z",
    "nvd_published_at" : "2026-06-22T19:17:21Z"
  }
}