Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: #2560 DateTime Query Evaluator #2561

Closed
wants to merge 91 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
0a68231
Feature: Added GUID list and query suppression support
aguggenberger-ps Aug 3, 2022
a08d8da
Fixed bug: suppress options with guids type
aguggenberger Aug 3, 2022
4c62456
fixed bug in SuppressOptions with guids options
aguggenberger Aug 3, 2022
6f0174e
Bug: Allowed using results-guids and expression arguments together.
aguggenberger Aug 4, 2022
8c80a87
chore: typo in log message
ejohn20 Aug 5, 2022
4b91d6b
feat: console log number of suppressions applied
ejohn20 Aug 5, 2022
46e65de
bug: comma delimit results arg
ejohn20 Aug 5, 2022
15ec413
feat: cis cat pro json converter
ejohn20 Aug 8, 2022
e366b48
bug: exclude passing tests from results for match forward baseline st…
ejohn20 Aug 9, 2022
aefdd5e
Fixed bug with ResultsGuids and added debug output
aguggenberger Aug 9, 2022
407183c
fixed bug with ResultsGuids union to Query guids
aguggenberger Aug 9, 2022
723140b
WIP - Added IsSuppressed evaluator and updated unit tests
aguggenberger Aug 11, 2022
3f84ae4
feat: nessus converter v0
ejohn20 Aug 11, 2022
bec3834
bug: fingerprint targetid + empty plugin output
ejohn20 Aug 12, 2022
ebd4bd2
Merge branch 'main' into suppression-updates
ejohn20 Aug 12, 2022
f1558f5
Merge pull request #1 from pumasecurity/suppression-updates
ejohn20 Aug 12, 2022
c1fae87
Merge branch 'feature/cis-cat-converter' into feature/2531/nessus-cis…
ejohn20 Aug 14, 2022
92397b4
Merge pull request #2 from pumasecurity/feature/2531/nessus-cis-cat
ejohn20 Aug 14, 2022
2a250aa
feat: cis cat unit tests
ejohn20 Aug 15, 2022
2304ccd
feat: nessus unit tests
ejohn20 Aug 15, 2022
e5b349c
Merge pull request #3 from pumasecurity/feature/2531/nessus-cis-cat
ejohn20 Aug 16, 2022
d2c9e4e
Merge branch 'microsoft:main' into main
ejohn20 Aug 16, 2022
56d0849
feat: cis cat pro json converter
ejohn20 Aug 8, 2022
f94940f
bug: exclude passing tests from results for match forward baseline st…
ejohn20 Aug 9, 2022
92b8d44
feat: nessus converter v0
ejohn20 Aug 11, 2022
ce1485f
bug: fingerprint targetid + empty plugin output
ejohn20 Aug 12, 2022
adcc11b
feat: cis cat unit tests
ejohn20 Aug 15, 2022
e327ed5
feat: nessus unit tests
ejohn20 Aug 15, 2022
af47e6b
Merge branch 'main' into 2531/converter-nessus-cis-cat
ejohn20 Aug 16, 2022
f1bf268
bug: omit 0 severity results + cvss override
ejohn20 Aug 16, 2022
3b611d1
Merge pull request #5 from pumasecurity/2531/converter-nessus-cis-cat
ejohn20 Aug 16, 2022
39dd8ef
chore: ignore ds store
ejohn20 Aug 19, 2022
256f0fc
Merge branch 'microsoft:main' into main
ejohn20 Aug 19, 2022
9978c2f
Fixed: Changes requested for #2530
aguggenberger Aug 23, 2022
f2caacf
Merge branch 'main' into release
ejohn20 Aug 23, 2022
61a40d7
Merge pull request #7 from pumasecurity/feature/3.0.0
ejohn20 Aug 23, 2022
11758bd
Merge branch 'main' into suppression-updates
aguggenberger Aug 23, 2022
7b9633f
bug: validate result guid values are not whitespace
ejohn20 Aug 23, 2022
2db4ef0
bug: validate result guid values are not whitespace
ejohn20 Aug 23, 2022
717ae81
bug: cis cat set unknown status to warning
ejohn20 Aug 24, 2022
80a03d0
bug: cis cat set unknown status to warning
ejohn20 Aug 24, 2022
ee26de3
Feature: Add GenericSarifConvter to meet validation
aguggenberger Aug 25, 2022
2d69e79
test: GenericSarifConverter unit tests
aguggenberger-ps Aug 25, 2022
e642f68
chore: cleaned up code
aguggenberger Aug 25, 2022
ac4e74d
Merge pull request #8 from pumasecurity/generic-sarif-converter
ejohn20 Aug 28, 2022
65c654b
feat: set rank for critical capability
ejohn20 Aug 29, 2022
85523af
Merge branch 'release' of github.com:pumasecurity/sarif-sdk into release
ejohn20 Aug 29, 2022
f50d46b
chore: update test cases
ejohn20 Aug 29, 2022
982b156
feat: set rank for critical capability
ejohn20 Aug 29, 2022
da4c735
chore: update test cases
ejohn20 Aug 29, 2022
bd9004e
bug: empty search suppresses all results
ejohn20 Sep 5, 2022
63504c1
bug: skip duplicate suppression entries
ejohn20 Sep 5, 2022
7ccd409
Merge pull request #9 from pumasecurity/bug/suppression-duplicates
aguggenberger Sep 5, 2022
9829d17
Merge branch 'suppression-updates' into release
ejohn20 Sep 5, 2022
ebd7327
bug: suppress visitor multiple test cases
ejohn20 Sep 7, 2022
ce5ebb0
Merge branch 'suppression-updates' into release
ejohn20 Sep 7, 2022
2d226b4
bug: fixed merge command unit test failure
ejohn20 Sep 7, 2022
43104be
chore: formatting failures
ejohn20 Sep 7, 2022
696b57a
Merge branch 'suppression-updates' into release
ejohn20 Sep 7, 2022
8361a60
feat: suppress expiryUtc command argument
ejohn20 Sep 8, 2022
5745a87
Merge branch 'feature/expiry-date' into release
ejohn20 Sep 8, 2022
a4446d9
bug: reverted bad test data
ejohn20 Sep 8, 2022
3b5c76d
Merge branch 'feature/expiry-date' into release
ejohn20 Sep 8, 2022
366bdde
chore: codeql cleanup
ejohn20 Sep 20, 2022
8269738
chore: dotnet format errors
ejohn20 Sep 20, 2022
822c89c
Merge branch 'main' into 2531/converter-nessus-cis-cat
ejohn20 Sep 20, 2022
d90b625
chore: dotnet format errors
ejohn20 Sep 20, 2022
fe1f447
chore: codeql cleanup
ejohn20 Sep 20, 2022
1279674
Merge pull request #11 from pumasecurity/main
ejohn20 Sep 20, 2022
2cbdeeb
feat: snyk oss converter
ejohn20 Sep 20, 2022
56697c5
Merge branch 'converter/snyk-oss' into release
ejohn20 Sep 20, 2022
aefe2e5
bug: write entire sarif log to avoid location index + artifact compar…
ejohn20 Sep 21, 2022
7bd9d8d
Merge branch 'converter/snyk-oss' into release
ejohn20 Sep 21, 2022
9ad77d1
bug: fingerprint package mgr
ejohn20 Sep 21, 2022
efa033d
Merge branch 'converter/snyk-oss' into release
ejohn20 Sep 21, 2022
0014752
bug: null help block if no data
ejohn20 Sep 22, 2022
c86603b
chore: docs
ejohn20 Sep 22, 2022
245831b
bug: suppression expiration no expiry logic flaw
ejohn20 Sep 23, 2022
d93fa19
docs: release notes + query mode updates
ejohn20 Sep 23, 2022
d3f477c
bug: snyk report single test support
ejohn20 Oct 25, 2022
5deb2cb
Merge pull request #12 from pumasecurity/main
ejohn20 Oct 25, 2022
2619b3a
Merge pull request #13 from pumasecurity/bug/synk-oss-single-result
ejohn20 Oct 25, 2022
e27540a
feat: version suffix build prop
ejohn20 Oct 25, 2022
99dafc8
Merge branch 'release' of github.com:pumasecurity/sarif-sdk into release
ejohn20 Oct 25, 2022
f8a7a46
feat: gh property tags
ejohn20 Oct 25, 2022
bc52189
Merge pull request #14 from pumasecurity/2531/converter-nessus-cis-cat
ejohn20 Oct 25, 2022
88107e0
chore: query docs
ejohn20 Oct 26, 2022
6cf080a
feat: date time property evaluator
ejohn20 Oct 26, 2022
dddffa4
bug: null location guard check
ejohn20 Oct 26, 2022
81f02a7
feat: enhanced query command test suite
ejohn20 Oct 26, 2022
a795595
Merge pull request #15 from pumasecurity/2560/datetime-compare
ejohn20 Oct 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,5 @@ FakesAssemblies/
# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
ModelManifest.xml
*.DS_Store
7 changes: 7 additions & 0 deletions docs/multitool-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,26 @@ Sarif.Multitool validate Other.sarif
```

## Supported Converters

Run ```Sarif.Multitool convert --help``` for the current list.

- AndroidStudio
- CisCat
- ClangAnalyzer
- ClangTidy
- CppCheck
- ContrastSecurity
- FlawFinder
- Fortify
- FortifyFpr
- FxCop
- GenericSarif
- Hdf
- Nessus
- PREfast
- Pylint
- SemmleQL
- SnykOpenSource
- StaticDriverVerifier
- TSLint

Expand Down
3 changes: 3 additions & 0 deletions docs/query-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ NOT RuleId = SM00251 OR OccurrenceCount > 10 AND OccurrenceCount < 100
* CorrelationGuid
* Guid
* HostedViewerUri
* IsSuppressed
* Kind
* Level
* Message.Text
* OccurrenceCount
* properties.[value]
* Rank
* rule.properties.[value]
* RuleId
* Uri
2 changes: 2 additions & 0 deletions src/ReleaseHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* BUGFIX: Update `merge` command to properly produce runs by tool and version when passed the `--merge-runs` argument. [#2488](https://github.com/microsoft/sarif-sdk/pull/2488)
* BUGFIX: Eliminate `IOException` and `DirectoryNotFoundException` exceptions thrown by `merge` command when splitting by rule (due to invalid file characters in rule ids). [#2513](https://github.com/microsoft/sarif-sdk/pull/2513)
* BUGFIX: Fix classes inside NotYetAutoGenerated folder missing `virtual` keyword for public methods and properties, by regenerate and manually sync the changes. [#2537](https://github.com/microsoft/sarif-sdk/pull/2537)
* FEATURE: Enhancement to the `suppress` command to better support auditing results. New argument `--expression` provides the capability to suppress all results matching the expression. New argument `--results-guids` provides the capability to suppress one to many results by the `guid` value. With this update, previously suppressed (non-expired) results will not be suppressed again. [#2530](https://github.com/microsoft/sarif-sdk/pull/2530)
* FEATURE: Enhancement to the `query` command adding a new `IsSuppressed` expression option. This query expression allows auditors to filter results based on their suppression status. The expression finds all suppressed (non-expired) results. [#2530](https://github.com/microsoft/sarif-sdk/pull/2530)

## **v3.1.0** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/3.1.0) | [Driver](https://www.nuget.org/packages/Sarif.Driver/3.1.0) | [Converters](https://www.nuget.org/packages/Sarif.Converters/3.1.0) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/3.1.0) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/3.1.0)

Expand Down
4 changes: 4 additions & 0 deletions src/Sarif.Converters/BuiltInConverterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static Dictionary<string, Lazy<ToolFileConverterBase>> CreateBuiltInConv
{
var result = new Dictionary<string, Lazy<ToolFileConverterBase>>();
CreateConverterRecord<AndroidStudioConverter>(result, ToolFormat.AndroidStudio);
CreateConverterRecord<CisCatConverter>(result, ToolFormat.CisCat);
CreateConverterRecord<CppCheckConverter>(result, ToolFormat.CppCheck);
CreateConverterRecord<ClangAnalyzerConverter>(result, ToolFormat.ClangAnalyzer);
CreateConverterRecord<ClangTidyConverter>(result, ToolFormat.ClangTidy);
Expand All @@ -33,9 +34,12 @@ private static Dictionary<string, Lazy<ToolFileConverterBase>> CreateBuiltInConv
CreateConverterRecord<FortifyFprConverter>(result, ToolFormat.FortifyFpr);
CreateConverterRecord<FxCopConverter>(result, ToolFormat.FxCop);
CreateConverterRecord<FlawFinderConverter>(result, ToolFormat.FlawFinder);
CreateConverterRecord<GenericSarifConverter>(result, ToolFormat.GenericSarif);
CreateConverterRecord<HdfConverter>(result, ToolFormat.Hdf);
CreateConverterRecord<NessusConverter>(result, ToolFormat.Nessus);
CreateConverterRecord<PREfastConverter>(result, ToolFormat.PREfast);
CreateConverterRecord<PylintConverter>(result, ToolFormat.Pylint);
CreateConverterRecord<SnykOpenSourceConverter>(result, ToolFormat.SnykOpenSource);
CreateConverterRecord<SemmleQLConverter>(result, ToolFormat.SemmleQL);
CreateConverterRecord<StaticDriverVerifierConverter>(result, ToolFormat.StaticDriverVerifier);
CreateConverterRecord<TSLintConverter>(result, ToolFormat.TSLint);
Expand Down
188 changes: 188 additions & 0 deletions src/Sarif.Converters/CisCatConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.CodeAnalysis.Sarif.Converters.CisCatObjectModel;

namespace Microsoft.CodeAnalysis.Sarif.Converters
{
public class CisCatConverter : ToolFileConverterBase
{
private readonly LogReader<CisCatReport> logReader;

public CisCatConverter()
{
logReader = new CisCatReportReader();
}

public override string ToolName => ToolFormat.CisCat;

public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert)
{
input = input ?? throw new ArgumentNullException(nameof(input));
output = output ?? throw new ArgumentNullException(nameof(output));

//Read CIS CAT data
CisCatReport log = logReader.ReadLog(input);

//Top level run object for the scan data
var run = new Run();

//Set the tool details
run.Tool = new Tool();
run.Tool.Driver = CreateDriver(log);

//Set the list of tool rules
run.Tool.Driver.Rules = new List<ReportingDescriptor>();
foreach (CisCatRule rule in log.Rules)
{
run.Tool.Driver.Rules.Add(CreateReportDescriptor(rule));
}

var results = new List<Result>();
foreach (CisCatRule rule in log.Rules.Where(i => !i.IsPass()))
{
results.Add(CreateResult(rule));
}

PersistResults(output, results, run);
}

internal ToolComponent CreateDriver(CisCatReport report)
{

var driver = new ToolComponent();

driver.Name = this.ToolName;
driver.FullName = report.BenchmarkTitle;
driver.Version = report.BenchmarkVersion;
driver.SemanticVersion = report.BenchmarkVersion;
driver.InformationUri = new Uri("https://www.cisecurity.org/cybersecurity-tools/cis-cat-pro_pre");

driver.SetProperty("benchmarkId", report.BenchmarkId);
driver.SetProperty("profileId", report.ProfileId);
driver.SetProperty("profileTitle", report.ProfileTitle);
driver.SetProperty("score", report.Score);

return driver;
}

internal ReportingDescriptor CreateReportDescriptor(CisCatRule rule)
{
ReportingDescriptor descriptor = new ReportingDescriptor();

descriptor.Id = rule.RuleId;
descriptor.Name = rule.RuleTitle;
descriptor.ShortDescription = new MultiformatMessageString()
{
Text = rule.RuleTitle,
Markdown = rule.RuleTitle,
};
descriptor.FullDescription = new MultiformatMessageString()
{
Text = rule.RuleTitle,
Markdown = rule.RuleTitle,
};
descriptor.Help = new MultiformatMessageString()
{
Text = rule.RuleTitle,
Markdown = rule.RuleTitle,
};

//Use for GH Security Advisories
//set result level and rank (Critical - Low risk rating)
FailureLevel level = FailureLevel.None;
ResultKind kind = ResultKind.None;
double rank = RankConstants.None;
getResultSeverity(rule.Result, out level, out kind, out rank);

//Create only if a valid is assigned
if (rank != RankConstants.None)
{
descriptor.SetProperty("security-severity", rank);
}

//Tags for GH filtering
var tags = new List<string>()
{
"security",
};

descriptor.SetProperty("tags", tags);

return descriptor;
}

internal Result CreateResult(CisCatRule rule)
{
//set the result metadata
Result result = new Result
{
RuleId = rule.RuleId,
Message = new Message { Text = rule.RuleTitle },
};

//set result kind, level and rank (Critical - Low risk rating)
FailureLevel level = FailureLevel.None;
ResultKind kind = ResultKind.None;
double rank = RankConstants.None;
getResultSeverity(rule.Result, out level, out kind, out rank);

//Set result object data
result.Level = level;
result.Kind = kind;
result.Rank = rank;

//Set the unique fingerprint
result.Fingerprints = new Dictionary<string, string>();
result.Fingerprints.Add("0", HashUtilities.ComputeSha256HashValue(rule.RuleId).ToLower());

return result;
}

private void getResultSeverity(string result, out FailureLevel level, out ResultKind kind, out double rank)
{
// Default values
level = FailureLevel.None;
kind = ResultKind.None;
rank = RankConstants.None;

//Kind & Level determine the status
//Result: "fail": Level = Error, Kind = Fail
//Result: "info|notchecked|pass|unknown": Level = None, Kind = Informational|NotApplicable|Pass|Review
switch (result)
{
case "pass":
level = FailureLevel.None;
kind = ResultKind.Pass;
rank = RankConstants.None;
break;
case "fail":
level = FailureLevel.Error;
kind = ResultKind.Fail;
rank = RankConstants.High;
break;
case "notchecked":
level = FailureLevel.None;
kind = ResultKind.NotApplicable;
rank = RankConstants.None;
break;
case "informational":
level = FailureLevel.None;
kind = ResultKind.Informational;
rank = RankConstants.None;
break;
case "unknown":
default:
level = FailureLevel.Warning;
kind = ResultKind.Fail;
rank = RankConstants.Medium;
break;
};
}
}
}
33 changes: 33 additions & 0 deletions src/Sarif.Converters/CisCatObjectModel/CisCatReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;

using Newtonsoft.Json;

namespace Microsoft.CodeAnalysis.Sarif.Converters.CisCatObjectModel
{
public class CisCatReport
{
[JsonProperty("benchmark-id")]
public string BenchmarkId { get; set; }

[JsonProperty("benchmark-title")]
public string BenchmarkTitle { get; set; }

[JsonProperty("benchmark-version")]
public string BenchmarkVersion { get; set; }

[JsonProperty("profile-id")]
public string ProfileId { get; set; }

[JsonProperty("profile-title")]
public string ProfileTitle { get; set; }

[JsonProperty("score")]
public string Score { get; set; }

[JsonProperty("rules")]
public IEnumerable<CisCatRule> Rules { get; set; }
}
}
25 changes: 25 additions & 0 deletions src/Sarif.Converters/CisCatObjectModel/CisCatReportReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.IO;

using Newtonsoft.Json;

namespace Microsoft.CodeAnalysis.Sarif.Converters.CisCatObjectModel
{
public class CisCatReportReader : LogReader<CisCatReport>
{
public override CisCatReport ReadLog(Stream input)
{
string reportData;

using (TextReader streamReader = new StreamReader(input))
{
reportData = streamReader.ReadToEnd();
}

return JsonConvert.DeserializeObject<CisCatReport>(reportData);
}
}
}
24 changes: 24 additions & 0 deletions src/Sarif.Converters/CisCatObjectModel/CisCatRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Newtonsoft.Json;

namespace Microsoft.CodeAnalysis.Sarif.Converters.CisCatObjectModel
{
public class CisCatRule
{
[JsonProperty("rule-id")]
public string RuleId { get; set; }

[JsonProperty("rule-title")]
public string RuleTitle { get; set; }

[JsonProperty("result")]
public string Result { get; set; }

public bool IsPass()
{
return this.Result == "pass";
}
}
}
Loading