Skip to content

Instantly share code, notes, and snippets.

@Winand
Created February 29, 2024 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Winand/dbb229abaebdb539e8c7b84b9647c05b to your computer and use it in GitHub Desktop.
Save Winand/dbb229abaebdb539e8c7b84b9647c05b to your computer and use it in GitHub Desktop.
Convert GitLab SAST report to HTML table
from json2html import json2html
import json
from markdown import markdown
filename = "gl-sast-report"
svr = {"Critical": "Crimson", "Medium": "Coral", "Low": "MediumSeaGreen", "Info": "SteelBlue"}
with open(filename + ".json") as f:
inp = json.load(f)
data = inp["vulnerabilities"]
for i in data:
del i["id"], i["category"], i["identifiers"]
i["description"] = markdown(i["description"], extensions=["fenced_code"])
i["severity"] = f"<font color='{svr[i['severity']]}'>{i['severity']}</font>"
i["scanner"] = i["scanner"]["name"]
i["location"] = ":".join(str(i) for i in i["location"].values())
with open(filename + ".html", 'w') as f:
html: str = json2html.convert(data, escape=False, table_attributes="border=\"1\" style=\"table-layout: fixed; width: 100%; word-wrap: break-word\"")
html = html.replace("<th>description</th>", "<th style='width:45%'>description</th>")
f.write(html)
@Winand
Copy link
Author

Winand commented Feb 29, 2024

Requires markdown and json2html packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment