Skip to content

Commit

Permalink
Added threat category to markdown export
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophNiehoff committed Jun 9, 2023
1 parent 1574fe9 commit addaebb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/server/__tests__/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,19 @@ it('Download threat file', async () => {
=======
1. **title**
- *Category:* Spoofing
- *Severity:* High
- *Author:* Player 1
- *Description:* <img src="" onerror="alert\\('XSS'\\) alt="Uh oh...">
- *Mitigation:* mitigation
2. **title**
- *Category:* Spoofing
- *Severity:* High
- *Author:* Player 1
- *Description:* description
- *Mitigation:* mitigation
3. **title**
- *Category:* Spoofing
- *Severity:* High
- *Author:* Player 1
- *Description:* description
Expand Down
19 changes: 17 additions & 2 deletions src/server/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import send from 'koa-send';
import request from 'superagent';
import { v4 as uuidv4 } from 'uuid';
import { ElevationOfPrivilege } from '../game/eop';
import { getSuitDisplayName } from '../utils/cardDefinitions';
import { getSuitDisplayName, isSuit } from '../utils/cardDefinitions';
import { DEFAULT_MODEL, ModelType } from '../utils/constants';
import { GameMode } from '../utils/GameMode';
import { INTERNAL_API_PORT } from '../utils/serverConfig';
Expand Down Expand Up @@ -244,9 +244,20 @@ export const downloadThreatsMarkdownFile = (gameServer) => async (ctx) => {
logEvent(`Download threats: ${matchID}`);
ctx.attachment(filename);
ctx.set('Access-Control-Expose-Headers', 'Content-Disposition');
ctx.body = formatThreats(threats, date);
ctx.body = formatThreats(threats.map(threat => enrichThreatWithCategory(threat, game.state.G.gameMode)), date);
};

function enrichThreatWithCategory(threat, gameMode) {
if (threat.type && isSuit(threat.type)) {
return ({
...threat,
category: getSuitDisplayName(gameMode, threat.type)
});
}

return threat;
}

function getThreats(gameState, metadata, model) {
var threats = [];

Expand Down Expand Up @@ -295,6 +306,10 @@ function formatSingleThreat(threat, index) {
`${index + 1}. **${escapeMarkdownText(threat.title.trim())}**`,
];

if ('category' in threat) {
lines.push(` - *Category:* ${escapeMarkdownText(threat.category)}`);
}

if ('severity' in threat) {
lines.push(` - *Severity:* ${escapeMarkdownText(threat.severity)}`);
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/cardDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ const CARD_DECKS: CardDeckDefinitions = {
},
};

export function isSuit(str: string): str is Suit {
return ['A', 'B', 'C', 'D', 'E', 'T'].includes(str);
}

export function getStartingCard(gameMode: GameMode, suit: Suit): Card {
const usedSuit =
CARD_DECKS[gameMode][suit].cards.length > 0
Expand Down

0 comments on commit addaebb

Please sign in to comment.