Giter VIP home page Giter VIP logo

go-sarif's Introduction

go-sarif

Go Report Card Github Release

What?

SARIF is the Static Analysis Results Interchange Format, this project seeks to provide a simple interface to generate reports in the SARIF format.

Example report

This example is taken directly from the Microsoft sarif pages

{
  "version": "2.1.0",
  "$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "ESLint",
          "informationUri": "https://eslint.org",
          "rules": [
            {
              "id": "no-unused-vars",
              "shortDescription": {
                "text": "disallow unused variables"
              },
              "helpUri": "https://eslint.org/docs/rules/no-unused-vars",
              "properties": {
                "category": "Variables"
              }
            }
          ]
        }
      },
      "artifacts": [
        {
          "location": {
            "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js"
          }
        }
      ],
      "results": [
        {
          "level": "error",
          "message": {
            "text": "'x' is assigned a value but never used."
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js",
                  "index": 0
                },
                "region": {
                  "startLine": 1,
                  "startColumn": 5
                }
              }
            }
          ],
          "ruleId": "no-unused-vars",
          "ruleIndex": 0
        }
      ]
    }
  ]
}

What prompted this?

One of the projects I like to contribute to is tfsec - this is a static analysis tool for Terraform which produces output in many formats. Generating SARIF reports is missing functionality and felt like it warranted being moved out to a project of its own.

More information about SARIF

For more information about SARIF, you can visit the Oasis Open site.

Usage

Add an import to go get github.com/owenrumney/go-sarif/sarif

Parsing a Sarif report

There are a number of ways to load in the content of a sarif report.

Open

sarif.Open takes a file path and loads the sarif from that location. Returns a report and any corresponding error

FromBytes

sarif.FromBytes takes a slice of byte and returns a report and any corresponding error.

FromString

sarif.FromString takes a string of the sarif content and returns a report and any corresponding error.

Creating a new report

Creating a new Sarif report is done by passing the version, the only supported at the moment is 2.1.0

for a detailed example check the example folder example/main.go

go-sarif's People

Contributors

afdesk avatar arukiidou avatar dependabot[bot] avatar glebziz avatar jaspervdj-luminal avatar kiwiz avatar masakura avatar msugakov avatar owenrumney avatar owenrumney-f3 avatar shaopeng-gh avatar spiffcs 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  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

go-sarif's Issues

Save an additional property to already existing `propertyBag`

๐Ÿ‘‹ Hi! How one could save a new property to some existing property bag?

E.g. I have the following SARIF file:

...
"runs": [
    {
      ...
      "properties": {
        "somePropertyA": "some value",
        "tags": [
          "somePropertyA"
        ]
      }
    }
  ]
...

I want to save somePropertyB additionally to that Run object.
Tried creating new property bags and accessing the existing property field, but was unable to solve it.

Thanks!

setting `defaultConfiguration`

I'd like to set up defaultConfiguration.
Now I'm doing next:

r := sw.run.AddRule(data.vulnerabilityId).
...
r.DefaultConfiguration = &sarif.ReportingConfiguration{
	Level: toSarifErrorLevel(data.severity),
}

is it ok?

`fullName` for ToolComponent

The current version of sarif template for trivy contains field fullName. but i can't find information about it.
maybe it's already deprecated.

@owenrumney what do you think about it?

broken package

isn't 1.0.13 technically a breaking change?

go get: github.com/owenrumney/[email protected] updating to
	github.com/owenrumney/[email protected]: parsing go.mod:
	module declares its path as: github.com/owenrum/go-sarif
	        but was required as: github.com/owenrumney/go-sarif

Add the deprecatedIds field in rule

Can you add the 3.49.4 deprecatedIds property to rules? Currently I am putting it in properties field, but since it's an official field it should not be in a field under properties. Thanks!

sarif report without results

Hi @owenrumney!
It seems that I already bore you, sorry!

githbub can't accept a report without vulnerabilities / misconfigurations, because:

"results": null

should trivy handle this case itself?
thanks a lot again!

Suggestion to change Rule Properties type definition

I'm attempting to use this library to build out a code scan in github. Based on this definition

https://docs.github.com/en/code-security/secure-coding/integrating-with-code-scanning/sarif-support-for-code-scanning#reportingdescriptor-object

ReportingDescriptor in github == Rule here.

I believe that we should change Properties from a map[string]string to simply Properities

Properties map[string]string `json:"properties,omitempty"`

Which would match what Run has setup today.

Properties Properties `json:"properties,omitempty"`

Also would be nice to have a corresponding AttachPropertyBag method on this struct like we do here on Run.

go-sarif/sarif/run.go

Lines 75 to 77 in 73511fb

func (run *Run) AttachPropertyBag(pb *PropertyBag) {
run.Properties = pb.Properties
}

Let me know your thoughts. I'm happy to PR that change in.

`properties` property

According to the spec:

In addition to those properties that are explicitly documented, every object defined in this document MAY contain a property named properties whose value is a property bag. This allows SARIF producers to include information about each object that is not explicitly specified in the SARIF format.

This sounds a bit hairy to implement - would every object have a PropertyBag object? How would the interface to that look? For my usecase, I'm looking to set properties on run, toolComponent and result but I thought it'd be worthwhile to discuss this in general.

Also, gratz on v1.0.0!

messageString is missing the `omitempty` tag

messageStrings added in #63 is missing the omitempty tag so it's always showing up in results, e.g.:

"rules": [
  {
    "id": "CVE-123-456",
    "shortDescription": {
      "text": "..."
    },
    "messageStrings": null
  }
]

Update sarif schema

Hello!

https://sarifweb.azurewebsites.net/Validation says that sarif-2.1.0-rtm.5.json is not final version.

[SARIF1011](http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html): $schema: The '$schema' property value 'https://json.schemastore.org/sarif-2.1.0-rtm.5.json' does not refer to the final version of the SARIF 2.1.0 schema. If you are using an earlier version of the SARIF format, consider upgrading your analysis tool to produce the final version. If this file does in fact conform to the final version of the schema, upgrade the tool to populate the '$schema' property with a URL that refers to the final version of the schema.

Looks like sarif-2.1.0-rtm.5.json > sarif-2.1.0.json and sarif-2.1.0.rtm-6.json doesn't exist.

Can you help me understand what I am missing?

Best Regards, Dmitriy!

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.