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

Defines the base report generation functionality for aggregated SAST 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.

Attributes:

Name Type Description
REPORT_FORMATS

REPORT_FORMATS module-attribute

REPORT_FORMATS = {'HTML': HTMLReport, 'SARIF': SARIFReport}

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.

sast_color 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
sast_color instance-attribute
sast_color = {}
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 levels.

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 levels.

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.

Parameters:

Name Type Description Default
name
str

The name of the project.

required
analysis_results
dict[str, AnalysisResult]

A dictionary of analysis results from various SAST tools.

required

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_levels

Calculate statistics on defects, grouped by severity level.

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
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 = []
__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_levels
stats_by_levels() -> dict

Calculate statistics on defects, grouped by severity level.

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(top: int | None = None) -> dict

Prepare data needed to generate a report.

Parameters:

Name Type Description Default
top
int | None

The maximum number of files to include, ranked by score.

None

Returns:

Type Description
dict

A dictionary containing the prepared report data.

report

Defines the base report generation functionality for aggregated SAST results.

Modules:

Name Description
HTML

Generates HTML reports for aggregated SAST analysis results.

SARIF

Generates SARIF reports for aggregated SAST analysis results.

Report

Report(
    project: str, all_sast: AllSAST, top: int | None = None
)

Bases: ABC

Abstract base class for report generation.

Attributes:

Name Type Description
format str

The format of the report (e.g., "HTML", "SARIF").

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 Report.

Parameters:

Name Type Description Default
project
str

The name of the project.

required
all_sast
AllSAST

The AllSAST instance.

required
top
int | None

The number of top files to include in the report based on score.

None

Methods:

Name Description
generate

Generate the report.

format instance-attribute
format: str
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" / self.format
)
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(top=top)
generate abstractmethod
generate() -> None

Generate the report.

HTML

Generates HTML reports for aggregated SAST analysis results.

HTMLReport
HTMLReport(
    project: str, all_sast: AllSAST, top: int | None = None
)

Bases: Report

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.

Methods:

Name Description
generate_single_defect

Generate the HTML report for a single file with defects.

generate

Generate the HTML report.

format class-attribute instance-attribute
format = 'HTML'
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    '
generate_single_defect
generate_single_defect(defect_file: dict) -> str

Generate the HTML report for a single file with defects.

generate
generate() -> None

Generate the HTML report.

SARIF

Generates SARIF reports for aggregated SAST analysis results.

SARIFReport
SARIFReport(
    project: str, all_sast: AllSAST, top: int | None = None
)

Bases: Report

Generate SARIF reports for SAST analysis results.

Attributes:

Name Type Description
format str

The format of the report, which is "SARIF".

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.

Methods:

Name Description
generate

Generate the SARIF report.

format class-attribute instance-attribute
format = 'SARIF'
generate
generate() -> None

Generate the SARIF report.

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
full_sasts list[SAST]
partial_sasts list[SAST]
any_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
full_sasts instance-attribute
full_sasts: list[SAST] = []
partial_sasts instance-attribute
partial_sasts: list[SAST] = []
any_sasts instance-attribute
any_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.