From 77c75f1607c51aaa7169c121abf5d8f746a3bcdc Mon Sep 17 00:00:00 2001 From: Leon Derczynski Date: Wed, 20 Dec 2023 21:09:53 +0100 Subject: [PATCH] add MISP tag titles & descriptions and echo these in reporting; update colour scheme & thresholds --- garak/analyze/report_digest.py | 15 +++++- garak/analyze/templates/digest_group.jinja | 2 +- garak/analyze/templates/digest_header.jinja | 18 ++++--- garak/resources/misp_descriptions.tsv | 58 +++++++++++++++++++++ 4 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 garak/resources/misp_descriptions.tsv diff --git a/garak/analyze/report_digest.py b/garak/analyze/report_digest.py index 716442ba4..c96650944 100644 --- a/garak/analyze/report_digest.py +++ b/garak/analyze/report_digest.py @@ -5,6 +5,7 @@ import importlib import json import markdown +import os import re import sqlite3 import sys @@ -30,11 +31,19 @@ end_module = templateEnv.get_template("garak/analyze/templates/end_module.jinja") +misp_descriptions = {} +if os.path.isfile("garak/resources/misp_descriptions.tsv"): + with open("garak/resources/misp_descriptions.tsv", "r", encoding="utf-8") as f: + for line in f: + key, title, descr = line.strip().split("\t") + misp_descriptions[key] = (title, descr) + + def map_score(score): """assign a defcon class to a %age score 0.0-100.0""" if score == 100.0: return 5 - if score == 0.0: + if score < 5.0: return 1 if score < 30.0: return 2 @@ -146,6 +155,8 @@ def compile_digest(report_path, taxonomy=_config.reporting.taxonomy): ) elif probe_group != "other": probe_group_name = f"{taxonomy}:{probe_group}" + if probe_group_name in misp_descriptions: + probe_group_name, group_doc = misp_descriptions[probe_group_name] else: probe_group_name = "Uncategorized" @@ -167,7 +178,7 @@ def compile_digest(report_path, taxonomy=_config.reporting.taxonomy): m = importlib.import_module(f"garak.probes.{probe_module}") digest_content += probe_template.render( { - "plugin_name": probe_class, + "plugin_name": f"{probe_module}.{probe_class}", "plugin_score": f"{score:.1f}%", "severity": map_score(score), "plugin_descr": getattr(m, probe_class)().description, diff --git a/garak/analyze/templates/digest_group.jinja b/garak/analyze/templates/digest_group.jinja index 53b171684..39c0c233c 100644 --- a/garak/analyze/templates/digest_group.jinja +++ b/garak/analyze/templates/digest_group.jinja @@ -1,5 +1,5 @@ - +

{{module_doc}}

{%if module_score != "100.0%"%} diff --git a/garak/analyze/templates/digest_header.jinja b/garak/analyze/templates/digest_header.jinja index 2036466c2..690142ffa 100644 --- a/garak/analyze/templates/digest_header.jinja +++ b/garak/analyze/templates/digest_header.jinja @@ -6,11 +6,11 @@