-
Notifications
You must be signed in to change notification settings - Fork 93
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
Adding rule SARIF2016 #1996
Merged
Merged
Adding rule SARIF2016 #1996
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
88 changes: 88 additions & 0 deletions
88
src/Sarif.Multitool/Rules/SARIF2016.FileUrisShouldBeRelative.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,88 @@ | ||
// 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 Microsoft.Json.Pointer; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Multitool.Rules | ||
{ | ||
public class FileUrisShouldBeRelative : SarifValidationSkimmerBase | ||
{ | ||
/// <summary> | ||
/// SARIF2016 | ||
/// </summary> | ||
public override string Id => RuleId.FileUrisShouldBeRelative; | ||
|
||
/// <summary> | ||
/// When an artifact location refers to a file on the local file system, specify a relative reference | ||
/// for the uri property and provide a uriBaseId property, rather than specifying an absolute URI. | ||
/// | ||
/// There are several advantages to this approach: | ||
/// Portability: A log file that contains relative references together with uriBaseI properties can | ||
/// be interpreted on a machine where the files are located at a different absolute location. | ||
/// | ||
/// Determinism: A log file that uses uriBaseId properties has a better chance of being “deterministic”; | ||
/// that is, of being identical from run to run if none of its inputs have changed, even if those runs | ||
/// occur on machines where the files are located at different absolute locations. | ||
/// | ||
/// Security: The use of uriBaseId properties avoids the persistence of absolute path names in the | ||
/// log file.Absolute path names can reveal information that might be sensitive. | ||
/// | ||
/// Semantics: Assuming the reader of the log file (an end user or another tool) has the necessary | ||
/// context, they can understand the meaning of the location specified by the uri property, for | ||
/// example, “this is a source file”. | ||
/// </summary> | ||
public override MultiformatMessageString FullDescription => new MultiformatMessageString { Text = RuleResources.SARIF2016_FileUrisShouldBeRelative_FullDescription_Text }; | ||
|
||
protected override IEnumerable<string> MessageResourceNames => new string[] { | ||
nameof(RuleResources.SARIF2016_FileUrisShouldBeRelative_Note_Default_Text) | ||
}; | ||
|
||
public override FailureLevel DefaultLevel => FailureLevel.Note; | ||
|
||
protected override void Analyze(Run run, string runPointer) | ||
{ | ||
if (run.Results != null) | ||
{ | ||
AnalyzeResults(run.Results, runPointer.AtProperty(SarifPropertyName.Results)); | ||
} | ||
} | ||
|
||
private void AnalyzeResults(IList<Result> results, string resultsPointer) | ||
{ | ||
for (int i = 0; i < results.Count; i++) | ||
{ | ||
string resultPointer = resultsPointer.AtIndex(i); | ||
Result result = results[i]; | ||
|
||
if (result.Locations != null) | ||
{ | ||
AnalyzeResultLocations(result.Locations, resultPointer.AtProperty(SarifPropertyName.Locations)); | ||
} | ||
} | ||
} | ||
|
||
private void AnalyzeResultLocations(IList<Location> locations, string locationsPointer) | ||
{ | ||
for (int i = 0; i < locations.Count; i++) | ||
{ | ||
string locationPointer = locationsPointer.AtIndex(i); | ||
Location location = locations[i]; | ||
|
||
if (location.PhysicalLocation?.ArtifactLocation.Uri != null) | ||
{ | ||
if (location.PhysicalLocation.ArtifactLocation.Uri.IsAbsoluteUri && location.PhysicalLocation.ArtifactLocation.Uri.IsFile) | ||
{ | ||
// {0}: The file location '{1}' is specified with absolute URI. Prefer a relative | ||
// reference together with a uriBaseId property. | ||
LogResult( | ||
locationPointer.AtProperty(SarifPropertyName.PhysicalLocation).AtProperty(SarifPropertyName.ArtifactLocation).AtProperty(SarifPropertyName.Uri), | ||
nameof(RuleResources.SARIF2016_FileUrisShouldBeRelative_Note_Default_Text), | ||
location.PhysicalLocation.ArtifactLocation.Uri.OriginalString); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
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.
If the point is simply to enable a specific rule, we should have a helper that constructs the appropriate config using a rule id. And dispense with maintaining a checked in file.