Skip to content

[main] Avoid repeated validation error copies (CVE-2026-118749) - #70449

Merged
rbhanda merged 6 commits into
dotnet:mainfrom
rbhanda:security/nov2026-118749
Nov 11, 2026
Merged

rbhanda merged 6 commits into
dotnet:mainfrom
rbhanda:security/nov2026-118749

Conversation

@rbhanda

@rbhanda rbhanda commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Avoid rebuilding the validation error dictionary and every error collection on each property access.
  • Preserve the read-only public surface while returning the existing collected data.
  • Add coverage proving repeated access does not copy the full result.

Addresses CVE-2026-118749.

Testing

Not run locally. The focused repository test setup was blocked before compilation because the required .NET 12 SDK needs MSBuild 18.7 or newer, while this machine has MSBuild 17.15. CI validation is required.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: fdac132c-0926-4fda-8c97-88ae5b59b9fd
@rbhanda
rbhanda requested a review from javiercn November 10, 2026 18:42
@rbhanda
rbhanda marked this pull request as ready for review November 10, 2026 22:25
Copilot AI balanced review requested due to automatic review settings November 10, 2026 22:25
@rbhanda
rbhanda enabled auto-merge November 10, 2026 22:30

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.

🟡 Changes recommended

Exposing the backing dictionary and mutable value lists lets callers alter collected errors and replace lists with arrays, causing later AddValidationError calls to fail at the list cast.

1 open issue
What changed in this PR

This PR reduces repeated allocations when accessing collected validation errors in Microsoft.Extensions.Validation, while keeping the public property signature unchanged.

Changes:

  • Returns the existing error dictionary instead of rebuilding it on each access.
  • Adjusts internal storage and appending to use read-only list interfaces.
  • Adds repeated-access identity coverage for synchronous and asynchronous validation, and removes the immutability test.
File Description
src/​Validation/​test/​Microsoft.Extensions.Validation.Tests/​ValidatableParameterInfoTests.cs Adds no-copy coverage and removes collection immutability assertions.
src/​Validation/​src/​ValidateContext.cs Returns backing error storage directly and adjusts per-path error insertion.

Review effort: Balanced

/// </remarks>
public IReadOnlyDictionary<string, IReadOnlyList<ValidationError>>? ValidationErrors
=> _validationErrors?.ToDictionary(kvp => kvp.Key, kvp => (IReadOnlyList<ValidationError>)kvp.Value.AsReadOnly()).AsReadOnly();
=> _validationErrors;
@rbhanda
rbhanda merged commit aae674b into dotnet:main Nov 11, 2026
25 of 29 checks passed
@rbhanda
rbhanda temporarily deployed to copilot-pat-pool November 11, 2026 00:57 — with GitHub Actions Inactive
@rbhanda
rbhanda temporarily deployed to copilot-pat-pool November 11, 2026 00:57 — with GitHub Actions Inactive
@rbhanda
rbhanda temporarily deployed to copilot-pat-pool November 11, 2026 00:58 — with GitHub Actions Inactive
@rbhanda
rbhanda temporarily deployed to copilot-pat-pool November 11, 2026 00:59 — with GitHub Actions Inactive
@rbhanda
rbhanda temporarily deployed to copilot-pat-pool November 11, 2026 01:01 — with GitHub Actions Inactive
@rbhanda
rbhanda temporarily deployed to copilot-pat-pool November 11, 2026 01:01 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

ℹ️ This pull request wasn't processed automatically.

This change requires specialized review. Please confirm whether documentation updates are needed and handle them through the appropriate process.

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 74d1c5d8 Deployed Nov 11, 2026 by rbhanda via conclusion #286
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.

4 participants