@daoyi/nmtl-ui 2.0.1-beta.135 → 2.0.1-beta.136
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.
|
@@ -50,8 +50,17 @@ const addNewWindowHint = function (html) {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
const HtmlToReactParser = require('html-to-react').Parser;
|
|
53
|
+
const DOMPurify = require('dompurify');
|
|
53
54
|
const htmlToReactParser = new HtmlToReactParser();
|
|
54
55
|
|
|
56
|
+
/* 後台文稿以 markdown-it(html: true)轉換,原始 HTML 會直接放行;轉成 React 之前必須先消毒,
|
|
57
|
+
擋掉 <script>、onerror、javascript: 等 XSS 向量(內容雖來自後台,仍做縱深防禦;比照主站 nmtl-web htmlEntities.js)。
|
|
58
|
+
用獨立實例:@daoyi/timeline 在全域 DOMPurify 掛了 hook,會把所有沒寫 target 的連結強制改成另開新視窗 */
|
|
59
|
+
const purify = DOMPurify(typeof window !== 'undefined' ? window : undefined);
|
|
60
|
+
const sanitize = html => purify.isSupported ? purify.sanitize(html, {
|
|
61
|
+
ADD_ATTR: ['target']
|
|
62
|
+
}) : html;
|
|
63
|
+
|
|
55
64
|
// full options list (defaults)
|
|
56
65
|
const md = require('markdown-it')({
|
|
57
66
|
html: true,
|
|
@@ -88,8 +97,8 @@ const md = require('markdown-it')({
|
|
|
88
97
|
// eslint-disable-next-line import/prefer-default-export
|
|
89
98
|
const convert2HtmlEntities = text => {
|
|
90
99
|
if (text === undefined) return '';
|
|
91
|
-
/*
|
|
92
|
-
return htmlToReactParser.parse(addNewWindowHint(md.render(text)));
|
|
100
|
+
/* 先消毒,再替 target="_blank" 的連結文字補「(另開新視窗)」(HM1240404E,2026-10-07) */
|
|
101
|
+
return htmlToReactParser.parse(addNewWindowHint(sanitize(md.render(text))));
|
|
93
102
|
};
|
|
94
103
|
|
|
95
104
|
/* eslint-disable react/no-danger */
|
|
@@ -2,8 +2,19 @@ import { a as addNewWindowHint } from './newWindowHint-db113a69.js';
|
|
|
2
2
|
import '../components/globalConfig';
|
|
3
3
|
|
|
4
4
|
var HtmlToReactParser = require('html-to-react').Parser;
|
|
5
|
+
var DOMPurify = require('dompurify');
|
|
5
6
|
var htmlToReactParser = new HtmlToReactParser();
|
|
6
7
|
|
|
8
|
+
/* 後台文稿以 markdown-it(html: true)轉換,原始 HTML 會直接放行;轉成 React 之前必須先消毒,
|
|
9
|
+
擋掉 <script>、onerror、javascript: 等 XSS 向量(內容雖來自後台,仍做縱深防禦;比照主站 nmtl-web htmlEntities.js)。
|
|
10
|
+
用獨立實例:@daoyi/timeline 在全域 DOMPurify 掛了 hook,會把所有沒寫 target 的連結強制改成另開新視窗 */
|
|
11
|
+
var purify = DOMPurify(typeof window !== 'undefined' ? window : undefined);
|
|
12
|
+
var sanitize = function sanitize(html) {
|
|
13
|
+
return purify.isSupported ? purify.sanitize(html, {
|
|
14
|
+
ADD_ATTR: ['target']
|
|
15
|
+
}) : html;
|
|
16
|
+
};
|
|
17
|
+
|
|
7
18
|
// full options list (defaults)
|
|
8
19
|
var md = require('markdown-it')({
|
|
9
20
|
html: true,
|
|
@@ -39,8 +50,8 @@ var md = require('markdown-it')({
|
|
|
39
50
|
// eslint-disable-next-line import/prefer-default-export
|
|
40
51
|
var convert2HtmlEntities = function convert2HtmlEntities(text) {
|
|
41
52
|
if (text === undefined) return '';
|
|
42
|
-
/*
|
|
43
|
-
return htmlToReactParser.parse(addNewWindowHint(md.render(text)));
|
|
53
|
+
/* 先消毒,再替 target="_blank" 的連結文字補「(另開新視窗)」(HM1240404E,2026-10-07) */
|
|
54
|
+
return htmlToReactParser.parse(addNewWindowHint(sanitize(md.render(text))));
|
|
44
55
|
};
|
|
45
56
|
|
|
46
57
|
export { convert2HtmlEntities as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daoyi/nmtl-ui",
|
|
3
3
|
"packageManager": "pnpm@10.34.5",
|
|
4
|
-
"version": "2.0.1-beta.
|
|
4
|
+
"version": "2.0.1-beta.136",
|
|
5
5
|
"description": "This project is to be used as a starter kit for building React component using Storybook and Rollup",
|
|
6
6
|
"author": "daoyi",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"d3-selection": "1.4.2",
|
|
27
27
|
"d3-transition": "1.3.2",
|
|
28
28
|
"dom-to-image": "2.6.0",
|
|
29
|
+
"dompurify": "2.5.8",
|
|
29
30
|
"formik": "2.2.9",
|
|
30
31
|
"html-to-react": "1.4.5",
|
|
31
32
|
"jquery": "3.6.0",
|