Skip to content

Commit 1aa5e24

Browse files
committed
C#: Remove duplicate results from cs/use-of-vulnerable-package
1 parent 0647743 commit 1aa5e24

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

csharp/ql/src/Security Features/CWE-937/Vulnerability.qll

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ class Package extends XMLElement {
4141
abstract class Vulnerability extends string {
4242
bindingset[this]
4343
Vulnerability() { any() }
44-
44+
4545
/**
4646
* Holds if a package with name `name` is vulnerable from version `affected`
4747
* until version `fixed`.
4848
*/
4949
predicate matchesRange(string name, Version affected, Version fixed) { none() }
50-
50+
5151
/**
5252
* Holds if a package with name `name` is vulnerable in version `affected`, and
5353
* is fixed by version `fixed`.
5454
*/
5555
predicate matchesVersion(string name, Version affected, Version fixed) { none() }
56-
56+
5757
/** Gets the URL describing the vulnerability. */
5858
abstract string getUrl();
59-
59+
6060
/**
6161
* Holds if a package with name `name` and version `version`
6262
* has this vulnerability. The fixed version is given by `fixed`.
@@ -75,20 +75,28 @@ abstract class Vulnerability extends string {
7575
}
7676
}
7777

78+
bindingset[name, version]
79+
private Version getUltimateFix(string name, Version version) {
80+
result = max(Version fix | any(Vulnerability v).isVulnerable(name, version, fix))
81+
}
82+
7883
/**
7984
* A package with a vulnerability.
8085
*/
8186
class VulnerablePackage extends Package {
8287
Vulnerability vuln;
83-
Version fixed;
84-
88+
8589
VulnerablePackage() {
86-
vuln.isVulnerable(this.getPackageName(), this.getVersion(), fixed)
90+
vuln.isVulnerable(this.getPackageName(), this.getVersion(), _)
8791
}
88-
92+
8993
/** Gets the vulnerability of this package. */
9094
Vulnerability getVulnerability() { result = vuln }
91-
95+
9296
/** Gets the version of this package where the vulnerability is fixed. */
93-
Version getFixedVersion() { result = fixed }
97+
Version getFixedVersion() {
98+
// This is needed because sometimes the "fixed" version of some
99+
// vulnerabilities are themselves vulnerable to other vulnerabilities.
100+
result = getUltimateFix(this.getPackageName(), this.getVersion())
101+
}
94102
}

csharp/ql/test/query-tests/Security Features/CWE-937/VulnerablePackage.expected

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
| csproj.config:11:5:11:75 | system.text.encodings.web 4.3 | Package 'system.text.encodings.web 4.3' has vulnerability $@, and should be upgraded to version 4.3.1. | https://github.com/dotnet/corefx/issues/19535 | Microsoft Security Advisory 4021279 |
33
| csproj.config:12:5:12:67 | System.Net.Http 4.1.1 | Package 'System.Net.Http 4.1.1' has vulnerability $@, and should be upgraded to version 4.1.2. | https://github.com/dotnet/corefx/issues/19535 | Microsoft Security Advisory 4021279 |
44
| csproj.config:13:5:13:67 | System.Net.Http 4.1.2 | Package 'System.Net.Http 4.1.2' has vulnerability $@, and should be upgraded to version 4.3.4. | https://github.com/dotnet/announcements/issues/88 | CVE-2018-8292 |
5-
| packages.config:8:3:8:79 | System.IO.Pipelines 4.5.0 | Package 'System.IO.Pipelines 4.5.0' has vulnerability $@, and should be upgraded to version 4.5.1. | https://github.com/aspnet/Announcements/issues/316 | CVE-2018-8409 |
6-
| packages.config:9:3:9:81 | System.IO.Pipelines 4.5.0.0 | Package 'System.IO.Pipelines 4.5.0.0' has vulnerability $@, and should be upgraded to version 4.5.1. | https://github.com/aspnet/Announcements/issues/316 | CVE-2018-8409 |
5+
| packages.config:9:3:9:79 | System.IO.Pipelines 4.5.0 | Package 'System.IO.Pipelines 4.5.0' has vulnerability $@, and should be upgraded to version 4.5.1. | https://github.com/aspnet/Announcements/issues/316 | CVE-2018-8409 |
6+
| packages.config:10:3:10:81 | System.IO.Pipelines 4.5.0.0 | Package 'System.IO.Pipelines 4.5.0.0' has vulnerability $@, and should be upgraded to version 4.5.1. | https://github.com/aspnet/Announcements/issues/316 | CVE-2018-8409 |
7+
| packages.config:11:3:11:84 | microsoft.aspnetcore.all 2.0.0 | Package 'microsoft.aspnetcore.all 2.0.0' has vulnerability $@, and should be upgraded to version 2.0.9. | https://github.com/aspnet/Announcements/issues/300 | ASPNETCore-Mar18 |
8+
| packages.config:11:3:11:84 | microsoft.aspnetcore.all 2.0.0 | Package 'microsoft.aspnetcore.all 2.0.0' has vulnerability $@, and should be upgraded to version 2.0.9. | https://github.com/aspnet/Announcements/issues/311 | ASPNETCore-July18 |
9+
| packages.config:12:3:12:84 | Microsoft.AspNetCore.All 2.0.8 | Package 'Microsoft.AspNetCore.All 2.0.8' has vulnerability $@, and should be upgraded to version 2.0.9. | https://github.com/aspnet/Announcements/issues/311 | ASPNETCore-July18 |

csharp/ql/test/query-tests/Security Features/CWE-937/packages.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
<!-- These are GOOD -->
44
<package id="System.IO.Pipelines" version="4.5.1" targetFramework="net45" />
55
<package id="System.IO.Pipelines" version="4.5.1.0" targetFramework="net45" />
6-
6+
<package id="Microsoft.AspNetCore.All" version="2.0.9" targetFramework="net45" />
7+
78
<!-- These are BAD -->
89
<package id="System.IO.Pipelines" version="4.5.0" targetFramework="net45" />
910
<package id="System.IO.Pipelines" version="4.5.0.0" targetFramework="net45" />
11+
<package id="microsoft.aspnetcore.all" version="2.0.0" targetFramework="net45" />
12+
<package id="Microsoft.AspNetCore.All" version="2.0.8" targetFramework="net45" />
1013
</packages>

0 commit comments

Comments
 (0)