File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 47
47
"array-move" : " ^4.0.0" ,
48
48
"browserfs" : " ^1.4.3" ,
49
49
"classnames" : " ^2.3.2" ,
50
+ "dompurify" : " ^3.1.6" ,
50
51
"flexboxgrid" : " ^6.3.1" ,
51
52
"flexboxgrid-helpers" : " ^1.1.3" ,
52
53
"hastscript" : " ^9.0.0" ,
109
110
"@testing-library/jest-dom" : " ^6.0.0" ,
110
111
"@testing-library/react" : " ^14.0.0" ,
111
112
"@testing-library/user-event" : " ^14.4.3" ,
113
+ "@types/dompurify" : " ^3.0.5" ,
112
114
"@types/estree" : " ^1.0.5" ,
113
115
"@types/gapi" : " ^0.0.44" ,
114
116
"@types/gapi.auth2" : " ^0.0.57" ,
Original file line number Diff line number Diff line change 1
1
import { Classes } from '@blueprintjs/core' ;
2
2
import classNames from 'classnames' ;
3
+ import DOMPurify from 'dompurify' ;
3
4
import React from 'react' ;
4
5
import { Converter } from 'showdown' ;
5
6
@@ -24,7 +25,12 @@ const Markdown: React.FC<Props> = props => {
24
25
return (
25
26
< div
26
27
className = { classNames ( props . className ? props . className : 'md' , Classes . RUNNING_TEXT ) }
27
- dangerouslySetInnerHTML = { { __html : converter . makeHtml ( props . content ) } }
28
+ dangerouslySetInnerHTML = { {
29
+ __html : DOMPurify . sanitize ( converter . makeHtml ( props . content ) , {
30
+ USE_PROFILES : { html : true } ,
31
+ ADD_ATTR : [ 'target' ]
32
+ } )
33
+ } }
28
34
/>
29
35
) ;
30
36
} ;
Original file line number Diff line number Diff line change @@ -6,10 +6,10 @@ exports[`Markdown page renders correctly 1`] = `
6
6
dangerouslySetInnerHTML = {
7
7
Object {
8
8
" __html" : " <p>Welcome to the Source Academy playground!</p>
9
- <p >The book <a href =\\"https://sourceacademy.org/sicpjs/ \\" rel =\\"noopener noreferrer\\" target =\\"_blank \\"><em>Structure and Interpretation of Computer Programs, JavaScript Edition</em></a>
10
- uses JavaScript sublanguages that we call <a href =\\"https://docs.sourceacademy.org/ \\" rel =\\"noopener noreferrer\\" target =\\"_blank \\"><em>Source</em></a>. You have chosen the sublanguage <a href =\\"https://docs.sourceacademy.org/source_1/ \\" rel =\\"noopener noreferrer\\" target =\\"_blank \\"><em>Source §1</em></a>.</p>
11
- <p>In the editor on the left, you can use the <a href =\\"https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts \\" rel =\\"noopener noreferrer\\" target =\\"_blank \\"><em>Ace keyboard shortcuts</em></a>
12
- and also the <a href =\\"https://github.com/source-academy/frontend/wiki/Source-Academy-Keyboard-Shortcuts\\" rel =\\"noopener noreferrer\\" target =\\"_blank \\"><em>Source Academy keyboard shortcuts</em></a>.</p>",
9
+ <p >The book <a target =\\"_blank \\" rel =\\"noopener noreferrer\\" href =\\"https://sourceacademy.org/sicpjs/ \\"><em>Structure and Interpretation of Computer Programs, JavaScript Edition</em></a>
10
+ uses JavaScript sublanguages that we call <a target =\\"_blank \\" rel =\\"noopener noreferrer\\" href =\\"https://docs.sourceacademy.org/ \\"><em>Source</em></a>. You have chosen the sublanguage <a target =\\"_blank \\" rel =\\"noopener noreferrer\\" href =\\"https://docs.sourceacademy.org/source_1/ \\"><em>Source §1</em></a>.</p>
11
+ <p>In the editor on the left, you can use the <a target =\\"_blank \\" rel =\\"noopener noreferrer\\" href =\\"https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts \\"><em>Ace keyboard shortcuts</em></a>
12
+ and also the <a target =\\"_blank\\" rel =\\"noopener noreferrer\\" href =\\"https://github.com/source-academy/frontend/wiki/Source-Academy-Keyboard-Shortcuts\\"><em>Source Academy keyboard shortcuts</em></a>.</p>",
13
13
}
14
14
}
15
15
/>
Original file line number Diff line number Diff line change 2936
2936
dependencies:
2937
2937
"@types/ms" "*"
2938
2938
2939
+ "@types/dompurify@^3.0.5":
2940
+ version "3.0.5"
2941
+ resolved "https://registry.yarnpkg.com/@types/dompurify/-/dompurify-3.0.5.tgz#02069a2fcb89a163bacf1a788f73cb415dd75cb7"
2942
+ integrity sha512-1Wg0g3BtQF7sSb27fJQAKck1HECM6zV1EB66j8JH9i3LCjYabJa0FSdiSgsD5K/RbrsR0SiraKacLB+T8ZVYAg==
2943
+ dependencies:
2944
+ "@types/trusted-types" "*"
2945
+
2939
2946
"@types/eslint@^7.29.0 || ^8.4.1":
2940
2947
version "8.21.1"
2941
2948
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.21.1.tgz#110b441a210d53ab47795124dbc3e9bb993d1e7c"
3279
3286
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"
3280
3287
integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==
3281
3288
3289
+ "@types/trusted-types@*":
3290
+ version "2.0.7"
3291
+ resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.7.tgz#baccb07a970b91707df3a3e8ba6896c57ead2d11"
3292
+ integrity sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==
3293
+
3282
3294
"@types/trusted-types@^2.0.2":
3283
3295
version "2.0.3"
3284
3296
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.3.tgz#a136f83b0758698df454e328759dbd3d44555311"
@@ -5950,6 +5962,11 @@ domhandler@^5.0.2, domhandler@^5.0.3:
5950
5962
dependencies:
5951
5963
domelementtype "^2.3.0"
5952
5964
5965
+ dompurify@^3.1.6:
5966
+ version "3.1.6"
5967
+ resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.1.6.tgz#43c714a94c6a7b8801850f82e756685300a027e2"
5968
+ integrity sha512-cTOAhc36AalkjtBpfG6O8JimdTMWNXjiePT2xQH/ppBGi/4uIpmj8eKyIkMJErXWARyINV/sB38yf8JCLF5pbQ==
5969
+
5953
5970
domutils@^1.7.0:
5954
5971
version "1.7.0"
5955
5972
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.7.0.tgz#56ea341e834e06e6748af7a1cb25da67ea9f8c2a"
You can’t perform that action at this time.
0 commit comments