Skip to content

Commit ef4f364

Browse files
authored
Add SARIF Taxonomy Support (#727)
* add sarif support
1 parent 014a102 commit ef4f364

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

.github/workflows/docgenerator.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Generate CycloneDX JSON
3535
run: python3 ./tools/generate_masvs_cyclonedx.py
3636

37+
- name: Generate SARIF
38+
run: python3 ./tools/generate_masvs_sarif.py
39+
3740
- name: Upload Artifacts
3841
uses: actions/upload-artifact@v3
3942
with:
@@ -61,5 +64,6 @@ jobs:
6164
OWASP_MASVS.epub
6265
OWASP_MASVS.yaml
6366
OWASP_MASVS.cdx.json
67+
OWASP_MASVS.sarif
6468
env:
6569
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tools/generate_masvs_sarif.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import yaml
2+
import json
3+
from datetime import datetime
4+
5+
MASVS_SARIF_GUID = "77cf1749-d61e-4cfe-98f7-a217e3b5448c"
6+
7+
# Re-examining the YAML content for structure
8+
masvs_parsed = yaml.safe_load(open("OWASP_MASVS.yaml"))
9+
version = masvs_parsed["metadata"]["version"]
10+
if version.startswith("v"):
11+
version = version[1:]
12+
current_date_str = datetime.now().strftime("%Y-%m-%d")
13+
14+
# Creating a new SARIF template for the corrected conversion
15+
sarif_corrected_template = {
16+
"$schema": "http://json.schemastore.org/sarif-2.1.0",
17+
"version": "2.1.0",
18+
"runs": [{
19+
"tool": {
20+
"driver": {
21+
"name": "OWASP MASVS",
22+
"fullName": "OWASP Mobile Application Security Verification Standard (MASVS)",
23+
"version": version,
24+
"releaseDateUtc": current_date_str,
25+
"organization": "OWASP",
26+
"informationUri": "https://mas.owasp.org/MASVS/",
27+
"downloadUri": "https://github.com/OWASP/owasp-masvs/releases"
28+
}
29+
},
30+
"taxonomies": [{
31+
"name": "OWASP MASVS",
32+
"guid": MASVS_SARIF_GUID,
33+
"isComprehensive": True,
34+
"taxa": []
35+
}]
36+
}]
37+
}
38+
39+
# Counter to ensure we capture the total number of controls
40+
total_controls_count = 0
41+
42+
# Iterating through groups and their controls
43+
for group in masvs_parsed.get("groups", []):
44+
for control in group.get("controls", []):
45+
total_controls_count += 1
46+
taxa_element = {
47+
"id": control["id"],
48+
"name": control.get("id", ""),
49+
"shortDescription": {
50+
"text": control.get("statement", "")
51+
},
52+
"fullDescription": {
53+
"text": control.get("description", "")
54+
}
55+
}
56+
sarif_corrected_template["runs"][0]["taxonomies"][0]["taxa"].append(taxa_element)
57+
58+
# Verify the total number of taxa elements matches the total number of controls
59+
total_taxa_count = len(sarif_corrected_template["runs"][0]["taxonomies"][0]["taxa"])
60+
61+
# Save the correctly populated SARIF output
62+
sarif_corrected_output_path = 'OWASP_MASVS.sarif'
63+
with open(sarif_corrected_output_path, 'w') as file:
64+
json.dump(sarif_corrected_template, file, indent=2)

0 commit comments

Comments
 (0)