/

CVE-2026-39399

Severity:

CRITICAL RISK

(9.6)

Improper Input Validation and Path Traversal in NuGet

CVE-2026-39399

Awaiting Analysis

Vulnerability type

Category:

Improper Input Validation and Path Traversal

CWE:

CWE-20, CWE-22

Impact:

Remote Code Execution and Arbitrary File/Blob Write

Severity:

CRITICAL RISK

(9.6)

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

NuGet Gallery's backend job improperly validates metadata from .nuspec files inside uploaded NuGet packages, allowing crafted package identifiers and metadata to influence how blob paths and metadata are resolved.

Under certain conditions, this can lead to cross-package metadata injection and attacker-controlled blob paths, potentially resulting in remote code execution and arbitrary writes to blobs in the storage container.

Affected context

The vulnerability affects environments running the NuGet Gallery backend jobs that process .nuspec files from uploaded packages.

It is relevant when:

  • Package metadata (e.g., identifiers, URIs, or related fields) from the .nuspec file is consumed as trusted input,
  • Derived values are used to construct blob storage paths or metadata without strict validation or normalization,
  • URI fragments and other untrusted components can influence how and where blobs are written.

The issue does not inherently affect clients directly; it arises in the server-side processing pipeline that handles and persists package content and metadata.

Exploit preconditions

  • Attack surface: NuGet Gallery backend job responsible for ingesting and processing NuGet packages.
  • Required access: Ability to publish or submit a NuGet package containing a crafted .nuspec file to a vulnerable NuGet Gallery instance (which could be a public gallery or a private/internal deployment).
  • Trigger point: Automatic or scheduled execution of the backend job that reads .nuspec metadata and uses it to construct blob paths or perform metadata resolution.
  • Why exploitation is possible:
  • Untrusted .nuspec fields, including package identifiers, are insufficiently validated or sanitized.
  • URI fragment injection and path manipulation are possible when building blob URIs, allowing an attacker to influence the resolved storage location.
  • The backend job uses this derived path with elevated storage permissions, enabling writes to blobs beyond the attacker's own package content and potentially enabling follow-on behaviors that can be abused for RCE in downstream consumers or processing components.

Why this happens

The core issue is insufficient input validation (CWE-20) combined with improper restriction of path and resource references (CWE-22) when handling .nuspec metadata within the backend job.

Package identifiers and related metadata are treated as structurally trustworthy, and used directly or with weak sanitization to construct blob URIs and storage paths.

Because URI fragments and path segments are not normalized or strictly constrained to safe, expected patterns, an attacker-controlled .nuspec can:

  • Inject or manipulate URI fragments ("#" components) that influence how the final blob path is interpreted.
  • Cause cross-package metadata injection, where metadata from one package is effectively applied to or stored as if it belonged to another package.

Conceptually, this maps to a broader pattern where user-controlled identifiers are used to build file or object storage paths without rigorous validation, enabling overwrites or unauthorized writes to arbitrary locations, and in some scenarios creating conditions conducive to remote code execution when downstream systems interpret or execute tampered blobs.

Potential impact

  • Attacker-controlled writes to arbitrary blobs within the backing storage container.
  • Tampering with existing package content or associated metadata blobs.
  • Cross-package metadata injection, causing one package's metadata to contaminate or override another's.
  • Potential remote code execution in components that later consume, execute, or deserialize tampered blobs or metadata.
  • Supply-chain compromise via malicious alteration of packages or associated artifacts hosted on the gallery.
  • Loss of integrity for hosted packages and reduced trust in the package repository.

General mitigation guidance

Robust mitigation typically focuses on tightening validation of all untrusted metadata and hardening how storage paths are derived:

  • Enforce strict input validation on .nuspec metadata:
  • Accept only well-defined formats for identifiers and related fields (e.g., whitelist allowed characters and lengths).
  • Reject or normalize any use of URI fragments, unexpected delimiters, or path traversal patterns.
  • Decouple storage paths from raw user input:
  • Derive blob keys from canonical, server-side normalized identifiers rather than directly from user-supplied values.
  • Use stable, pre-defined naming schemes that do not embed arbitrary metadata or fragments from the package.
  • Normalize and constrain all path- and URI-related operations:
  • Apply path normalization functions and enforce that final paths remain within an expected logical container or prefix.
  • Avoid concatenating untrusted strings into URIs or storage keys without structural checks.
  • Apply least-privilege to storage operations:
  • Restrict the write scope of the backend job to only the prefixes or containers that are required.
  • Use separate containers or logical namespaces for different artifact types to reduce blast radius.
  • Introduce secure-by-default parsing behavior:
  • Treat .nuspec content as untrusted data and validate against a strict schema before using any values in security-relevant operations such as path construction or command invocation.

How teams detect issues like this

Detection is most effective when combining code-centric and behavior-centric approaches:

  • Static analysis and code review:
  • Flag code paths where .nuspec fields, package IDs, or other untrusted metadata are used to construct URIs, paths, or blob keys.
  • Look for direct string concatenation or interpolation of user-controlled values into storage keys or file paths.
  • Identify places where URI fragments or query strings are parsed but not sanitized or normalized.
  • Verify that all path- and URI-building functions enforce a canonical base path and validate against traversal or injection patterns.
  • Unit and integration tests:
  • Add test cases that submit crafted .nuspec files with unusual identifiers, fragments, and path-like patterns to ensure they are rejected or safely handled.
  • Runtime monitoring:
  • Monitor storage logs for unexpected writes outside the typical directory or prefix structure for packages.
  • Alert on blob write operations that:
  • Target unexpected locations,
  • Overwrite existing blobs, or
  • Include suspicious naming patterns that reflect fragments, traversal sequences, or inconsistent identifiers.
  • Automated tooling:
  • Use security-focused linters or SAST tools configured to detect unsanitized input in path or URI construction.
  • Integrate these checks into CI pipelines so that changes to backend job logic are automatically scrutinized for input validation and path safety regressions.

Sources

SourceLink
github.comgithub.com/NuGet/NuGetGallery/commit/0e80f87628349207cdcaf55358491f8a6f1ca276
github.comgithub.com/NuGet/NuGetGallery/security/advisories/GHSA-9r3h-v4hx-rhfr

Frequently asked

questions

Yes. An attacker can exploit this issue remotely by submitting a crafted NuGet package containing a malicious .nuspec file to a vulnerable NuGet Gallery instance. The backend job processes the package and triggers the vulnerability without requiring local access.

The attacker typically needs the ability to publish or upload packages to the affected gallery. No direct access to the storage backend is required; the backend job's elevated storage privileges are abused indirectly through crafted metadata.

The safest pattern is to treat all .nuspec metadata as untrusted, apply strict validation and normalization, and ensure that storage paths or blob keys are derived from canonical, server-controlled representations. Avoid constructing URIs or paths directly from raw user input, and enforce that any derived path is constrained to an expected namespace.

Prevention relies on a combination of secure design and process:

  • Apply strong input validation and schema enforcement to all package metadata and configuration files.
  • Design storage and file path schemes where user input cannot escape predefined namespaces or containers.
  • Use security-focused code reviews and automated checks (e.g., SAST) to detect unsafe use of untrusted data in URIs, paths, and command parameters.
  • Regularly test ingestion pipelines with adversarial inputs to confirm that malicious metadata is safely rejected or neutralized.
Find out what's already
exploitable in your codebase.