|
| 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