Skip to content

Commit d3a60eb

Browse files
committed
Merge branch 'ca5366' of https://github.com/LLLXXXCCC/visualstudio-docs-pr into ca5366
2 parents cedf519 + 0037173 commit d3a60eb

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

docs/code-quality/ca5374.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: "CA5374: Do Not Use XslTransform"
3+
description: Provides information about code analysis rule CA5374, including causes, how to fix violations, and when to suppress it.
4+
ms.date: 04/28/2020
5+
ms.topic: reference
6+
author: LLLXXXCCC
7+
ms.author: linche
8+
manager: jillfra
9+
dev_langs:
10+
- CSharp
11+
- VB
12+
ms.workload:
13+
- "multiple"
14+
f1_keywords:
15+
- "CA5374"
16+
- "DoNotUseXslTransform"
17+
---
18+
# CA5374: Do Not Use XslTransform
19+
20+
|||
21+
|-|-|
22+
|CheckId|CA5374|
23+
|Category|Microsoft.Security|
24+
|Breaking change|Non-breaking|
25+
26+
## Cause
27+
28+
Instantiating an <xref:System.Xml.Xsl.XslTransform?displayProperty=nameWithType>, which doesn't restrict potentially dangerous external references.
29+
30+
## Rule description
31+
32+
<xref:System.Xml.Xsl.XslTransform> is vulnerable when operating on untrusted input. An attack could execute arbitrary code.
33+
34+
## How to fix violations
35+
36+
Replace <xref:System.Xml.Xsl.XslTransform> with <xref:System.Xml.Xsl.XslCompiledTransform?displayProperty=nameWithType>. For more guidance, see [/dotnet/standard/data/xml/migrating-from-the-xsltransform-class].
37+
38+
## When to suppress warnings
39+
40+
The <xref:System.Xml.Xsl.XslTransform> object, XSLT style sheets, and XML source data are all from trusted sources.
41+
42+
## Pseudo-code examples
43+
44+
### Violation
45+
46+
At present, the following pseudo-code sample illustrates the pattern detected by this rule.
47+
48+
```csharp
49+
using System;
50+
using System.Xml;
51+
using System.Xml.XPath;
52+
using System.Xml.Xsl;
53+
54+
namespace TestForXslTransform
55+
{
56+
class Program
57+
{
58+
static void Main(string[] args)
59+
{
60+
// Create a new XslTransform object.
61+
XslTransform xslt = new XslTransform();
62+
63+
// Load the stylesheet.
64+
xslt.Load("http://server/favorite.xsl");
65+
66+
// Create a new XPathDocument and load the XML data to be transformed.
67+
XPathDocument mydata = new XPathDocument("inputdata.xml");
68+
69+
// Create an XmlTextWriter which outputs to the console.
70+
XmlWriter writer = new XmlTextWriter(Console.Out);
71+
72+
// Transform the data and send the output to the console.
73+
xslt.Transform(mydata, null, writer, null);
74+
}
75+
}
76+
}
77+
```
78+
79+
### Solution
80+
81+
```csharp
82+
using System.Xml;
83+
using System.Xml.Xsl;
84+
85+
namespace TestForXslTransform
86+
{
87+
class Program
88+
{
89+
static void Main(string[] args)
90+
{
91+
// Create the XsltSettings object with script enabled.
92+
XsltSettings settings = new XsltSettings(false, true);
93+
94+
// Execute the transform.
95+
XslCompiledTransform xslt = new XslCompiledTransform();
96+
xslt.Load("http://server/favorite.xsl", settings, new XmlUrlResolver());
97+
xslt.Transform("inputdata.xml", "outputdata.html");
98+
}
99+
}
100+
}
101+
102+
```

