Skip to content

Commit 432406b

Browse files
committed
feat(metadata): add basic metadata validation
1 parent e0e4f1f commit 432406b

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

index.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ const envelopeSchema = Joi.object().keys({
6363
process: processSchema
6464
});
6565

66+
const metadataSchemaSAST = Joi.object().keys({
67+
lineContent: Joi.string().required(),
68+
confidence: Joi.string().optional(),
69+
severity: Joi.string().optional(),
70+
description: Joi.string().optional(),
71+
title: Joi.string().optional(),
72+
cweID: Joi.string().optional(),
73+
references: Joi.array().optional()
74+
});
75+
const metadataSchemaSCA = Joi.object().keys({});
6676
/* data loading */
6777

6878
function readFromStdin() {
@@ -102,12 +112,25 @@ Joi.validate(reportData, envelopeSchema, (err, value) => {
102112

103113
/* validating the line items */
104114
reportData.output.forEach(lineItem => {
105-
let schema = lineitemSchema;
106-
Joi.validate(lineItem, schema, (err, value) => {
115+
Joi.validate(lineItem, lineitemSchema, (err, value) => {
107116
if (err) {
108117
console.log(err);
109118
} else {
110119
console.log(lineItem.type + " ✅");
111120
}
112121
});
122+
let metadataSchema;
123+
if (lineItem.type == "issue" || lineItem.type == "secret") {
124+
metadataSchema = metadataSchemaSAST;
125+
} else if (lineItem.type == "advisory") {
126+
metadataSchema = metadataSchemaSCA;
127+
}
128+
129+
Joi.validate(lineItem.metadata, metadataSchema, (err, value) => {
130+
if (err) {
131+
console.log(err);
132+
} else {
133+
console.log(lineItem.type + " metadata ✅");
134+
}
135+
});
113136
});

test/fixtures/brakeman.json

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"references": [
3030
"https://brakemanscanner.org/docs/warning_types/unsafe_deserialization"
3131
],
32-
"confidence": "Medium"
32+
"confidence": "Medium",
33+
"lineContent": "sometext"
3334
}
3435
},
3536
{
@@ -49,7 +50,8 @@
4950
"references": [
5051
"https://brakemanscanner.org/docs/warning_types/sql_injection/"
5152
],
52-
"confidence": "Medium"
53+
"confidence": "Medium",
54+
"lineContent": "sometext"
5355
}
5456
},
5557
{
@@ -69,7 +71,8 @@
6971
"references": [
7072
"https://brakemanscanner.org/docs/warning_types/dangerous_send/"
7173
],
72-
"confidence": "High"
74+
"confidence": "High",
75+
"lineContent": "sometext"
7376
}
7477
},
7578
{
@@ -89,7 +92,8 @@
8992
"references": [
9093
"https://brakemanscanner.org/docs/warning_types/session_setting/"
9194
],
92-
"confidence": "High"
95+
"confidence": "High",
96+
"lineContent": "sometext"
9397
}
9498
},
9599
{
@@ -109,7 +113,8 @@
109113
"references": [
110114
"https://brakemanscanner.org/docs/warning_types/cross-site_request_forgery/"
111115
],
112-
"confidence": "High"
116+
"confidence": "High",
117+
"lineContent": "sometext"
113118
}
114119
},
115120
{
@@ -129,7 +134,8 @@
129134
"references": [
130135
"https://brakemanscanner.org/docs/warning_types/session_setting/"
131136
],
132-
"confidence": "High"
137+
"confidence": "High",
138+
"lineContent": "sometext"
133139
}
134140
},
135141
{
@@ -149,7 +155,8 @@
149155
"references": [
150156
"https://brakemanscanner.org/docs/warning_types/session_setting/"
151157
],
152-
"confidence": "High"
158+
"confidence": "High",
159+
"lineContent": "sometext"
153160
}
154161
},
155162
{
@@ -169,7 +176,8 @@
169176
"references": [
170177
"https://brakemanscanner.org/docs/warning_types/remote_code_execution/"
171178
],
172-
"confidence": "High"
179+
"confidence": "High",
180+
"lineContent": "sometext"
173181
}
174182
},
175183
{
@@ -189,7 +197,8 @@
189197
"references": [
190198
"https://brakemanscanner.org/docs/warning_types/mass_assignment/"
191199
],
192-
"confidence": "High"
200+
"confidence": "High",
201+
"lineContent": "sometext"
193202
}
194203
},
195204
{
@@ -209,7 +218,8 @@
209218
"references": [
210219
"https://brakemanscanner.org/docs/warning_types/sql_injection/"
211220
],
212-
"confidence": "High"
221+
"confidence": "High",
222+
"lineContent": "sometext"
213223
}
214224
},
215225
{
@@ -229,7 +239,8 @@
229239
"references": [
230240
"https://brakemanscanner.org/docs/warning_types/mass_assignment/"
231241
],
232-
"confidence": "Medium"
242+
"confidence": "Medium",
243+
"lineContent": "sometext"
233244
}
234245
},
235246
{
@@ -249,7 +260,8 @@
249260
"references": [
250261
"https://brakemanscanner.org/docs/warning_types/format_validation/"
251262
],
252-
"confidence": "High"
263+
"confidence": "High",
264+
"lineContent": "sometext"
253265
}
254266
},
255267
{
@@ -269,7 +281,8 @@
269281
"references": [
270282
"https://brakemanscanner.org/docs/warning_types/command_injection/"
271283
],
272-
"confidence": "Medium"
284+
"confidence": "Medium",
285+
"lineContent": "sometext"
273286
}
274287
},
275288
{
@@ -289,7 +302,8 @@
289302
"references": [
290303
"https://brakemanscanner.org/docs/warning_types/remote_code_execution/"
291304
],
292-
"confidence": "High"
305+
"confidence": "High",
306+
"lineContent": "sometext"
293307
}
294308
},
295309
{
@@ -309,7 +323,8 @@
309323
"references": [
310324
"https://brakemanscanner.org/docs/warning_types/file_access/"
311325
],
312-
"confidence": "High"
326+
"confidence": "High",
327+
"lineContent": "sometext"
313328
}
314329
},
315330
{
@@ -329,7 +344,8 @@
329344
"references": [
330345
"https://brakemanscanner.org/docs/warning_types/cross-site_scripting/"
331346
],
332-
"confidence": "High"
347+
"confidence": "High",
348+
"lineContent": "sometext"
333349
}
334350
},
335351
{
@@ -349,7 +365,8 @@
349365
"references": [
350366
"https://brakemanscanner.org/docs/warning_types/remote_code_execution/"
351367
],
352-
"confidence": "High"
368+
"confidence": "High",
369+
"lineContent": "sometext"
353370
}
354371
}
355372
],

0 commit comments

Comments
 (0)