Skip to content

Commit b08bf6e

Browse files
Updates to Populate Sarif Fields for GitHub Severity + Precision (#606)
* 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]>
1 parent d08607c commit b08bf6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+200
-11
lines changed

Changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.0.31] - 2024-1-28
8+
### Sarif Format
9+
Populate additional fields for GitHub Code scanning
10+
11+
### Rules
12+
Populate Confidence values for rules
13+
14+
### Dependencies
15+
Update Dependencies
16+
17+
### Engine
18+
Prioritize confidence value from Pattern level in Issue records but fall back to rule level if not specified.
19+
720
## [1.0.30] - 2024-1-31
821
### Pipeline
922
Additional pipeline fixes

DevSkim-DotNet/Microsoft.DevSkim.CLI/Microsoft.DevSkim.CLI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
<ItemGroup>
3838
<PackageReference Include="CommandLineParser" Version="2.9.1" />
3939
<PackageReference Include="LibGit2Sharp" Version="0.29.0" />
40-
<PackageReference Include="Microsoft.CST.ApplicationInspector.Logging" Version="1.9.18" />
40+
<PackageReference Include="Microsoft.CST.ApplicationInspector.Logging" Version="1.9.19" />
4141
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
42-
<PackageReference Include="Sarif.Sdk" Version="4.4.0" />
42+
<PackageReference Include="Sarif.Sdk" Version="4.5.3" />
4343
</ItemGroup>
4444

4545
</Project>

DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,36 @@ private void AddRuleToSarifRule(DevSkimRule devskimRule)
213213
Enabled = true,
214214
Level = DevSkimLevelToSarifLevel(devskimRule.Severity)
215215
};
216+
// Set github code scanning properties
217+
sarifRule.SetProperty("precision", ConfidenceToPrecision(devskimRule.Confidence));
218+
sarifRule.SetProperty("problem.severity", DevSkimLevelToGitHubLevel(devskimRule.Severity));
216219
sarifRule.SetProperty("DevSkimSeverity", devskimRule.Severity.ToString());
217220
sarifRule.SetProperty("DevSkimConfidence", devskimRule.Confidence.ToString());
218221

219222
_rules.TryAdd(devskimRule.Id, sarifRule);
220223
}
221224
}
222225

226+
private object DevSkimLevelToGitHubLevel(Severity severity) => severity switch
227+
{
228+
Severity.Unspecified => string.Empty,
229+
Severity.Critical => "error",
230+
Severity.Important => "warning",
231+
Severity.Moderate => "warning",
232+
Severity.BestPractice => "recommendation",
233+
Severity.ManualReview => "recommendation",
234+
_ => string.Empty,
235+
};
236+
237+
private static string ConfidenceToPrecision(Confidence confidence) => confidence switch
238+
{
239+
Confidence.High => "high",
240+
Confidence.Medium => "medium",
241+
Confidence.Low => "low",
242+
Confidence.Unspecified => string.Empty,
243+
_ => string.Empty
244+
};
245+
223246
private string ToSarifFriendlyName(string devskimRuleName) =>
224247
string.Concat(devskimRuleName.Split(' ', StringSplitOptions.RemoveEmptyEntries)
225248
.Select(x => string.Concat(x.Where(char.IsLetterOrDigit)))

DevSkim-DotNet/Microsoft.DevSkim.Tests/Microsoft.DevSkim.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
13-
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
14-
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
13+
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
14+
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/Microsoft.DevSkim.VisualStudio.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@
8787
<ItemGroup>
8888
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
8989
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Client">
90-
<Version>17.8.36</Version>
90+
<Version>17.9.46</Version>
9191
</PackageReference>
9292
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol">
9393
<Version>17.2.8</Version>
9494
</PackageReference>
95-
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.8.37222" ExcludeAssets="runtime">
95+
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.9.37000" ExcludeAssets="runtime">
9696
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9797
</PackageReference>
98-
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.8.2365">
98+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.9.3168">
9999
<PrivateAssets>all</PrivateAssets>
100100
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
101101
</PackageReference>

DevSkim-DotNet/Microsoft.DevSkim/DevSkimRuleProcessor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public IEnumerable<Issue> Analyze(string text, string fileName)
4141
StartLocation: textContainer.GetLocation(matchRecord.Boundary.Index),
4242
EndLocation: textContainer.GetLocation(matchRecord.Boundary.Index + matchRecord.Boundary.Length),
4343
Rule: devSkimRule);
44+
// Match record confidence is based on pattern confidence (from AI engine)
45+
// As a backup, DevSkim Rules may also have an overall confidence specified for the rule, use that when match confidence undefined
46+
issue.Confidence = matchRecord.Confidence == Confidence.Unspecified ? devSkimRule.Confidence : matchRecord.Confidence;
4447
if (_processorOptions.EnableSuppressions)
4548
{
4649
Suppression supp = new(textContainer, issue.StartLocation.Line);

DevSkim-DotNet/Microsoft.DevSkim/Issue.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@ public Issue(Boundary Boundary, Location StartLocation, Location EndLocation, De
4141
/// Location (line, column) where issue starts
4242
/// </summary>
4343
public Location StartLocation { get; set; }
44+
/// <summary>
45+
/// Confidence level of match
46+
/// </summary>
47+
public Confidence Confidence { get; internal set; }
4448
}
4549
}

DevSkim-DotNet/Microsoft.DevSkim/Microsoft.DevSkim.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<PackageReference Include="Microsoft.CST.ApplicationInspector.RulesEngine" Version="1.9.18" />
27+
<PackageReference Include="Microsoft.CST.ApplicationInspector.RulesEngine" Version="1.9.19" />
2828
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2929
</ItemGroup>
3030

guidance/DS106864.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ anywhere.
1111
In general, the [Advanced Encryption Standard](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard),
1212
or AES, algorithm, is preferred for all cases where symmetric encryption is needed.
1313

14+
#### Solution
15+
16+
##### .NET
17+
18+
Use the following method: `System.Security.Cryptography.Aes.Create()`
19+
1420
### Implementation
1521

1622
#### C# / .NET

guidance/DS113286.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Do not include user-input directoy in format strings
1+
## Do not include user-input directly in format strings
22

33
### Summary
44
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

0 commit comments

Comments
 (0)