Skip to content

Compare full HMAC against full SignatureValue in SignedXml.CheckSignedInfo - #130969

Merged
krwq merged 1 commit into
dotnet:mainfrom
krwq:sxml-hmac-compare
Jul 22, 2026
Merged

krwq merged 1 commit into
dotnet:mainfrom
krwq:sxml-hmac-compare

Conversation

@krwq

@krwq krwq commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

No description provided.

@krwq
krwq requested a review from bartonjs July 17, 2026 13:23
Copilot AI review requested due to automatic review settings July 17, 2026 13:23
@krwq krwq changed the title Compare full HMAC against full SignatureValue in SignedXml.CheckSigne… Compare full HMAC against full SignatureValue in SignedXml.CheckSignature Jul 17, 2026
@krwq krwq changed the title Compare full HMAC against full SignatureValue in SignedXml.CheckSignature Compare full HMAC against full SignatureValue in SignedXml.CheckSignedInfo Jul 17, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

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 hardens System.Security.Cryptography.Xml HMAC signature verification by ensuring the computed HMAC is compared against the entire SignatureValue, preventing acceptance of empty/truncated signatures via prefix comparisons.

Changes:

  • Update SignedXml.CheckSignedInfo(KeyedHashAlgorithm) to compare the full computed HMAC against the full SignatureValue.
  • Add regression tests covering zero-length and truncated HMAC SignatureValue scenarios, including cases where the SignatureMethod is non-HMAC or signature format validation is disabled/bypassed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXml.cs Switch HMAC verification to full-value comparison via CryptographicEquals, avoiding prefix-acceptance edge cases.
src/libraries/System.Security.Cryptography.Xml/tests/SignedXmlTest.cs Add targeted tests for zero-length/truncated HMAC SignatureValue cases across different SignatureMethod URLs and validator configurations.

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "fe4bceb7f6a64139edf8687774a869d428840e6f",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "402ed14c4080491d0965638b7a1dfd673239b586",
  "last_reviewed_commit": "fe4bceb7f6a64139edf8687774a869d428840e6f",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "402ed14c4080491d0965638b7a1dfd673239b586",
  "last_recorded_worker_run_id": "29686416791",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "fe4bceb7f6a64139edf8687774a869d428840e6f",
      "review_id": 4730734898
    }
  ]
}

@github-actions github-actions Bot 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.

Holistic Review

Motivation: SignedXml.CheckSignedInfo verified an HMAC-signed SignedInfo by comparing the received SignatureValue against only the first SignatureValue.Length bytes of the freshly computed HMAC (SequenceEqual(hashValue.AsSpan(0, SignatureValue.Length))). This is an implicit truncated-HMAC comparison: with a small (or zero) HMACOutputLength/SignatureLength, only a prefix of the MAC is checked. When the default SignatureFormatValidator is replaced by a permissive or null validator (which disables the built-in truncated-HMAC rejection), this reduces MAC strength and, at zero length, degenerates into an empty-span comparison that always succeeds — a signature-forgery bypass.

Approach: The comparison is replaced with the existing constant-time CryptographicEquals(m_signature.SignatureValue, hashValue) helper already used for digest comparison. Because CryptographicEquals short-circuits to false on any length mismatch, the received value must now equal the full HMAC output, eliminating prefix/truncated comparisons regardless of the format validator. The prior length-validation guards (SignatureValue.Length == signatureLength / 8, range and modulo-8 checks) are retained, so malformed lengths still throw as before. Five focused tests cover zero-length and half-length HMACs under null, permissive, and default validators, plus a non-HMAC SignatureMethod override and a post-processed enveloped-signature variant, asserting rejection in each case.

Summary: This is a correct, minimal, and well-targeted security fix. Routing HMAC verification through the constant-time full-length comparison closes the truncated/zero-length HMAC bypass while preserving the existing behavior for well-formed, full-length signatures (which the surrounding length checks and existing verification tests continue to exercise). The added tests are clear and directly exercise the vulnerable paths. Verdict: LGTM.

Detailed Findings

No actionable defects found.

  • Behavior note (non-actionable): This change removes the ability to verify deliberately truncated HMAC signatures even when a caller opts in via a permissive SignatureFormatValidator. Since the default validator (DoesSignatureUseTruncatedHmac) already rejects truncated HMACs, the only affected scenario is a caller that intentionally overrode that policy; for those callers, previously-verifiable truncated-HMAC documents will now fail verification. This is the intended security posture, but is worth calling out as a subtle behavioral change for any consumer relying on custom truncated-HMAC verification.
  • Test coverage (non-actionable): The new tests assert rejection paths thoroughly. Positive-path verification of a full-length HMAC is left to the existing test suite; consider ensuring at least one added or existing test asserts that a normal full-length HMAC signature still verifies true through this code path, to guard against a future regression that over-rejects.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 59 AIC · ⌖ 10.6 AIC · ⊞ 10K

@krwq

krwq commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

/ba-g failures look like infra issue

@krwq
krwq merged commit 5d9a801 into dotnet:main Jul 22, 2026
92 of 94 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 24, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants