Skip to content

Commit

Permalink
Updates to Populate Sarif Fields for GitHub Severity + Precision (#606)
Browse files Browse the repository at this point in the history
* Update dependencies

* Improve Confidence Reporting

Adds Confidence Field to Issue Record
Sets Confidence to either Confidence of Pattern if specified, or confidence of overall rule if specified
Report Confidence and Severity in special Github sarif fields.
Add Confidence values to rules

* Update Guidance (#600)
Fixed typo
Tokens/keys in source code
DES->AES Guidance

* Update Changelog.md
---------

Co-authored-by: Cristián Rojas <[email protected]>
  • Loading branch information
gfs and injcristianrojas authored Feb 29, 2024
1 parent d08607c commit b08bf6e
Show file tree
Hide file tree
Showing 59 changed files with 200 additions and 11 deletions.
13 changes: 13 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.31] - 2024-1-28
### Sarif Format
Populate additional fields for GitHub Code scanning

### Rules
Populate Confidence values for rules

### Dependencies
Update Dependencies

### Engine
Prioritize confidence value from Pattern level in Issue records but fall back to rule level if not specified.

## [1.0.30] - 2024-1-31
### Pipeline
Additional pipeline fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="LibGit2Sharp" Version="0.29.0" />
<PackageReference Include="Microsoft.CST.ApplicationInspector.Logging" Version="1.9.18" />
<PackageReference Include="Microsoft.CST.ApplicationInspector.Logging" Version="1.9.19" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Sarif.Sdk" Version="4.4.0" />
<PackageReference Include="Sarif.Sdk" Version="4.5.3" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,36 @@ private void AddRuleToSarifRule(DevSkimRule devskimRule)
Enabled = true,
Level = DevSkimLevelToSarifLevel(devskimRule.Severity)
};
// Set github code scanning properties
sarifRule.SetProperty("precision", ConfidenceToPrecision(devskimRule.Confidence));
sarifRule.SetProperty("problem.severity", DevSkimLevelToGitHubLevel(devskimRule.Severity));
sarifRule.SetProperty("DevSkimSeverity", devskimRule.Severity.ToString());
sarifRule.SetProperty("DevSkimConfidence", devskimRule.Confidence.ToString());

_rules.TryAdd(devskimRule.Id, sarifRule);
}
}

private object DevSkimLevelToGitHubLevel(Severity severity) => severity switch
{
Severity.Unspecified => string.Empty,
Severity.Critical => "error",
Severity.Important => "warning",
Severity.Moderate => "warning",
Severity.BestPractice => "recommendation",
Severity.ManualReview => "recommendation",
_ => string.Empty,
};

private static string ConfidenceToPrecision(Confidence confidence) => confidence switch
{
Confidence.High => "high",
Confidence.Medium => "medium",
Confidence.Low => "low",
Confidence.Unspecified => string.Empty,
_ => string.Empty
};

