-
Notifications
You must be signed in to change notification settings - Fork 91
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
Introduce GitHub DSP analysis rules #2021
Merged
Merged
Changes from 17 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
9407fc6
Bump version; update release history.
79abb3a
Add GitHub DSP policy file.
f15178e
Merge branch 'master' into users/lgolding/dsp-rules-2
72b8cbd
Fix broken functional test.
fee99c9
Add user-facing strings for SARIF2017.
88fec5e
Define rule id for SARIF2017.
8c321cc
Introduce SARIF2017.LocationsMustHaveRequiredProperties.
07a7233
Add "valid" functional test for SARIF2017.LocationsMustHaveRequiredPr…
f94e54c
Add "invalid" functional test for SARIF2017.LocationsMustHaveRequired…
038c641
Cover case where result.locations is empty.
e3b030d
Move location property bags up to expose JPointer bug.
fa59293
Introduce Skimmer.EnabledByDefault
37685f6
Skimmer: Populate DefaultConfiguration so it appears in rule metadata.
0e3afc2
Don't execute default-disabled rules unless the configuration enables…
a0c36b6
Add first rule to policy file; add file to solution.
f162209
Add DSP XML config file.
31ab5bd
Remove associated tool GUID from SARIF config file.
57118bf
Update solution file for renamed policy file.
42f444d
Adjust line numbers to fix test broken by JPointer bug.
4e468ec
Update a comment.
0fa413d
Merge branch 'master' into users/lgolding/dsp-rules-2
a304d93
Rename misnamed resource strings.
4708c2c
Implement SARIF2018.InlineThreadFlowLocations.
18e3912
Implement SARIF2019.RegionsMustProvideRequiredProperties.
27ef72a
Update policy files for SARIF2019.
0db7e86
Implement SARIF2020.ReviewArraysThatExceedConfigurableDefaults.
6947dcb
Fix broken formatted messages; improve messages.
ac534bb
Fix naming errors in policy files and a bug in SARIF2019.
43bfc60
Implement SARIF2021.LocationsMustBeRelativeUrisOrFilePaths.
59a345e
Implement SARIF2022.ProvideCheckoutPath.
b05eb59
SARIF2017 now covers related locations.
b6ea1b9
SARIF2017: Add tests for relatedLocations.
fd9973b
SARIF2017: Really add relatedLocations logic this time.
173e3d7
Rename "policy" files to "config".
6a6e24e
Protect SARIF1004 against a null ref.
02646b4
Correct user-facing strings for SARIF2019 to match DSP behavior.
a1de09c
Improve user-facing strings for SARIF2021.
b7052ea
Avoid null ref in SARIF2022.
a50f065
Implement SARIF2023.RelatedLocationsMustProvideRequiredProperties.
6268f27
Update test for changed message.
6fdf5e0
Fix typo in summary comment.
1f1f0c2
Merge branch 'master' into users/lgolding/dsp-rules-2
661fafb
Refactor SARIF2021 to prepare for related locations.
1c5a33e
Apply SARIF2021 to related locations.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
policies/github-dsp-policy.config.sarif-external-properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/sarif-external-property-file-2.1.0-rtm.5", | ||
"version": "2.1.0", | ||
"guid": "89072b7a-3d16-43f2-ac0b-3d9cffc814be", | ||
"policies": [ | ||
{ | ||
"name": "GitHub Developer Security Portal policy", | ||
"version": "0.0.1", | ||
"organization": "Microsoft", | ||
"product": "Microsoft SARIF SDK", | ||
"associatedComponent": { | ||
"name": "Sarif.Multitool" | ||
}, | ||
"rules": [ | ||
{ | ||
"id": "SARIF2017", | ||
"name": "LocationsMustHaveRequiredProperties", | ||
"defaultConfiguration": { | ||
"enabled": true | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Properties> | ||
<Properties Key='SARIF2017.LocationsMustHaveRequiredProperties.Options'> | ||
<Property Key='RuleEnabled' Value='Error' /> | ||
</Properties> | ||
</Properties> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Sarif.Multitool/Rules/SARIF2017.LocationsMustHaveRequiredProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// 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.Diagnostics; | ||
using System.Linq; | ||
|
||
using Microsoft.Json.Pointer; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules | ||
{ | ||
public class LocationsMustHaveRequiredProperties : SarifValidationSkimmerBase | ||
{ | ||
/// <summary> | ||
/// SARIF2017 | ||
/// </summary> | ||
public override string Id => RuleId.LocationsMustHaveRequiredProperties; | ||
|
||
/// <summary> | ||
/// Each result location must provide the property 'physicalLocation.artifactLocation.uri'. | ||
/// The GitHub Developer Security Portal will not display a result whose location does not | ||
/// provide the URI of the artifact that was analyzed. | ||
/// </summary> | ||
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2017_LocationsMustHaveRequiredProperties_FullDescription_Text }; | ||
|
||
protected override IEnumerable<string> MessageResourceNames => new string[] { | ||
nameof(RuleResources.SARIF2017_LocationsMustHaveRequired_Properties_Error_NoLocationsArray_Text), | ||
nameof(RuleResources.SARIF2017_LocationsMustHaveRequired_Properties_Error_EmptyLocationsArray_Text), | ||
nameof(RuleResources.SARIF2017_LocationsMustHaveRequired_Properties_Error_Default_Text) | ||
}; | ||
|
||
public override FailureLevel DefaultLevel => FailureLevel.Error; | ||
|
||
public override bool EnabledByDefault => false; | ||
|
||
protected override void Analyze(Result result, string resultPointer) | ||
{ | ||
if (result.Locations == null) | ||
{ | ||
// {0}: The 'locations' property is absent. The GitHub Developer Security Portal | ||
// will not display a result unless it provides a location that specifies the URI | ||
// of the artifact that contains the result. | ||
LogResult( | ||
resultPointer, | ||
nameof(RuleResources.SARIF2017_LocationsMustHaveRequired_Properties_Error_NoLocationsArray_Text), | ||
SarifPropertyName.Locations); | ||
return; | ||
} | ||
|
||
string locationsPointer = resultPointer.AtProperty(SarifPropertyName.Locations); | ||
if (!result.Locations.Any()) | ||
{ | ||
// {0}: The 'locations' array is empty. The GitHub Developer Security Portal will | ||
// not display a result unless it provides a location that specifies the URI of the | ||
// artifact that contains the result. | ||
LogResult( | ||
locationsPointer, | ||
nameof(RuleResources.SARIF2017_LocationsMustHaveRequired_Properties_Error_EmptyLocationsArray_Text)); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < result.Locations.Count; i++) | ||
{ | ||
Location location = result.Locations[i]; | ||
string missingProperty = null; | ||
string jsonPointer = null; | ||
|
||
if (location.PhysicalLocation == null) | ||
{ | ||
missingProperty = SarifPropertyName.PhysicalLocation; | ||
jsonPointer = locationsPointer.AtIndex(i); | ||
} | ||
else if (location.PhysicalLocation.ArtifactLocation == null) | ||
{ | ||
missingProperty = SarifPropertyName.ArtifactLocation; | ||
jsonPointer = locationsPointer.AtIndex(i).AtProperty(SarifPropertyName.PhysicalLocation); | ||
} | ||
else if (location.PhysicalLocation.ArtifactLocation.Uri == null) | ||
{ | ||
missingProperty = SarifPropertyName.Uri; | ||
jsonPointer = locationsPointer.AtIndex(i).AtProperty(SarifPropertyName.PhysicalLocation).AtProperty(SarifPropertyName.ArtifactLocation); | ||
} | ||
|
||
if (missingProperty != null) | ||
{ | ||
Debug.Assert(jsonPointer != null); | ||
|
||
// {0}: The '{1}' property is absent. The GitHub Developer Security Portal will | ||
// not display a result whose location does not provide the URI of the artifact | ||
// that contains the result. | ||
LogResult( | ||
jsonPointer, | ||
nameof(RuleResources.SARIF2017_LocationsMustHaveRequired_Properties_Error_Default_Text), | ||
missingProperty); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would start jsonPointer as LocationPointer.AtIndex(i), since every place you have that. Then, update the other places below to specific cases when necessary. #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to do it this way because otherwise, we unnecessarily calculate
.AtIndex(i)
for every location in every result in the log file. This way, we only calculate it in the rare case where the rule fires.In reply to: 463585630 [](ancestors = 463585630)