Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai findings to sarif

From Leeroopedia
Knowledge Sources
Domains Security_Testing, CI_CD
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete SARIF v2.1.0 export function that converts pentest-ai findings into the Static Analysis Results Interchange Format for CI/CD integration with GitHub Code Scanning and Azure DevOps.

Description

findings_to_sarif converts a list of finding dicts into a SARIF v2.1.0 JSON document. Each finding becomes a result with:

  • Rule definition: id (CWE or category), name, description, default level (severity → error/warning/note)
  • Location: artifact URI (finding target URL)
  • Properties: cvss_score, cwe_id, compliance_mapping, and (when verified_only) export properties
  • DAST extension: webRequest/webResponse from http_request evidence artifacts for inline rendering in GitHub Code Scanning
  • Invocation metadata: engagement_id, target, scope

The tool driver name is "pentest-ai" with the installed package version resolved dynamically.

When verified_only is True, only findings with verdict="verified" are included — this is the CI gate's contract (no proof, no SARIF result).

Usage

Import this when you need to:

  • Export findings as SARIF for GitHub Code Scanning
  • Generate SARIF for Azure DevOps or other SARIF consumers
  • Export verified-only findings for CI gates

Code Reference

Source Location

Signature

SARIF_VERSION = "2.1.0"
SARIF_SCHEMA = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json"

SEVERITY_TO_LEVEL: dict[str, str] = {
    "critical": "error",
    "high": "error",
    "medium": "warning",
    "low": "note",
    "info": "note",
}

def findings_to_sarif(
    findings: list[dict[str, Any]],
    engagement: dict[str, Any],
    verified_only: bool = False,
) -> dict[str, Any]:
    """Convert findings to SARIF v2.1.0 JSON."""

Import

from engine.sarif import findings_to_sarif

I/O Contract

Inputs

Name Type Required Description
findings list[dict[str, Any]] Yes Findings from FindingsDB
engagement dict[str, Any] Yes Engagement record
verified_only bool No Filter to verdict=="verified" only (default: False)

Outputs

Name Type Description
returns SARIF v2.1.0 JSON document with $schema, version, runs

Usage Examples

Exporting SARIF

import json
from engine.sarif import findings_to_sarif

findings = await db.get_findings(engagement_id="eng-123")
engagement = await db.get_engagement("eng-123")

# Export verified-only SARIF for CI
sarif = findings_to_sarif(findings, engagement, verified_only=True)
with open("pentest-ai.sarif", "w") as f:
    json.dump(sarif, f, indent=2)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment