Skip to content

Allow string vuln severity in STJ code path - #7465

Merged
Nigusu-Allehu merged 2 commits into
devfrom
dev-nyenework-severity-stj-fix
Jun 9, 2026
Merged

Nigusu-Allehu merged 2 commits into
devfrom
dev-nyenework-severity-stj-fix

Conversation

@Nigusu-Allehu

@Nigusu-Allehu Nigusu-Allehu commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#14938

Description

Fixes two bugs in the System.Text.Json deserialization path

  1. Severity crash: nuget.org's registration API returns vulnerability severity as a string ("2"), but PackageVulnerabilityMetadata.Severity is int. STJ rejects this by default.
  2. Streaming TrySkip crash: PackageDependencyGroupStjConverter called reader.Skip() which throws on streaming readers. Fix: use reader.TrySkip() instead.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses two System.Text.Json (STJ) deserialization issues in NuGet.Protocol when consuming nuget.org-style registration JSON: vulnerability severity occasionally arrives as a JSON string, and the STJ dependency-group converter could throw when skipping unknown properties in streaming scenarios.

Changes:

  • Allow PackageVulnerabilityMetadata.Severity to be read from a JSON string in the STJ path.
  • Update STJ PackageDependencyGroup converter to use Utf8JsonReader.TrySkip() instead of Skip().
  • Extend protocol tests/test data to validate vulnerability parsing (including severity-as-string) for both STJ and Newtonsoft.Json paths.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/TestUtilities/Test.Utility/JsonData.cs Adds a vulnerability entry (with severity encoded as a string) to the DeepEqual registration test JSON.
test/NuGet.Core.Tests/NuGet.Protocol.Tests/PackageMetadataResourceV3Tests.cs Asserts vulnerabilities are parsed correctly (severity + advisory URL) for both STJ-enabled and STJ-disabled runs.
src/NuGet.Core/NuGet.Protocol/Model/PackageVulnerabilityMetadata.cs Enables STJ to read numeric severity from a JSON string via JsonNumberHandling.AllowReadingFromString.
src/NuGet.Core/NuGet.Protocol/Converters/PackageDependencyGroupStjConverter.cs Switches unknown-property skipping to TrySkip() to avoid streaming-related exceptions.

@Nigusu-Allehu
Nigusu-Allehu marked this pull request as ready for review June 9, 2026 17:12
@Nigusu-Allehu
Nigusu-Allehu requested a review from a team as a code owner June 9, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AOT test] System.Text.Json code path failures in NuGet.Protocol: Vulnerability Severity and PackageDependencyGroupStjConverter

4 participants