Skip to content

Commit 1c14206

Browse files
Merge pull request #176 from TNG/severity-in-report
Added severity to markdown report
2 parents 6c55352 + f6ebe98 commit 1c14206

File tree

2 files changed

+65
-79
lines changed

2 files changed

+65
-79
lines changed

src/server/__tests__/server.test.js

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -326,62 +326,38 @@ it('Download threat file', async () => {
326326
expect(response.text).toBe(`Threats ${date}
327327
=======
328328
329-
**1. title**
330-
331-
- *Author:* Player 1
332-
333-
- *Description:* <img src="" onerror="alert\\('XSS'\\) alt="Uh oh...">
334-
335-
- *Mitigation:* mitigation
336-
337-
338-
**2. title**
339-
340-
- *Author:* Player 1
341-
342-
- *Description:* description
343-
344-
- *Mitigation:* mitigation
345-
346-
347-
**3. title**
348-
349-
- *Author:* Player 1
350-
351-
- *Description:* description
352-
353-
- *Mitigation:* mitigation
354-
355-
356-
**4. Accessing DB credentials**
357-
358-
- *Description:* The Background Worker configuration stores the credentials used by the worker to access the DB. An attacker could compromise the Background Worker and get access to the DB credentials.
359-
360-
- *Mitigation:* \\[Click Me\\]\\(javascript:alert\\('XSS'\\)\\)
361-
362-
363-
**5. Unauthorised access**
364-
365-
- *Description:* An attacker could make an query call on the DB,
366-
367-
- *Mitigation:* Require all queries to be authenticated.
368-
369-
370-
**6. Credential theft**
371-
372-
- *Author:* The Model
373-
374-
- *Description:* An attacker could obtain the DB credentials ans use them to make unauthorised queries.
375-
376-
- *Mitigation:* Use a firewall to restrict access to the DB to only the Background Worker IP address.
377-
378-
379-
**7. \\!\\[Uh oh...\\]\\(https://www.example.com/image.png"onload="alert\\('XSS'\\)\\)**
380-
381-
- *Description:* The Web Application Config stores credentials used by the Web App to access the message queue. These could be stolen by an attacker and used to read confidential data or place poison message on the queue.
382-
383-
- *Mitigation:* The Message Queue credentials should be encrypted. newlines shouldn't break the formatting
384-
329+
1. **title**
330+
- *Severity:* High
331+
- *Author:* Player 1
332+
- *Description:* <img src="" onerror="alert\\('XSS'\\) alt="Uh oh...">
333+
- *Mitigation:* mitigation
334+
2. **title**
335+
- *Severity:* High
336+
- *Author:* Player 1
337+
- *Description:* description
338+
- *Mitigation:* mitigation
339+
3. **title**
340+
- *Severity:* High
341+
- *Author:* Player 1
342+
- *Description:* description
343+
- *Mitigation:* mitigation
344+
4. **Accessing DB credentials**
345+
- *Severity:* High
346+
- *Description:* The Background Worker configuration stores the credentials used by the worker to access the DB. An attacker could compromise the Background Worker and get access to the DB credentials.
347+
- *Mitigation:* \\[Click Me\\]\\(javascript:alert\\('XSS'\\)\\)
348+
5. **Unauthorised access**
349+
- *Severity:* High
350+
- *Description:* An attacker could make an query call on the DB,
351+
- *Mitigation:* Require all queries to be authenticated.
352+
6. **Credential theft**
353+
- *Severity:* Medium
354+
- *Author:* The Model
355+
- *Description:* An attacker could obtain the DB credentials ans use them to make unauthorised queries.
356+
- *Mitigation:* Use a firewall to restrict access to the DB to only the Background Worker IP address.
357+
7. **\\!\\[Uh oh...\\]\\(https://www.example.com/image.png"onload="alert\\('XSS'\\)\\)**
358+
- *Severity:* High
359+
- *Description:* The Web Application Config stores credentials used by the Web App to access the message queue. These could be stolen by an attacker and used to read confidential data or place poison message on the queue.
360+
- *Mitigation:* The Message Queue credentials should be encrypted. newlines shouldn't break the formatting
385361
`);
386362
});
387363

src/server/endpoints.js

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -277,32 +277,42 @@ function getThreats(gameState, metadata, model) {
277277
function formatThreats(threats, date) {
278278
return `Threats ${date}
279279
=======
280-
${threats
281-
.map(
282-
(threat, index) => `
283-
**${index + 1}. ${escapeMarkdownText(threat.title.trim())}**
284-
${
285-
'owner' in threat
286-
? `
287-
- *Author:* ${escapeMarkdownText(threat.owner)}
288-
`
289-
: ''
280+
281+
${threats.map(formatSingleThreat).join('\n')}
282+
`;
290283
}
291-
- *Description:* ${
292-
escapeMarkdownText(
293-
threat.description.replace(/(\r|\n)+/gm, ' '),
294-
) /* Stops newlines breaking md formatting */
284+
285+
function formatSingleThreat(threat, index) {
286+
const lines = [
287+
`${index + 1}. **${escapeMarkdownText(threat.title.trim())}**`,
288+
];
289+
290+
if ('severity' in threat) {
291+
lines.push(` - *Severity:* ${escapeMarkdownText(threat.severity)}`);
292+
}
293+
294+
if ('owner' in threat) {
295+
lines.push(` - *Author:* ${escapeMarkdownText(threat.owner)}`);
295296
}
296297

297-
${
298-
threat.mitigation !== `No mitigation provided.`
299-
? ` - *Mitigation:* ${escapeMarkdownText(
298+
if ('description' in threat) {
299+
lines.push(
300+
` - *Description:* ${escapeMarkdownText(
301+
threat.description.replace(/(\r|\n)+/gm, ' '),
302+
)}`,
303+
);
304+
}
305+
306+
if (
307+
'mitigation' in threat &&
308+
threat.mitigation !== `No mitigation provided.`
309+
) {
310+
lines.push(
311+
` - *Mitigation:* ${escapeMarkdownText(
300312
threat.mitigation.replace(/(\r|\n)+/gm, ' '),
301-
)}
313+
)}`,
314+
);
315+
}
302316

303-
`
304-
: ''
305-
}`,
306-
)
307-
.join('')}`;
317+
return lines.join('\n');
308318
}

0 commit comments

Comments
 (0)