docs/code-quality/code-analysis-warnings-for-managed-code-by-checkid.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ f1_keywords:
271271
- CA2245
272272
- CA2246
273273
- CA5122
274+
- CA5374
274275
ms.assetid: 5cb221f6-dc59-4abf-9bfa-adbd6f907f96
275276
author: mikejo5000
276277
ms.author: mikejo
@@ -540,3 +541,4 @@ The following table lists Code Analysis warnings for managed code by the CheckId
540541
| CA2246 | [CA2246: Do not assign a symbol and its member in the same statement](../code-quality/ca2246.md) | Assigning a symbol and its member, that is, a field or a property, in the same statement is not recommended. It is not clear if the member access was intended to use the symbol's old value prior to the assignment or the new value from the assignment in this statement. |
541542
| CA5122 | [CA5122 P/Invoke declarations should not be safe critical](../code-quality/ca5122.md) | Methods are marked as SecuritySafeCritical when they perform a security sensitive operation, but are also safe to be used by transparent code. Transparent code may never directly call native code through a P/Invoke. Therefore, marking a P/Invoke as security safe critical will not enable transparent code to call it, and is misleading for security analysis. |
542543
| CA5366 | [CA5366 Use XmlReader For DataSet Read XML](../code-quality/ca5366.md) | Using a <xref:System.Data.DataSet> to read XML with untrusted data may load dangerous external references, which should be restricted by using an <xref:System.Xml.XmlReader> with a secure resolver or with DTD processing disabled. |
544+
| CA5374 | [CA5374 Do Not Use XslTransform](../code-quality/ca5374.md) | This rule checks if <xref:System.Xml.Xsl.XslTransform?displayProperty=nameWithType> is instantiated in the code. <xref:System.Xml.Xsl.XslTransform?displayProperty=nameWithType> is now obsolete and shouldn’t be used. |

docs/code-quality/security-warnings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Security warnings support safer libraries and applications. These warnings help
109109
|[CA5371: Use XmlReader for schema read](../code-quality/ca5371.md)|Processing untrusted DTD and XML schemas may enable loading dangerous external references. Using an XmlReader with a secure resolver or with DTD and XML inline schema processing disabled restricts this.|
110110
|[CA5372: Use XmlReader for XPathDocument](../code-quality/ca5372.md)|Processing XML from untrusted data may load dangerous external references, which can be restricted by using an XmlReader with a secure resolver or with DTD processing disabled.|
111111
|[CA5373: Do not use obsolete key derivation function](../code-quality/ca5373.md)|This rule detects the invocation of weak key derivation methods <xref:System.Security.Cryptography.PasswordDeriveBytes?displayProperty=fullName> and `Rfc2898DeriveBytes.CryptDeriveKey`. <xref:System.Security.Cryptography.PasswordDeriveBytes?displayProperty=fullName> used a weak algorithm PBKDF1.|
112+
|[CA5374: Do Not Use XslTransform](../code-quality/ca5374.md)|This rule checks if <xref:System.Xml.Xsl.XslTransform?displayProperty=nameWithType> is instantiated in the code. <xref:System.Xml.Xsl.XslTransform?displayProperty=nameWithType> is now obsolete and shouldn’t be used.|
112113
|[CA5378: Do not disable ServicePointManagerSecurityProtocols](../code-quality/ca5378.md)|Setting `Switch.System.ServiceModel.DisableUsingServicePointManagerSecurityProtocols` to `true` limits Windows Communication Framework's (WCF) Transport Layer Security (TLS) connections to using TLS 1.0. That version of TLS will be deprecated.|
113114
|[CA5380: Do not add certificates to root store](../code-quality/ca5380.md)|This rule detects code that adds a certificate into the Trusted Root Certification Authorities certificate store. By default, the Trusted Root Certification Authorities certificate store is configured with a set of public CAs that has met the requirements of the Microsoft Root Certificate Program.|
114115
|[CA5381: Ensure certificates are not added to root store](../code-quality/ca5381.md)|This rule detects code that potentially adds a certificate into the Trusted Root Certification Authorities certificate store. By default, the Trusted Root Certification Authorities certificate store is configured with a set of public certification authorities (CAs) that has met the requirements of the Microsoft Root Certificate Program.|

docs/code-quality/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@
764764
href: ca5372.md
765765
- name: "CA5373: Do not use obsolete key derivation function"
766766
href: ca5373.md
767+
- name: "CA5374: Do Not Use XslTransform"
768+
href: ca5374.md
767769
- name: "CA5378: Do not disable ServicePointManagerSecurityProtocols"
768770
href: ca5378.md
769771
- name: "CA5380: Do not add certificates to root store"

0 commit comments

Comments
 (0)