Skip to content

Commit 588663e

Browse files
committed
#6 fix potential xss issue
1 parent c656b54 commit 588663e

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

client/components/editor/Terminal.tsx

+15-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from 'react';
22

33
import { Paper, Divider, TextField, InputAdornment } from '@mui/material';
44

5+
import dompurify from 'dompurify';
6+
57
import Convert from 'ansi-to-html';
68

79
const convert = new Convert();
@@ -50,14 +52,19 @@ export default function Terminal(props: {
5052
<br />
5153

5254
<span className="terminal-command-output">
53-
{command.output.map((output: string): any => (
54-
<div>
55-
<td
56-
dangerouslySetInnerHTML={{ __html: convert.toHtml(output) }}
57-
style={{ paddingLeft: '16px' }}
58-
/>
59-
</div>
60-
))}
55+
{command.output.map((output: string): any => {
56+
const html = convert.toHtml(output);
57+
const sanitizer = dompurify.sanitize;
58+
59+
return (
60+
<div>
61+
<td
62+
dangerouslySetInnerHTML={{ __html: sanitizer(html) }}
63+
style={{ paddingLeft: '16px' }}
64+
/>
65+
</div>
66+
);
67+
})}
6168
</span>
6269
</div>
6370
))}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"body-parser": "^1.20.0",
3131
"chalk": "4.1.2",
3232
"cors": "^2.8.5",
33+
"dompurify": "^2.4.0",
3334
"express": "^4.18.1",
3435
"jsonwebtoken": "^8.5.1",
3536
"monaco-editor": "^0.34.0",
@@ -42,6 +43,7 @@
4243
},
4344
"devDependencies": {
4445
"@babel/core": "^7.19.3",
46+
"@types/dompurify": "^2.3.4",
4547
"@types/express": "^4.17.14",
4648
"@types/jest": "^29.1.1",
4749
"@types/jsonwebtoken": "^8.5.9",

yarn.lock

+17
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,13 @@
10541054
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080"
10551055
integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==
10561056

1057+
"@types/dompurify@^2.3.4":
1058+
version "2.3.4"
1059+
resolved "https://registry.yarnpkg.com/@types/dompurify/-/dompurify-2.3.4.tgz#94e997e30338ea24d4c8d08beca91ce4dd17a1b4"
1060+
integrity sha512-EXzDatIb5EspL2eb/xPGmaC8pePcTHrkDCONjeisusLFrVfl38Pjea/R0YJGu3k9ZQadSvMqW0WXPI2hEo2Ajg==
1061+
dependencies:
1062+
"@types/trusted-types" "*"
1063+
10571064
"@types/eslint-scope@^3.7.3":
10581065
version "3.7.4"
10591066
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16"
@@ -1262,6 +1269,11 @@
12621269
dependencies:
12631270
"@types/superagent" "*"
12641271

1272+
"@types/trusted-types@*":
1273+
version "2.0.2"
1274+
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756"
1275+
integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==
1276+
12651277
"@types/uuid@^8.3.4":
12661278
version "8.3.4"
12671279
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
@@ -2393,6 +2405,11 @@ dom-helpers@^5.0.1:
23932405
"@babel/runtime" "^7.8.7"
23942406
csstype "^3.0.2"
23952407

2408+
dompurify@^2.4.0:
2409+
version "2.4.0"
2410+
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.4.0.tgz#c9c88390f024c2823332615c9e20a453cf3825dd"
2411+
integrity sha512-Be9tbQMZds4a3C6xTmz68NlMfeONA//4dOavl/1rNw50E+/QO0KVpbcU0PcaW0nsQxurXls9ZocqFxk8R2mWEA==
2412+
23962413
dotenv-defaults@^2.0.2:
23972414
version "2.0.2"
23982415
resolved "https://registry.yarnpkg.com/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz#6b3ec2e4319aafb70940abda72d3856770ee77ac"

0 commit comments

Comments
 (0)