Description
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)