fhir-react 2.1.1 → 2.1.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/index.js +5 -5
- package/package.json +1 -1
- package/src/components/datatypes/Markdown/Markdown.js +38 -15
package/package.json
CHANGED
|
@@ -3,31 +3,54 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import marked from 'marked';
|
|
4
4
|
import DOMPurify from 'dompurify';
|
|
5
5
|
|
|
6
|
-
// Prevent reverse-tabnabbing: any link with target="_blank" gets
|
|
7
|
-
// rel="noopener noreferrer" enforced after sanitization. This runs at module
|
|
8
|
-
// level instead of in Markdown component so it isn't re-registered on every render
|
|
9
|
-
DOMPurify.addHook('afterSanitizeAttributes', node => {
|
|
10
|
-
if (node.tagName === 'A' && node.getAttribute('target') === '_blank') {
|
|
11
|
-
node.setAttribute('rel', 'noopener noreferrer');
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
6
|
const Markdown = props => {
|
|
16
7
|
const { fhirData } = props;
|
|
17
8
|
const markdown = String(fhirData);
|
|
18
9
|
let html = null;
|
|
19
10
|
try {
|
|
20
11
|
const unsafeHTML = marked(markdown, { gfm: true });
|
|
21
|
-
|
|
12
|
+
// RETURN_DOM returns a <body> element rather than an HTML string, so the
|
|
13
|
+
// reverse-tabnabbing fix below can use querySelectorAll and innerHTML.
|
|
14
|
+
// A DOMPurify hook would be the usual approach, but it must be registered
|
|
15
|
+
// at module load, which throws under SSR where dompurify has no window.
|
|
16
|
+
const sanitized = DOMPurify.sanitize(unsafeHTML, {
|
|
17
|
+
RETURN_DOM: true,
|
|
22
18
|
ALLOWED_TAGS: [
|
|
23
|
-
'p',
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
19
|
+
'p',
|
|
20
|
+
'br',
|
|
21
|
+
'strong',
|
|
22
|
+
'em',
|
|
23
|
+
'b',
|
|
24
|
+
'i',
|
|
25
|
+
'u',
|
|
26
|
+
's',
|
|
27
|
+
'code',
|
|
28
|
+
'pre',
|
|
29
|
+
'blockquote',
|
|
30
|
+
'ul',
|
|
31
|
+
'ol',
|
|
32
|
+
'li',
|
|
33
|
+
'h1',
|
|
34
|
+
'h2',
|
|
35
|
+
'h3',
|
|
36
|
+
'h4',
|
|
37
|
+
'h5',
|
|
38
|
+
'h6',
|
|
39
|
+
'a',
|
|
40
|
+
'hr',
|
|
41
|
+
'table',
|
|
42
|
+
'thead',
|
|
43
|
+
'tbody',
|
|
44
|
+
'tr',
|
|
45
|
+
'th',
|
|
46
|
+
'td',
|
|
28
47
|
],
|
|
29
48
|
ALLOWED_ATTR: ['href', 'title', 'target', 'class', 'id'],
|
|
30
49
|
});
|
|
50
|
+
sanitized.querySelectorAll('a[target="_blank"]').forEach(anchor => {
|
|
51
|
+
anchor.setAttribute('rel', 'noopener noreferrer');
|
|
52
|
+
});
|
|
53
|
+
html = sanitized.innerHTML;
|
|
31
54
|
} catch {}
|
|
32
55
|
|
|
33
56
|
const dangerouslySetInnerHTML = html ? { __html: html } : null;
|