Skip to content

Commit 15b25cf

Browse files
RamiSouaiJ12934
authored andcommitted
#519: Added references attribute to semgrep findings
Signed-off-by: Rami Souai <rami.souai@iteratec.com>
1 parent 01dfcdf commit 15b25cf

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

‎scanners/semgrep/parser/parser.js‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,33 @@ async function parse(fileContent) {
2525
// severity of the issue: translate semgrep severity levels (INFO, WARNING, ERROR) to those of SCB (INFORMATIONAL, LOW, MEDIUM, HIGH)
2626
const severity = severityMap.has(result.extra.severity.toLowerCase()) ? severityMap.get(result.extra.severity.toLowerCase()) : "INFORMATIONAL"
2727

28+
29+
const references = result.extra.metadata?.references?.map((link) => {
30+
return {
31+
"type": "URL",
32+
"value": link,
33+
}
34+
});
35+
36+
if(result.extra.metadata.cwe != null) {
37+
const cweReference = result.extra.metadata.cwe.substring(4,6);
38+
references.push(
39+
{
40+
"type": "CWE",
41+
"value": `CWE-${cweReference}`
42+
},
43+
{
44+
"type": "URL",
45+
"value": `https://cwe.mitre.org/data/definitions/${cweReference}.html`
46+
});
47+
}
2848
const attributes = {
2949
// Common weakness enumeration, if available
3050
"cwe": result.extra.metadata.cwe || null,
3151
// OWASP category, if available
3252
"owasp_category": result.extra.metadata.owasp || null,
3353
// References given in the rule
34-
"references": result.extra.metadata.references || null,
54+
"references": references || null,
3555
// Link to the semgrep rule
3656
"rule_source": result.extra.metadata.source || null,
3757
// Which line of code matched?

‎scanners/semgrep/parser/parser.test.js‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@ test("should properly parse file with a single result", async () => {
5555
"cwe": "CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')",
5656
"owasp_category": "A1: Injection",
5757
"references": [
58-
"https://owasp.org/www-community/attacks/Command_Injection",
58+
{
59+
"type": "URL",
60+
"value": "https://owasp.org/www-community/attacks/Command_Injection",
61+
},
62+
{
63+
"type": "CWE",
64+
"value": "CWE-78",
65+
},
66+
{
67+
"type": "URL",
68+
"value": "https://cwe.mitre.org/data/definitions/78.html",
69+
},
5970
],
6071
"rule_source": "https://semgrep.dev/r/python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
6172
},
@@ -86,7 +97,18 @@ test("should properly parse file with multiple results", async () => {
8697
"cwe": "CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')",
8798
"owasp_category": "A1: Injection",
8899
"references": [
89-
"https://owasp.org/www-community/attacks/Command_Injection",
100+
{
101+
"type": "URL",
102+
"value": "https://owasp.org/www-community/attacks/Command_Injection",
103+
},
104+
{
105+
"type": "CWE",
106+
"value": "CWE-78",
107+
},
108+
{
109+
"type": "URL",
110+
"value": "https://cwe.mitre.org/data/definitions/78.html",
111+
},
90112
],
91113
"rule_source": "https://semgrep.dev/r/python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
92114
},
@@ -101,7 +123,18 @@ test("should properly parse file with multiple results", async () => {
101123
"cwe": "CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')",
102124
"owasp_category": "A1: Injection",
103125
"references": [
104-
"https://owasp.org/www-community/attacks/Command_Injection",
126+
{
127+
"type": "URL",
128+
"value": "https://owasp.org/www-community/attacks/Command_Injection",
129+
},
130+
{
131+
"type": "CWE",
132+
"value": "CWE-78",
133+
},
134+
{
135+
"type": "URL",
136+
"value": "https://cwe.mitre.org/data/definitions/78.html",
137+
},
105138
],
106139
"rule_source": "https://semgrep.dev/r/python.django.security.injection.command.command-injection-os-system.command-injection-os-system",
107140
},

0 commit comments

Comments
 (0)