GithubHelp home page GithubHelp logo

microsoft / sarif-visualstudio-extension Goto Github PK

View Code? Open in Web Editor NEW
44.0 10.0 24.0 6.11 MB

SARIF Microsoft Visual Studio Viewer Extension

License: MIT License

Batchfile 0.23% PowerShell 1.10% C# 98.11% HTML 0.25% C 0.07% C++ 0.25%

sarif-visualstudio-extension's Introduction

Microsoft SARIF Viewer

Build Status

The Microsoft SARIF Viewer extension for Visual Studio provides a convenient UI for analyzing static analysis log files and taking action on the items they contain. The SARIF Viewer integrates with the Visual Studio environment, displaying a list of analysis results in the Error List and result details in a dockable tool window.

Features

  • View the set of results from a SARIF log file
  • View details about each result, including:
    • Information about the rule that was violated
    • Locations of the defect
    • Code paths and call stacks that lead to the defect
    • Suggested fixes for the defect
    • Details about the static analysis run and the tool that performed it
  • Navigate to the defect location in the target file
  • Extract target files embedded in the SARIF log
  • Preview and apply suggested fixes in the target file with the click of a button
  • Automatically transform SARIF v1 logs to v2
  • Automatically convert log files from many other static analysis formats
  • Open SARIF log files in the SARIF Viewer from your own Visual Studio extension using the SARIF Viewer Interop Library

Installation

The Microsoft SARIF Viewer extension can be downloaded and installed from the Visual Studio Marketplace.

Alternatively, in Visual Studio, open the Extension Manager (Menu: Extensions -> Manage Extensions), search for "Microsoft SARIF Viewer", select the entry, and click on the Download button.

License

Microsoft SARIF Viewer is licensed under the MIT license.

sarif-visualstudio-extension's People

Contributors

chrishuynhc avatar dependabot[bot] avatar easyrhino-gh avatar easyrhinomsft avatar eddynaka avatar edkazcarlson-ms avatar gabedebacker avatar jarlob avatar marmegh avatar michaelcfanning avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar payton2022 avatar yongyan-gh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sarif-visualstudio-extension's Issues

Fixes don't recognize text-based regions

Repro:

  1. Build and run the sarif-sdk sample application:
SarifSdkSample.exe create Test.sarif
  1. Open Test.sarif in the viewer.
  2. In the Error List Window, click on the issue CA1820.
  3. In the SARIF Explorer Window, click Fixes.
  4. Expand the tree nodes "Replace empty string with test for zero length", "Analysis Sample.cs"

Expected: It should display the "Deleted region" with proper row and column values.

Actual: It says "Start at offset 0".

Viewer doesn't understand that startColumn is implicitly 1

ReformattingVisitor.txt

{
"$schema": "http://json.schemastore.org/sarif-2.0.0",
"version": "2.0.0",
"runs": [
{
"instanceGuid": "a8cd4914-c079-414c-86b0-1311f4c9678a",
"tool": {
"name": "Sarif.UnitTests",
"fullName": "Sarif.UnitTests.1.3.3.0-beta",
"version": "1.3.3.0",
"semanticVersion": "1.3.3",
"sarifLoggerVersion": "1.5.22.0",
"language": "en-US"
},
"originalUriBaseIds": { "SRCROOT": "file:///e$/src/sarif-sdk/" },
"results": [
{
"ruleId": "TEST2001",
"level": "error",
"message": {
"text": "This is an error with a 'dynamic' argument. It selects a text value of 'RegionOne'.",
"richMessageId": "Error",
"arguments": [ "dynamic" ]
},
"locations": [
{
"physicalLocation": {
"fileLocation": {
"uri": "/src/Sarif.UnitTests/TestData/ReformattingVisitor/ReformattingVisitor.txt",
"uriBaseId": "SRCROOT"
},
"region": {
"startLine": 14,
"endColumn": 10
}
}
}
]
}
],
"resources": {
"rules": {
}
}
}
]
}

