Repository navigation
Compare full HMAC against full SignatureValue in SignedXml.CheckSignedInfo - #130969
Conversation
|
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. |
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
There was a problem hiding this comment.
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 fullSignatureValue. - Add regression tests covering zero-length and truncated HMAC
SignatureValuescenarios, including cases where theSignatureMethodis 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. |
|
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
}
]
} |
There was a problem hiding this comment.
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
truethrough 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
|
/ba-g failures look like infra issue |
No description provided.