Skip to content

All SAST

codesectools.sasts.all

Initializes the All SAST module.

Modules:

Name Description
cli

Defines the command-line interface for running all available SAST tools.

graphics

Provides classes for generating plots and visualizations from aggregated SAST results.

parser

Provides classes for parsing and aggregating results from multiple SAST tools.

report

Generates HTML reports for aggregated SAST analysis results.

sast

Defines the logic for orchestrating multiple SAST tools together.

cli

Defines the command-line interface for running all available SAST tools.

Functions:

Name Description
build_cli

Build the Typer CLI for running all SAST tools.

build_cli

build_cli() -> typer.Typer

Build the Typer CLI for running all SAST tools.

graphics

Provides classes for generating plots and visualizations from aggregated SAST results.

Graphics

Graphics(project_name: str)

Bases: CoreGraphics

Base class for generating plots for aggregated SAST results.

Attributes:

Name Type Description
project_name str

The name of the project being visualized.

all_sast AllSAST

The instance managing all SAST tools.

output_dir Path

The directory containing the aggregated results.

color_mapping dict

A dictionary mapping SAST tool names to colors.

sast_names list[str]

A list of names of the SAST tools involved in the analysis.

plot_functions list

A list of methods responsible for generating plots.

Initialize the Graphics object.

project_name instance-attribute
project_name = project_name
all_sast instance-attribute
all_sast = AllSAST()
output_dir instance-attribute
output_dir = self.all_sast.output_dir / project_name
color_mapping instance-attribute
color_mapping = {}
sast_names instance-attribute
sast_names = []
plot_functions instance-attribute
plot_functions = []

ProjectGraphics

ProjectGraphics(project_name: str)

Bases: Graphics

Generate graphics for an aggregated analysis result of a single project.

Initialize the ProjectGraphics object.

Methods:

Name Description
plot_overview

Generate an overview plot with stats by files, SAST tools, and categories.

plot_top_cwes

Generate a stacked bar plot for the top CWEs found.

plot_top_scores

Generate a stacked bar plot for files with the highest scores.

Attributes:

Name Type Description
result
result instance-attribute
result = self.all_sast.parser.load_from_output_dir(
    project_name
)
plot_overview
plot_overview() -> Figure

Generate an overview plot with stats by files, SAST tools, and categories.

plot_top_cwes
plot_top_cwes() -> Figure

Generate a stacked bar plot for the top CWEs found.

plot_top_scores
plot_top_scores() -> Figure

Generate a stacked bar plot for files with the highest scores.

parser

Provides classes for parsing and aggregating results from multiple SAST tools.

AllSASTAnalysisResult

AllSASTAnalysisResult(
    name: str, analysis_results: dict[str, AnalysisResult]
)

Represent the aggregated results from multiple SAST analyses on a single project.

Initialize an AllSASTAnalysisResult instance.

Methods:

Name Description
__repr__

Return a developer-friendly string representation of the aggregated result.

load_from_output_dir

Load and parse analysis results from all SAST tools for a given project.

stats_by_files

Calculate statistics on defects, grouped by file.

stats_by_sasts

Calculate statistics on defects, grouped by SAST tool.

stats_by_categories

Calculate statistics on defects, grouped by severity category.

stats_by_cwes

Calculate statistics on defects, grouped by CWE.

stats_by_scores

Calculate a risk score for each file based on defect data.

prepare_report_data

Prepare data needed to generate a report.

Attributes:

Name Type Description
name
source_path
analysis_results
lang
sast_names
files
defects
category_mapping
name instance-attribute
name = name
source_path instance-attribute
source_path = None
analysis_results instance-attribute
analysis_results = analysis_results
lang instance-attribute
lang = None
sast_names instance-attribute
sast_names = []
files instance-attribute
files = set()
defects instance-attribute
defects = []
category_mapping instance-attribute
category_mapping = {}
__repr__
__repr__() -> str

Return a developer-friendly string representation of the aggregated result.

load_from_output_dir classmethod
load_from_output_dir(project_name: str) -> Self

Load and parse analysis results from all SAST tools for a given project.

stats_by_files
stats_by_files() -> dict

Calculate statistics on defects, grouped by file.

