From b9489a331baf65e856629814f68c6b74f495c863 Mon Sep 17 00:00:00 2001 From: 50 Date: Tue, 14 Dec 2021 10:02:49 +0800 Subject: [PATCH] fix: Add sanitizer for filtering HTML tags (#744) * fix: Add sanitizer for filtering HTML tags * fix: Do not share `markdown-it` instances * chore: fix lint Co-authored-by: wangsongc --- README-EN.md | 3 +- README.md | 3 +- src/dev/editor.vue | 9 ++- src/lib/core/rules.js | 34 ----------- src/lib/core/sanitizer.js | 31 ++++++++++ src/lib/mixins/markdown.js | 112 ++++++++++++++++++++----------------- src/mavon-editor.vue | 62 ++------------------ 7 files changed, 107 insertions(+), 147 deletions(-) delete mode 100644 src/lib/core/rules.js create mode 100644 src/lib/core/sanitizer.js diff --git a/README-EN.md b/README-EN.md index 56ada70d2..ff09b689b 100644 --- a/README-EN.md +++ b/README-EN.md @@ -123,7 +123,8 @@ export default { | imageFilter | Function | null | Image file filter Function, params is a `File Object`, you should return `Boolean` about the test result | | imageClick | function | null | Image Click Function | | tabSize | Number | null | How many spaces equals one tab, default \t | -| xssOptions | Object | {} | xss rule configuration, enabled by default, set to false to turn off, custom rule reference [https://jsxss.com/zh/options.html](https://jsxss.com/zh/options.html) | +| html | Boolean | true | Enable HTML tags in source, for historical reasons this tag has always been true by default, but it is recommended to turn it off if you don't need this feature, as doing so it eliminates the security vulnerabilities altogether. | +| xssOptions | Object | {} | xss rules configuration, enabled by default, set to false to turn off, enabled will filter HTML tags, the default filter all HTML tag attributes, it is recommended to configure the whitelist on demand to reduce the possibility of being attacked.
- custom rule reference: [https://jsxss.com/zh/options.html](https://jsxss.com/zh/options.html)
- Demo: [dev-demo](./src/dev/editor.vue) | | toolbars | Object | As in the following example | toolbars | #### toolbars diff --git a/README.md b/README.md index dca73d141..1e5afc5f9 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,8 @@ export default { | imageFilter | function | null | 图片过滤函数,参数为一个`File Object`,要求返回一个`Boolean`, `true`表示文件合法,`false`表示文件不合法 | | imageClick | function | null | 图片点击事件,默认为预览,可覆盖 | | tabSize | Number | \t | tab转化为几个空格,默认为\t | -| xssOptions | Object | {} | xss规则配置, 默认开启,设置false可以关闭,自定义规则参考 [https://jsxss.com/zh/options.html](https://jsxss.com/zh/options.html) | +| html | Boolean | true | 启用HTML标签,因为历史原因这个标记一直默认为true,但建议不使用HTML标签就关闭它,它能彻底杜绝安全问题。 | +| xssOptions | Object | {} | xss规则配置, 默认开启,设置false可以关闭,开启后会对HTML标签进行过滤,默认过滤所有HTML标签属性,建议按需配置白名单减少被攻击的可能。
- 自定义规则参考: [https://jsxss.com/zh/options.html](https://jsxss.com/zh/options.html)
- 参考DEMO: [dev-demo](./src/dev/editor.vue) | | toolbars | Object | 如下例 | 工具栏 | #### toolbars diff --git a/src/dev/editor.vue b/src/dev/editor.vue index c8b5c5734..57391f8e9 100644 --- a/src/dev/editor.vue +++ b/src/dev/editor.vue @@ -1,7 +1,7 @@