Skip to content

Commit d57f93b

Browse files
committed
json-writer: add CWE links to mitre.org in SARIF
1 parent db90a89 commit d57f93b

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/json-writer.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,21 @@ void SarifTreeEncoder::serializeCweMap()
165165

166166
PTree cweList;
167167
const auto cwe = item.second;
168-
const auto cweStr = "CWE-" + std::to_string(cwe);
169-
appendNode(&cweList, PTree(cweStr));
168+
const auto cweStr = std::to_string(cwe);
169+
appendNode(&cweList, PTree("CWE-" + cweStr));
170170

171+
// properties.cwe[]
171172
PTree props;
172173
props.put_child("cwe", cweList);
173174
rule.put_child("properties", props);
174175

176+
// help.text
177+
PTree help;
178+
const auto helpText =
179+
"https://cwe.mitre.org/data/definitions/" + cweStr + ".html";
180+
help.put<std::string>("text", helpText);
181+
rule.put_child("help", help);
182+
175183
appendNode(&ruleList, rule);
176184
}
177185

tests/csgrep/81-sarif-writer-stdout.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"cwe": [
1616
"CWE-762"
1717
]
18+
},
19+
"help": {
20+
"text": "https://cwe.mitre.org/data/definitions/762.html"
1821
}
1922
},
2023
{
@@ -23,6 +26,9 @@
2326
"cwe": [
2427
"CWE-252"
2528
]
29+
},
30+
"help": {
31+
"text": "https://cwe.mitre.org/data/definitions/252.html"
2632
}
2733
},
2834
{
@@ -31,6 +37,9 @@
3137
"cwe": [
3238
"CWE-569"
3339
]
40+
},
41+
"help": {
42+
"text": "https://cwe.mitre.org/data/definitions/569.html"
3443
}
3544
},
3645
{
@@ -39,6 +48,9 @@
3948
"cwe": [
4049
"CWE-569"
4150
]
51+
},
52+
"help": {
53+
"text": "https://cwe.mitre.org/data/definitions/569.html"
4254
}
4355
},
4456
{
@@ -47,6 +59,9 @@
4759
"cwe": [
4860
"CWE-561"
4961
]
62+
},
63+
"help": {
64+
"text": "https://cwe.mitre.org/data/definitions/561.html"
5065
}
5166
},
5267
{
@@ -55,6 +70,9 @@
5570
"cwe": [
5671
"CWE-561"
5772
]
73+
},
74+
"help": {
75+
"text": "https://cwe.mitre.org/data/definitions/561.html"
5876
}
5977
},
6078
{
@@ -63,6 +81,9 @@
6381
"cwe": [
6482
"CWE-561"
6583
]
84+
},
85+
"help": {
86+
"text": "https://cwe.mitre.org/data/definitions/561.html"
6687
}
6788
},
6889
{
@@ -71,6 +92,9 @@
7192
"cwe": [
7293
"CWE-476"
7394
]
95+
},
96+
"help": {
97+
"text": "https://cwe.mitre.org/data/definitions/476.html"
7498
}
7599
},
76100
{
@@ -79,6 +103,9 @@
79103
"cwe": [
80104
"CWE-687"
81105
]
106+
},
107+
"help": {
108+
"text": "https://cwe.mitre.org/data/definitions/687.html"
82109
}
83110
},
84111
{
@@ -87,6 +114,9 @@
87114
"cwe": [
88115
"CWE-119"
89116
]
117+
},
118+
"help": {
119+
"text": "https://cwe.mitre.org/data/definitions/119.html"
90120
}
91121
},
92122
{
@@ -95,6 +125,9 @@
95125
"cwe": [
96126
"CWE-119"
97127
]
128+
},
129+
"help": {
130+
"text": "https://cwe.mitre.org/data/definitions/119.html"
98131
}
99132
},
100133
{
@@ -103,6 +136,9 @@
103136
"cwe": [
104137
"CWE-125"
105138
]
139+
},
140+
"help": {
141+
"text": "https://cwe.mitre.org/data/definitions/125.html"
106142
}
107143
},
108144
{
@@ -111,6 +147,9 @@
111147
"cwe": [
112148
"CWE-686"
113149
]
150+
},
151+
"help": {
152+
"text": "https://cwe.mitre.org/data/definitions/686.html"
114153
}
115154
},
116155
{
@@ -119,6 +158,9 @@
119158
"cwe": [
120159
"CWE-404"
121160
]
161+
},
162+
"help": {
163+
"text": "https://cwe.mitre.org/data/definitions/404.html"
122164
}
123165
},
124166
{
@@ -127,6 +169,9 @@
127169
"cwe": [
128170
"CWE-404"
129171
]
172+
},
173+
"help": {
174+
"text": "https://cwe.mitre.org/data/definitions/404.html"
130175
}
131176
},
132177
{
@@ -135,6 +180,9 @@
135180
"cwe": [
136181
"CWE-170"
137182
]
183+
},
184+
"help": {
185+
"text": "https://cwe.mitre.org/data/definitions/170.html"
138186
}
139187
},
140188
{
@@ -143,6 +191,9 @@
143191
"cwe": [
144192
"CWE-120"
145193
]
194+
},
195+
"help": {
196+
"text": "https://cwe.mitre.org/data/definitions/120.html"
146197
}
147198
},
148199
{
@@ -151,6 +202,9 @@
151202
"cwe": [
152203
"CWE-367"
153204
]
205+
},
206+
"help": {
207+
"text": "https://cwe.mitre.org/data/definitions/367.html"
154208
}
155209
}
156210
]

0 commit comments

Comments
 (0)