From afb70822d5a4594d68f576d8c9d5b92c60c985ac Mon Sep 17 00:00:00 2001 From: joeshope <100427601+joeshope@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:59:52 -0500 Subject: [PATCH] Add files via upload Adds a score to Sarif file produced by Snyk Code so that High, Medium, or Low can be shown instead of Warning, error, and note. --- scripts/code_sarif.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 scripts/code_sarif.py diff --git a/scripts/code_sarif.py b/scripts/code_sarif.py new file mode 100644 index 0000000..ae481d4 --- /dev/null +++ b/scripts/code_sarif.py @@ -0,0 +1,25 @@ +import argparse +import json + +parser = argparse.ArgumentParser(description='file: input the file path to your sarif file') +parser.add_argument("--file") +args = parser.parse_args() +sarif_file = args.file + +if sarif_file == '': + print("Please input the sarif file path") + sarif_file = input() + +with open(sarif_file, 'r') as f: + data = json.load(f) + +for i in data['runs'][0]['tool']['driver']['rules']: + if i['defaultConfiguration']['level'] == "error": + i['properties']['security-severity'] = "7.5" + elif i['defaultConfiguration']['level'] == "warning": + i['properties']['security-severity'] = "5.5" + else: + i['properties']['security-severity'] = "2.5" + +with open(sarif_file, 'w') as f: + json.dump(data, f) \ No newline at end of file