import html import json import sys def bandit_rows(path): for r in json.load(open(path, encoding="utf-8"))["results"]: where = f'{r["filename"]}:{r["line_number"]}' yield "Bandit", r["issue_severity"], r["test_id"], where, r["issue_text"] def semgrep_rows(path): run = json.load(open(path, encoding="utf-8"))["runs"][0] levels = {r["id"]: r.get("defaultConfiguration", {}).get("level", "error") for r in run["tool"]["driver"]["rules"]} for r in run["results"]: loc = r["locations"][0]["physicalLocation"] where = f'{loc["artifactLocation"]["uri"]}:{loc["region"]["startLine"]}' yield "Semgrep", levels.get(r["ruleId"], "error").upper(), r["ruleId"].split(".")[-1], where, r["message"]["text"].splitlines()[0] bandit_json, semgrep_sarif, out = sys.argv[1:4] rows = list(bandit_rows(bandit_json)) + list(semgrep_rows(semgrep_sarif)) ok = not rows body = "".join( f"{t}{s}{html.escape(r)}" f"{html.escape(w)}{html.escape(m)}" for t, s, r, w, m in rows ) page = f"""SAST 게이트 결과 {body}
도구심각도룰위치설명
""" open(out, "w", encoding="utf-8").write(page)