private string ToSarifFriendlyName(string devskimRuleName) =>
string.Concat(devskimRuleName.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.Select(x => string.Concat(x.Where(char.IsLetterOrDigit)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Client">
<Version>17.8.36</Version>
<Version>17.9.46</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol">
<Version>17.2.8</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.8.37222" ExcludeAssets="runtime">
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.9.37000" ExcludeAssets="runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.8.2365">
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.9.3168">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 3 additions & 0 deletions DevSkim-DotNet/Microsoft.DevSkim/DevSkimRuleProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public IEnumerable<Issue> Analyze(string text, string fileName)
StartLocation: textContainer.GetLocation(matchRecord.Boundary.Index),
EndLocation: textContainer.GetLocation(matchRecord.Boundary.Index + matchRecord.Boundary.Length),
Rule: devSkimRule);
// Match record confidence is based on pattern confidence (from AI engine)
// As a backup, DevSkim Rules may also have an overall confidence specified for the rule, use that when match confidence undefined
issue.Confidence = matchRecord.Confidence == Confidence.Unspecified ? devSkimRule.Confidence : matchRecord.Confidence;
if (_processorOptions.EnableSuppressions)
{
Suppression supp = new(textContainer, issue.StartLocation.Line);
Expand Down
4 changes: 4 additions & 0 deletions DevSkim-DotNet/Microsoft.DevSkim/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ public Issue(Boundary Boundary, Location StartLocation, Location EndLocation, De
/// Location (line, column) where issue starts
/// </summary>
public Location StartLocation { get; set; }
/// <summary>
/// Confidence level of match
/// </summary>
public Confidence Confidence { get; internal set; }
}
}
2 changes: 1 addition & 1 deletion DevSkim-DotNet/Microsoft.DevSkim/Microsoft.DevSkim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CST.ApplicationInspector.RulesEngine" Version="1.9.18" />
<PackageReference Include="Microsoft.CST.ApplicationInspector.RulesEngine" Version="1.9.19" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions guidance/DS106864.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ anywhere.
In general, the [Advanced Encryption Standard](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard),
or AES, algorithm, is preferred for all cases where symmetric encryption is needed.

#### Solution

##### .NET

Use the following method: `System.Security.Cryptography.Aes.Create()`

### Implementation

#### C# / .NET
Expand Down
2 changes: 1 addition & 1 deletion guidance/DS113286.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Do not include user-input directoy in format strings
## Do not include user-input directly in format strings

### Summary
Do not create NSString objects using a user-provided format string, as this could lead to a security vulnerability. https://www.securecoding.cert.org/confluence/display/c/FIO30-C.+Exclude+user+input+from+format+strings
Expand Down
17 changes: 15 additions & 2 deletions guidance/DS117838.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
A token or key was found in source code. If this represents a secret, it should be moved somewhere else.

### Details
TO DO - put more details of problem and solution here

Secrets in source code pose a threat to the application's components, like
databases and other users, especially if this source code is leaked or shared.
This applies to:

* Users/passwords
* Tokens (JWT's, etc.)
* Hashes
* Encryption keys

### Severity Considerations
TO DO - put more details on the severity of the issue here. Generally how big of a problem is this, and what makes it more or less of a problem?

Follow these steps:

* Change passwords/keys/secrets on the target components.
* Store them in a secrets vault
* Remove them from your code.

1 change: 1 addition & 0 deletions rules/default/correctness/datetime.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"rule_info": "",
"patterns": [
{
"confidence": "high",
"pattern": "(%Y-%M-%d)|(%M-%d-%Y)|(%M/%d/%Y)",
"type": "regex",
"scopes": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_appconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS112838.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_appcontext.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_cobol.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_functioncall.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
9 changes: 9 additions & 0 deletions rules/default/security/TLS/tls_generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"overrides": [
"DS440000"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440001.md",
"patterns": [
Expand Down Expand Up @@ -58,6 +59,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"_comment": "Applies to all languages since many just wrap OpenSSL constructs.",
"rule_info": "DS440001.md",
Expand Down Expand Up @@ -127,6 +129,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"_comment": "Applies to all languages since many just wrap OpenSSL constructs.",
"rule_info": "DS440001.md",
Expand Down Expand Up @@ -156,6 +159,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"_comment": "Applies to all languages since many just wrap GnuTLS constructs.",
"rule_info": "DS440001.md",
Expand Down Expand Up @@ -185,6 +189,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"_comment": "Applies to all languages since many just wrap LibreSSL constructs.",
"rule_info": "DS440001.md",
Expand Down Expand Up @@ -214,6 +219,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"_comment": "Applies to all languages since many just wrap mbedTLS constructs.",
"rule_info": "DS440001.md",
Expand Down Expand Up @@ -251,6 +257,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440001.md",
"patterns": [
Expand Down Expand Up @@ -293,6 +300,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440001.md",
"patterns": [
Expand Down Expand Up @@ -364,6 +372,7 @@
"tags": [
"Cryptography.Protocol.TLS.Elliptic-Curve.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440001.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_go.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
2 changes: 2 additions & 0 deletions rules/default/security/TLS/tls_java.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down Expand Up @@ -55,6 +56,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"_comment": "Generic, since there are multiple languages that bind to these constants.",
"rule_info": "DS440000.md",
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_python.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_rust.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_securityprotocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS112835.md",
"patterns": [
Expand Down
1 change: 1 addition & 0 deletions rules/default/security/TLS/tls_sslprotocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
4 changes: 4 additions & 0 deletions rules/default/security/TLS/tls_win32.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down Expand Up @@ -43,6 +44,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down Expand Up @@ -71,6 +73,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down Expand Up @@ -155,6 +158,7 @@
"tags": [
"Cryptography.Protocol.TLS.Hard-Coded"
],
"confidence": "high",
"severity": "ManualReview",
"rule_info": "DS440000.md",
"patterns": [
Expand Down
Loading

0 comments on commit b08bf6e

Please sign in to comment.