Skip to content

[SignalR] Reject duplicate JSON properties - #69234

Open
javiercn wants to merge 4 commits into
mainfrom
javiercn/signalr-duplicate-target
Open

javiercn wants to merge 4 commits into
mainfrom
javiercn/signalr-duplicate-target

Conversation

@javiercn

@javiercn javiercn commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #68756

Overview

The System.Text.Json and Newtonsoft.Json SignalR hub protocol parsers now reject duplicate recognized properties. This prevents crafted payloads from producing inconsistent parser state, including binding arguments against one hub method and then overwriting the dispatch target with another method name.

Design

There is no public API change. Each parser rejects a repeated recognized top-level property with InvalidDataException using the message Duplicate '<property>' property is not allowed. before reading or applying the duplicate value.

The protected properties are type, invocationId, streamIds, target, error, allowReconnect, result, item, arguments, headers, and sequenceId. The validated non-null target value itself tracks whether target was already read. Explicit presence state is used where null/default values or later parser state changes make the parsed value insufficient, including nullable sequenceId, so {type:8,sequenceId:null,sequenceId:1} is rejected as a duplicate in both parsers.

Unknown extension properties remain ignored, and duplicate behavior for TypeScript, Java, and MessagePack is unchanged. The TypeScript client parses into one internally consistent last-value-wins object, while MessagePack uses positional fields.

Validation

  • Original target regression: Shared base tests exercise invocation (type: 1) and stream invocation (type: 4) payloads with arguments between conflicting target values against both JSON parsers. A target-specific binder uses int for the first target and string for the second to reproduce the mismatch faithfully.
  • Nullable sequence ID red: Before the explicit seen flag, System.Text.Json accepted {type:8,sequenceId:null,sequenceId:1} and Newtonsoft.Json rejected the first null with a type error instead of detecting the duplicate.
  • Focused green: All 26 shared duplicate-property and duplicate-target cases passed across both parsers.
  • Affected suites: 435 tests passed, 1 pre-existing test was skipped, and 0 failed across the System.Text.Json and Newtonsoft.Json hub protocol test classes.

A broader local src\SignalR\build.cmd -test run was previously attempted but could not complete because of unrelated environment limitations: Java Gradle compilation failed, ANCM native output was unavailable without MSBuild.exe, and Docker Client held a Redis test log lock. The prior PR CI completed successfully across the repository build and test matrix; checks for the latest review-fix commit will run after this push.

@github-actions github-actions Bot added the area-signalr Includes: SignalR clients and servers label Sep 11, 2026
@javiercn javiercn changed the title [SignalR] Reject duplicate JSON target properties [SignalR] Reject duplicate target properties Sep 11, 2026
@javiercn javiercn changed the title [SignalR] Reject duplicate target properties [SignalR] Reject duplicate JSON target properties Sep 11, 2026
@javiercn
javiercn marked this pull request as ready for review September 14, 2026 10:05
Copilot AI lite review requested due to automatic review settings September 14, 2026 10:05

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.

🟢 Approval recommended

All reviewed changes are covered by passing regression tests with no unresolved blocking issues.

Pull request overview

This pull request updates SignalR’s server-side JSON hub protocol parsers to reject duplicate target properties, preventing argument/dispatch mismatches.

Changes:

  • Added duplicate-target validation to both JSON parsers.
  • Added invocation and stream-invocation regression tests.
  • No public API changes.
File summaries
File Summary
src/SignalR/common/SignalR.Common/test/Internal/Protocol/NewtonsoftJsonHubProtocolTests.cs Tests duplicate targets with target-specific binding.
src/SignalR/common/SignalR.Common/test/Internal/Protocol/JsonHubProtocolTests.cs Adds duplicate-target validation cases.
src/SignalR/common/Protocols.NewtonsoftJson/src/Protocol/NewtonsoftJsonHubProtocol.cs Rejects repeated target properties.
src/SignalR/common/Protocols.Json/src/Protocol/JsonHubProtocol.cs Rejects repeated target properties.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@javiercn javiercn changed the title [SignalR] Reject duplicate JSON target properties [SignalR] Reject duplicate JSON properties Sep 18, 2026
@javiercn

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 7, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-signalr Includes: SignalR clients and servers pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject duplicate 'target' properties in SignalR hub protocol

3 participants