CVE-2026-126361: Astro: XSS via attribute injection in dynamic tag names
Low
- OSV id
- GHSA-mh32-jxcr-mh9f
- Also known as
- CVE-2026-126361
- Published
- Last modified
Affected packages
| Package | Affected versions | Fixed in |
|---|---|---|
| astro npm |
< 7.4.5 | 7.4.5 |
How to fix it
Upgrade astro to 7.4.5 or later.
npm install astro@7.4.5
# if it is an indirect dependency: npm update astro (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
Summary
When a dynamic tag (const Tag = ...; <Tag />) resolves to a string, Astro renders it as a raw HTML element name. The name was filtered to remove characters that could inject attributes, but the filter did not handle /. Because HTML parsers treat / inside a tag as an attribute separator, a tag name such as img/src/onerror=alert(1) was rendered as an <img> element with an onerror attribute. The JSX renderer used for MDX did not filter string tag names at all.
For example:
---
const Tag = Astro.url.searchParams.get('as') ?? 'div';
---
<Tag>hello</Tag>
rendered ?as=img/src/onerror=alert(1) as live HTML.
Impact
Reflected or stored cross-site scripting, but only in applications that use untrusted input (such as a request parameter or an uncontrolled CMS field) as all or part of an element name. Astro itself never derives element names from request data.
Applications that let content choose an element should map that input to a fixed set of known tags. Letting untrusted input choose an element name is unsafe even with a correct filter, because it can still select elements such as script or iframe.
Affected versions
astro <= 7.4.4.
Patches
Fixed in astro 7.4.5. String tag names in .astro dynamic tags, JSX, and MDX now render only the leading valid element name, so characters such as / or = can no longer change the generated markup. Strings that do not start with a valid element name now throw an error.
Workarounds
Upgrade to astro 7.4.5 or later. Before upgrading, do not use untrusted input as an element name, or map it to a fixed set of known tags.
Credits
Reported by @uttej-badwane.
References
- GHSA-mh32-jxcr-mh9f on OSV.dev
- Web: https://github.com/withastro/astro/security/advisories/GHSA-mh32-jxcr-mh9f
- Advisory: https://nvd.nist.gov/vuln/detail/CVE-2026-126361
- Web: https://github.com/withastro/astro/pull/18520
- Web: https://github.com/withastro/astro/commit/e023abac912d7cb6af2b9fb5107ef5dabc667096
- Package: https://github.com/withastro/astro
- Web: https://github.com/withastro/astro/releases/tag/astro@7.4.5
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.