/

CVE-2026-50146

Severity:

HIGH RISK

(7.1)

Reflected XSS (CWE-80) in Astro client directive slots

CVE-2026-50146

Modified

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-80

Impact:

Reflected Cross-Site Scripting (XSS)

Severity:

HIGH RISK

(7.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Astro fails to properly HTML-escape named slot content when rendering components that use a client:* directive, inserting the slot name directly into a data-astro-template attribute.

An attacker who can influence the slot name may break out of the attribute context and inject arbitrary HTML, leading to reflected cross-site scripting (XSS) during server-side rendering.

Affected context

This vulnerability occurs in Astro applications that:

  • Use components with client:* directives (e.g., client:load, client:visible)
  • Render named slots whose names can be influenced directly or indirectly by user-controlled data
  • Rely on server-side rendering (SSR) to generate HTML responses

Under these conditions, unescaped slot names are interpolated into a data-astro-template attribute, creating an injection point in the rendered HTML.

Exploit preconditions

  • Attack surface: HTTP(S) endpoints serving SSR-generated Astro pages that include client:* components with named slots.
  • Required access: Ability to control or affect the named slot identifier (e.g., via query parameters, route parameters, templating logic, or user-provided labels/names flowing into slot names).
  • Trigger point: A request that causes the vulnerable component to render with a maliciously crafted slot name, which is inserted into the data-astro-template attribute.
  • Why exploitation is possible: The slot name is interpolated into an HTML attribute without proper escaping or context-aware encoding, allowing an attacker to break the attribute syntax and inject arbitrary HTML/JS.

Why this happens

The underlying issue is a failure to perform proper output encoding when rendering user-influenced data into HTML attributes.

When a component uses a client:* directive, Astro constructs a data-astro-template attribute containing the slot name. Because the slot name is not HTML-escaped, special characters (such as quotes, angle brackets, and event handlers) can terminate the attribute value and inject additional HTML or script content.

This aligns with CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS), where user-controllable data is rendered into a page without appropriate neutralization for the output context.

Potential impact

  • Execution of arbitrary JavaScript in the victim's browser within the context of the vulnerable origin
  • Theft of session identifiers, CSRF tokens, or other sensitive data accessible via the DOM
  • Unauthorized actions performed on behalf of authenticated users (e.g., account changes, transactions)
  • Defacement or manipulation of page content to conduct phishing or social engineering
  • Lateral movement to other parts of the application via authenticated victim sessions

General mitigation guidance

Effective mitigation focuses on strict, context-aware output encoding and minimizing trust in any user-influenced values used in HTML structure:

  • Ensure that values interpolated into HTML attributes—especially data attributes—are properly escaped for the attribute context (e.g., encoding quotes, angle brackets, and ampersands).
  • Avoid deriving slot names, element attributes, or template identifiers directly from user-controlled data; instead, map user values to a constrained set of known-safe identifiers.
  • Enforce a clear separation between data and markup by treating all dynamic values as untrusted payloads that must be encoded for their specific rendering context (HTML body, attribute, URL, JavaScript, etc.).
  • Apply a least-privilege mindset to client-side behavior by limiting where executable contexts (inline event handlers, inline scripts) are used and preferring non-inline script patterns.
  • Where possible, supplement encoding with defense-in-depth mechanisms such as a restrictive Content Security Policy (CSP) that reduces impact of potential injection points.

How teams detect issues like this

Detection typically involves a combination of static and review-based approaches:

  • Configure static analysis or linting rules to flag unescaped insertion of dynamic values into HTML attributes, especially data attributes used for templating.
  • During code review, pay close attention to areas where user input or derived values influence slot names, attribute values, or other structural HTML constructs, verifying that proper escaping is applied.
  • Use security-focused template linting or framework-specific rules that enforce context-aware encoding for server-side rendering code paths.
  • Incorporate dynamic security testing or automated scanners that exercise application input points and look for reflected content that can break out of attribute or tag contexts.

Sources

SourceLink
github.comgithub.com/withastro/astro/security/advisories/GHSA-8hv8-536x-4wqp

Frequently asked

questions

Yes. If an attacker can supply or influence the slot name that is reflected in the SSR response, they can remotely trigger XSS in users who visit a crafted URL or interact with attacker-controlled input.

Typically, only the ability to send HTTP requests that affect the slot name or related templating logic is required. No authenticated access is strictly necessary unless the affected slot name is derived only from authenticated user data.

Apply strict, context-aware HTML escaping to any dynamic values written into attributes and avoid deriving slot names or similar structural identifiers directly from user-controlled data. Constraining these identifiers to a predefined, validated set further reduces risk.

Adopt a systematic output-encoding strategy within the framework and application code, enforce template and attribute-safety linting in CI, avoid mixing control/structure with untrusted data, and periodically conduct security reviews focused on SSR and templating paths.

Find out what's already
exploitable in your codebase.