Skip to content

Exploring SARIF output #165

Closed
@reactive-firewall

Description

@reactive-firewall

Should consider migrating to SARIF output for our custom checks.
For example SARIF can be generated from python like so:

from sarif import *

# Create a new SARIF file
sarif_file = SarifFile()

# Add a run to the SARIF file
run = Run()
sarif_file.runs.append(run)

# Set the tool information for the run
tool = Tool()
tool.driver = ToolComponent("My Security Tool")
run.tool = tool

# Add an analysis target to the run
analysis_target = AnalysisTarget()
analysis_target.uri = Uri("example.c")
run.analysisTarget = analysis_target

# Add a result to the run
result = Result()
result.ruleId = "SECURITY-1001"
result.level = "error"
result.message = Message("Potential security vulnerability: SQL injection")

# Add a location to the result
location = Location()
location.physicalLocation = PhysicalLocation(
    artifactLocation=ArtifactLocation(uri=Uri("example.c"), index=1),
    region=Region(startLine=10, startColumn=15, endLine=10, endColumn=30)
)
result.locations.append(location)

run.results.append(result)

# Serialize the SARIF file to JSON
sarif_json = sarif_file.to_json()

# Write the SARIF JSON to a file
with open("output.sarif", "w") as f:
    f.write(sarif_json)

Metadata

Metadata

Labels

CIContinuous Integration ToolingConfigsImprovements or additions to configurationPython LangChanges to Python source codeTestingSomething can be verifiedenhancementNew feature or requestquestionFurther information is requested

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions