Skip to main content
Vulnerability Database/CVE-2024-47604

CVE-2024-47604: Microsoft NuGetGallery XSS Vulnerability

CVE-2024-47604 is a cross-site scripting flaw in Microsoft NuGetGallery that enables attackers to execute arbitrary HTML or JavaScript code in victim browsers. This article covers technical details, impact assessment, and mitigation.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-47604 Overview

CVE-2024-47604 is a cross-site scripting (XSS) vulnerability in NuGet Gallery, the package repository software that powers nuget.org. The flaw stems from improper handling of HTML element attributes, allowing an attacker to inject arbitrary HTML or JavaScript code that executes in a victim's browser. The vulnerability is classified under [CWE-79] and requires user interaction to trigger. Successful exploitation can lead to session hijacking, credential theft, or unauthorized actions performed in the context of an authenticated gallery user.

Critical Impact

An attacker can execute arbitrary JavaScript in a victim's browser session, potentially compromising package maintainer accounts and the integrity of hosted NuGet packages.

Affected Products

  • Microsoft NuGet Gallery (nuget.org package repository software)
  • Self-hosted NuGet Gallery deployments prior to the patch commit 3a18689
  • Downstream forks of the NuGetGallery codebase

Discovery Timeline

  • 2024-10-01 - CVE-2024-47604 published to the National Vulnerability Database
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2024-47604

Vulnerability Analysis

The vulnerability resides in the Razor view template src/NuGetGallery/Views/Shared/Gallery/Layout.cshtml. The <body> element's id attribute was populated directly from Url.Current() without proper attribute encoding or quoting. When a user visits a crafted URL, the unquoted attribute value permits attribute injection, enabling an attacker to break out of the attribute context and inject event handlers or additional HTML.

Since NuGet Gallery handles package publishing and user authentication, successful exploitation can target package maintainers. An attacker who executes JavaScript in a maintainer's session can perform API operations, modify package metadata, or exfiltrate authentication tokens.

Root Cause

The root cause is missing output encoding on an HTML attribute value. The template rendered <body id=@Url.Current()> where the attribute value was neither quoted nor sanitized. Razor's implicit encoding does not fully protect unquoted attributes from attribute-boundary breakout.

Attack Vector

Exploitation requires an attacker to craft a URL on the NuGet Gallery host and convince a victim to visit it. The payload traverses the network, is reflected by the server into the response HTML, and executes in the victim's browser. The scope change indicates the injected script can access resources beyond the vulnerable component's security context.

text
// Patch diff from upstream commit 3a18689
     @ViewHelpers.ReleaseMeta()
     @ViewHelpers.InstrumentationScript(ViewBag)
 </head>
-<body id=@Url.Current()>
+<body @{if (Request.Url.GetComponents(UriComponents.Path, UriFormat.UriEscaped) == "") { <text>id="/"</text> } }>
     @Html.Partial("Gallery/Header")
     <div id="skippedToContent">
     @RenderBody()

Source: NuGet/NuGetGallery commit 3a18689. The patch replaces the attacker-controlled attribute value with a static id="/" emitted only for the root path, eliminating the injection sink.

Detection Methods for CVE-2024-47604

Indicators of Compromise

  • HTTP requests to NuGet Gallery URLs containing attribute-breaking characters such as ", >, or onerror= in the path component
  • Reflected response bodies where the <body> element contains unexpected event handlers or injected <script> tags
  • Unusual outbound requests from authenticated gallery sessions to attacker-controlled domains
  • Package metadata changes or new API keys generated shortly after a maintainer followed an external link

Detection Strategies

  • Review web server and WAF logs for requests whose path segments include HTML metacharacters targeting the gallery host
  • Deploy Content Security Policy (CSP) violation reporting to surface inline script execution attempts
  • Inspect browser telemetry for script execution originating from the gallery domain but calling third-party endpoints

Monitoring Recommendations

  • Enable audit logging for package publish, delete, and ownership change operations on self-hosted galleries
  • Monitor authentication events for session reuse from unexpected IP addresses or user agents
  • Alert on API key creation and package version pushes that occur outside normal maintainer activity windows

How to Mitigate CVE-2024-47604

Immediate Actions Required

  • Upgrade self-hosted NuGet Gallery deployments to a build that includes commit 3a18689 or pull request #10193
  • Rotate NuGet Gallery API keys for accounts that may have browsed untrusted links during the exposure window
  • Enforce a strict Content Security Policy that disallows inline scripts and restricts script sources to trusted origins

Patch Information

The fix is available in the upstream repository via NuGet/NuGetGallery pull request #10193 and the corresponding GitHub Security Advisory GHSA-hq63-27r7-2j64. Operators of self-hosted galleries should rebuild from a source tree that includes the patched Layout.cshtml and redeploy.

Workarounds

  • Place a web application firewall rule in front of the gallery that blocks request paths containing <, >, ", or = characters
  • Serve the gallery with a Content-Security-Policy header that forbids unsafe-inline and restricts script-src to a nonce or hash allowlist
  • Require re-authentication for sensitive package management actions to reduce the value of a hijacked session
bash
# Example nginx CSP header for self-hosted NuGet Gallery
add_header Content-Security-Policy "default-src 'self'; \
  script-src 'self' 'nonce-$request_id'; \
  object-src 'none'; \
  base-uri 'self'; \
  frame-ancestors 'none'" always;

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.