stats_by_sasts
stats_by_sasts() -> dict

Calculate statistics on defects, grouped by SAST tool.

stats_by_categories
stats_by_categories() -> dict

Calculate statistics on defects, grouped by severity category.

stats_by_cwes
stats_by_cwes() -> dict

Calculate statistics on defects, grouped by CWE.

stats_by_scores
stats_by_scores() -> dict

Calculate a risk score for each file based on defect data.

prepare_report_data
prepare_report_data() -> dict

Prepare data needed to generate a report.

report

Generates HTML reports for aggregated SAST analysis results.

ReportEngine

ReportEngine(project: str, all_sast: AllSAST)

Generate interactive HTML reports for SAST analysis results.

Attributes:

Name Type Description
TEMPLATE str

The HTML template used for report generation.

project str

The name of the project.

all_sast AllSAST

The AllSAST manager instance.

report_dir Path

The directory where reports are saved.

result AllSASTAnalysisResult

The parsed analysis results.

report_data dict

The data prepared for rendering the report.

Initialize the ReportEngine.

Parameters:

Name Type Description Default
project
str

The name of the project.

required
all_sast
AllSAST

The AllSAST instance.

required

Methods:

Name Description
generate_single_defect

Generate the HTML report for a single file with defects.

generate

Generate the HTML report.

TEMPLATE class-attribute instance-attribute
TEMPLATE = '\n    <!DOCTYPE html>\n    <html>\n    <head>\n    <meta charset="UTF-8">\n    <style>\n    {stylesheet}\n    body {{\n        color: {foreground};\n        background-color: {background};\n        font-family: Menlo, \'DejaVu Sans Mono\', consolas, \'Courier New\', monospace;\n    }}\n    .tippy-box {{\n        background-color: white;\n        color: black;\n    }}\n    img {{\n        display: block;\n        margin: auto;\n        border: solid black 1px;\n    }}\n    #top {{\n        position: fixed;\n        bottom: 20px;\n        right: 30px;\n        background-color: white;\n        padding: 10px;\n        border: solid black 5px;\n    }}\n    </style>\n    </head>\n    <body>\n        <a href="./home.html"><h1>CodeSecTools All SAST Tools Report</h1></a>\n        <h3>SAST Tools used: [sasts]</h3>\n        <h2>[name]</h2>\n        <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code style="font-family:inherit">{code}</code></pre>\n        <script src="https://unpkg.com/@popperjs/core@2"></script>\n        <script src="https://unpkg.com/tippy.js@6"></script>\n        <script>[tippy_calls]</script>\n        <a href="#" id="top">^</a>\n    </body>\n    </html>\n    '
project instance-attribute
project = project
all_sast instance-attribute
all_sast = all_sast
report_dir instance-attribute
report_dir = all_sast.output_dir / project / 'report'
result instance-attribute
result = all_sast.parser.load_from_output_dir(
    project_name=project
)
report_data instance-attribute
report_data = self.result.prepare_report_data()
generate_single_defect
generate_single_defect(file_data: dict) -> tuple

Generate the HTML report for a single file with defects.

generate
generate() -> None

Generate the HTML report.

Creates the report directory and generates HTML files for the main view and for each file with defects.

sast

Defines the logic for orchestrating multiple SAST tools together.

AllSAST

AllSAST()

Orchestrate running multiple SAST tools and managing their combined results.

Initialize the AllSAST instance.

Methods:

Name Description
list_results

List the names of analysis results common to all enabled SAST tools.

Attributes:

Name Type Description
name
parser
output_dir
sasts list[SAST]
sasts_by_lang
sasts_by_dataset
name class-attribute instance-attribute
name = 'AllSAST'
parser class-attribute instance-attribute
output_dir instance-attribute
output_dir = USER_OUTPUT_DIR / self.name
sasts instance-attribute
sasts: list[SAST] = []
sasts_by_lang instance-attribute
sasts_by_lang = {}
sasts_by_dataset instance-attribute
sasts_by_dataset = {}
list_results
list_results(
    project: bool = False,
    dataset: bool = False,
    limit: int | None = None,
) -> set[str]

List the names of analysis results common to all enabled SAST tools.