Open file picker for any file location

We currently require a region on the result. But if a result references a file, why not just try to open that file?

IOW, we assume there is a default region, which is the insertion point at the beginning of the file. :)

why are we always generating temporary file copies?

Repro, copy file contents below to file named test.sarif. Open it. double-click the result and open the file log. you get pointed to a copy in a temporary location rather than the original file.

{
"$schema": "http://json.schemastore.org/sarif-2.0.0-csd.2.beta.2018-10-10",
"version": "2.0.0-csd.2.beta.2018-10-10",
"runs": [
{
"tool": {
"name": "Contrast Security"
},
"results": [
{
"ruleId": "test",
"level": "warning",
"message": {
"text": "sample warning."
},
"locations": [
{
"physicalLocation": {"fileLocation": {"uri": "file:///c:/test.txt"}}
}
]
}
]
}
]
}

Investigation on create bug template.

Investigate on if there is any existing control/api which can render 'create bug' template form.

Comment : Discussed with Mukul, the creating bug is not priority now. Close this one, if it needs in the futue, will reopen.

Add UI for displaying rule metadata

The viewer is focused on displaying a list of results, and the details of a selected result. It needs a feature to display the list of rules, and details of a selected rule.

Feature: Export to SARIF?

Since the extension is already able to convert from different formats #41 Would it be easy to add an option to export to SARIF selected items from Errors window (the results could be from analyzers)?

My workflow is to save results from analyzers for opening later. Maybe I miss something, but all I found is dotnet/roslyn#430 and dotnet/roslyn#24319 but it requires changes to the project file.

Code highlight disappears on SARIF explorer "Info" tab click

Repro Steps:

  1. Open SARIF in viewer
  2. Select issue in error list that opens source code with proper highlighting
    (snippet is highlighted properly)
  3. In SARIF explorer window, click "Info" tab

Expected: Source highlighting should still exist
Actual: Source highlighting is remove and no longer present in source code

Null reference exception when opening WebGoat.xml.sarif

The viewer pops a null reference exception error box when opening the file WebGoat.xml.sarif from the SARIF SDK.

This might be because the .sarif file is invalid. Right now I can't validate the file because Sarif.Multitool is crashing on startup. I will file a bug for that, too.

Render links in all plain text messages

For any property that you display whose value is a message object or a multiformatMessage object, if you are displaying the object's text property, then render the sequence [link text](link target) as a hyperlink.

@michaelcfanning noticed the lack in the rule metadata display, but we should do it everywhere.

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

Following v1 sarif file (generated with https://github.com/Microsoft/DevSkim) fails to convert to v2 when opened in VS with the error "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters."

{
  "version": "1.0.0",
  "runs": [
    {
      "tool": {
        "name": "devskim",
        "fullName": "Microsoft DevSkim Command Line Interface",
        "version": "0.1.11"
      },
      "results": [
        {
          "ruleId": "DS137138",
          "level": "error",
          "message": "Insecure URL",
          "locations": [
            {
              "analysisTarget": {
                "uri": "file:///C:/temp/aaa.js",
                "region": {
                  "startLine": 18,
                  "startColumn": 27,
                  "endLine": 18,
                  "endColumn": 33,
                  "offset": 516,
                  "length": 6
                }
              }
            }
          ],
          "snippet": "http:/",
          "fixes": [
            {
              "description": "Change to HTTPS ",
              "fileChanges": [
                {
                  "uri": "file:///C:/temp/aaa.js",
                  "replacements": [
                    {
                      "offset": 516,
                      "deletedLength": 6,
                      "insertedBytes": "https:/"
                    }
                  ]
                }
              ]
            }
          ],
          "properties": {
            "tags": ["ThreatModel.Integration.HTTP"]
          }
        }
      ],
      "rules": {
        "DS137138": {
          "id": "DS137138",
          "name": "Insecure URL",
          "fullDescription": "An HTTP-based URL without TLS was detected.",
          "defaultLevel": "error",
          "helpUri": "https://github.com/Microsoft/DevSkim/blob/master/guidance/DS137138.md"
        }
      }
    }
  ]
}

Could not load file or assembly 'System.Collections.Immutable error

I am on Windows 10 Pro.

I have installed the extension using the method outlined in the readme. When in Visual Studio Community 2017, I go to Tools > Import Static Analysis Log File to Error List > Import SARIF file and selecting a sarif file, I am getting an error message:

Could not load file or assembly 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I am able to open this file in Visual Studio Code using the very same plugin, so the file is valid.

Where should I start looking to fix this?

Microsoft Visual Studio Community 2017 
Version 15.7.4
VisualStudio.15.Release/15.7.4+27703.2035
Microsoft .NET Framework
Version 4.7.03190

Installed Version: Community

Visual C++ 2017   00369-60000-00001-AA558
Microsoft Visual C++ 2017

ASP.NET and Web Tools 2017   15.0.40601.0
ASP.NET and Web Tools 2017

C# Tools   2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service   2.0
JavaScript Language Service

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft SARIF Viewer   2.0 beta
Visual Studio Static Analysis Results Interchange Format (SARIF) log file viewer

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

NuGet Package Manager   4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

Visual Basic Tools   2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Windows Machine Learning Generator Extension   1.0
Windows Machine Learning Visual Studio Extension Detailed Info

Preview and Apply action links are disabled in Fixes

Repro:

  1. Build and run the sarif-sdk sample application:
SarifSdkSample.exe create Test.sarif
  1. Open Test.sarif in the viewer.
  2. In the Error List Window, click on the issue CA1820.
  3. In the SARIF Explorer Window, click Fixes.
  4. Expand the tree nodes "Replace empty string with test for zero length", "Analysis Sample.cs"

Expected: The Preview and Apply links are enabled and work properly.

Actual: The links are disabled.

Offer .sarif and .sarif-external-properties file templates

Add options to File, New:

.sarif file, with initial contents

{
  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
  "version": "2.1.0",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "Tool Name"
        }
      },
      "results": [
      ]
    }
  ]
}

.sarif-external-properties file, with initial contents

{
  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-external-property-file-schema-2.1.0.json",
  "version": "2.1.0"

}

Cannot open SARIF files containing URIs that are empty strings

If I attempt to open the /analyze:log sarif output from Visual Studio 2019 (16.0.3 release or 16.1.0, preview 2), both Visual Studio 2019 and Visual Studio 2017 produce the same error dialog. It says, "Value cannot be null. Parameter name: path." I have no information within the standard that says a path parameter exists. Please refer to section I.5 of the official standard .

I suppose there is a small chance that the environmentVariables area under invocations is the cause. However, when I search the sarif file output from Visual Studio 2019, there is no entry anywhere in the file that is tagged environmentVariables. If this is an issue with Visual Studio 2019, then it would make sense. This file output type is not listed on the official analyze option page for 2019. For this issue, use the Microsoft Sample C++ project for code analysis.

Viewer doesn't maintain a rebasing cache per run object

ouch! when we load file table keys, these are shared across runs. this rightly raises an exception when Files.Add encounters a file name that's already there.

all our remapping needs to occur on a per-run basis. don't forget! when you have a uriBaseId (with no originalUriBaseId value that maps to an existing file location), you can just query for that directory location and you're off to the races. i.e., no more heuristics to figure out common path roots.

we might want separate simplified logic for this case (as it should, in fact, be simple, while the existing remapping has some complexity to it that I don't think can be easily removed for the absolute URL case, etc).

Error list shows all sentences in multisentence output

We correctly create an expander for multisentence error list entries. But we show the full contents for the unexpanded error list entry. we should only show the first sentence for this case (and the remainder of the error should display when expanded).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.