Skip to content

Commit 2a46a26

Browse files
author
Denis Levin
committed
Update addressing review comments
1 parent 7492dab commit 2a46a26

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

csharp/ql/src/Security Features/CWE-327/DontInstallRootCert.ql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* @description Application- or user-specific certificates placed in the system root store could
44
* weaken security for other processing running on the same system.
55
* @kind problem
6-
* @id cs/do-not-add-certs-to-root-store
6+
* @id cs/adding-cert-to-root-store
77
* @problem.severity error
8-
* @precision high
98
* @tags security
109
* external/cwe/cwe-327
1110
*/
@@ -16,21 +15,22 @@ class AddCertToRootStoreConfig extends DataFlow::Configuration {
1615
AddCertToRootStoreConfig() { this = "Adding Certificate To Root Store" }
1716

1817
override predicate isSource(DataFlow::Node source) {
19-
exists(ObjectCreation oc | oc = source.asExpr().(ObjectCreation) |
20-
oc.getType().(RefType).hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store")
21-
and oc.getArgument(0).(Access).getTarget().hasName("Root")
22-
)
18+
exists(ObjectCreation oc | oc = source.asExpr() |
19+
oc.getType().(RefType).hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store") and
20+
oc.getArgument(0).(Access).getTarget().hasName("Root")
21+
)
2322
}
2423

2524
override predicate isSink(DataFlow::Node sink) {
2625
exists(MethodCall mc |
27-
mc.getTarget().hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store", "Add")
28-
and sink.asExpr() = mc.getQualifier()
26+
(mc.getTarget().hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store", "Add") or
27+
mc.getTarget().hasQualifiedName("System.Security.Cryptography.X509Certificates.X509Store", "AddRange")) and
28+
sink.asExpr() = mc.getQualifier()
2929
)
3030
}
3131
}
3232

3333
from Expr oc, Expr mc, AddCertToRootStoreConfig config
3434
where config.hasFlow(DataFlow::exprNode(oc), DataFlow::exprNode(mc))
35-
select mc, "Do not add certificates to root certificate store"
35+
select mc, "Certificate added to the root certificate store. Do not add certificates to root certificate store."
3636

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
| Test.cs:19:13:19:17 | access to local variable store | Do not add certificates to root certificate store |
2-
| Test.cs:28:13:28:17 | access to local variable store | Do not add certificates to root certificate store |
1+
| Test.cs:19:13:19:17 | access to local variable store | Certificate added to the root certificate store. Do not add certificates to root certificate store. |
2+
| Test.cs:28:13:28:17 | access to local variable store | Certificate added to the root certificate store. Do not add certificates to root certificate store. |
3+
| Test.cs:69:13:69:17 | access to local variable store | Certificate added to the root certificate store. Do not add certificates to root certificate store. |

csharp/ql/test/query-tests/Security Features/CWE-327/DontInstallRootCert/Test.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,19 @@ public void RemoveRootCert()
5555
store.Remove(new X509Certificate2(X509Certificate2.CreateFromCertFile(file)));
5656
store.Close();
5757
}
58+
59+
public void InstallRoorCertRange()
60+
{
61+
string file1 = "mytest1.pfx"; // Contains name of certificate file
62+
string file2 = "mytest2.pfx"; // Contains name of certificate file
63+
var certCollection = new X509Certificate2[] {
64+
new X509Certificate2(X509Certificate2.CreateFromCertFile(file1)),
65+
new X509Certificate2(X509Certificate2.CreateFromCertFile(file2)),
66+
};
67+
X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
68+
store.Open(OpenFlags.ReadWrite);
69+
store.AddRange(new X509Certificate2Collection(certCollection));
70+
store.Close();
71+
}
5872
}
5973
}

0 commit comments

Comments
 (0)