Skip to content

Apply a number of mitigations to System.Security.Cryptography.Xml - #130705

Merged
eiriktsarpalis merged 4 commits into
mainfrom
xml-fixes-7b
Jul 15, 2026
Merged

eiriktsarpalis merged 4 commits into
mainfrom
xml-fixes-7b

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Member

No description provided.

@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.

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 applies several robustness/security mitigations to System.Security.Cryptography.Xml, primarily by bounding attacker-controlled XML workloads (transform chain length, encrypted element processing) and reducing memory retention during transform processing.

Changes:

  • Add AppContext-configurable limits for (1) number of transforms in a deserialized TransformChain and (2) number of EncryptedData elements processed by XmlDecryptionTransform.
  • Introduce Transform.ClearState() and invoke it during transform-chain execution, with overrides in key built-in transforms to release intermediate state.
  • Add new regression/behavior tests (including an embedded XML resource) covering transform reuse, transform-chain limits, and encrypted element limits.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/libraries/System.Security.Cryptography.Xml/tests/TransformChainTest.cs Adds a test ensuring the same transform instance can be applied twice in a chain.
src/libraries/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj Embeds a new encrypted XML sample resource used by new tests.
src/libraries/System.Security.Cryptography.Xml/tests/SignedXml_SignatureMethodAlgorithm.cs Adds tests for large transform algorithm strings and encrypted-element processing limits (including AppContext switch behavior).
src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlTests.cs Adds tests validating transform-chain length limits and behavior when the limit is adjusted/disabled.
src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlSample5.xml New crafted encrypted XML payload exercising long transform chains / encoded DTD scenarios.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlLicenseTransform.cs Implements ClearState() to drop cached document/namespace state.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigXsltTransform.cs Implements ClearState() to release input stream reference after output is produced.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigXPathTransform.cs Implements ClearState() to release the cached input document.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigExcC14NTransform.cs Implements ClearState() to release canonicalization state.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigEnvelopedSignatureTransform.cs Implements ClearState() to release document/nodelist/ns-manager state.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigC14NTransform.cs Implements ClearState() to release canonicalization state.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigBase64Transform.cs Implements ClearState() to release the transform’s CryptoStream reference.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDecryptionTransform.cs Adds a configurable cap on processed EncryptedData elements and implements ClearState().
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs Enforces transform-chain length limit on deserialization and clears per-transform state after output generation.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs Introduces the internal virtual ClearState() hook for transforms.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/LocalAppContextSwitches.cs Adds AppContext switches and defaults for the new limits.
src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs Extends invalid character filtering to block nested-type (+) usage in algorithm names.
src/libraries/System.Security.Cryptography.Xml/src/Resources/Strings.resx Adds a localized error string for exceeding the decrypted-element processing cap.

@tannergooding

Copy link
Copy Markdown
Member

Its already "in", so LGTM. But a couple pieces of feedback

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

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

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

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 15, 2026 09:52

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

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

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1e296050-3562-4cbc-8cf7-91541c1f87eb

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

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

@eiriktsarpalis

Copy link
Copy Markdown
Member Author

/ba-g test failure is unrelated

@eiriktsarpalis
eiriktsarpalis enabled auto-merge (squash) July 15, 2026 16:33
@eiriktsarpalis
eiriktsarpalis merged commit 883277e into main Jul 15, 2026
83 of 88 checks passed
@eiriktsarpalis
eiriktsarpalis deleted the xml-fixes-7b branch July 15, 2026 16:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 16, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 16, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 59b23ae2 Deployed Jul 15, 2026 by eiriktsarpalis via conclusion #15166
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Security linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants