From 4517eded009a2294f4e5b04bf3fbdb446ff3c3b0 Mon Sep 17 00:00:00 2001 From: ajaxzheng <894103554@qq.com> Date: Wed, 19 Mar 2025 11:11:29 +0800 Subject: [PATCH] docs: add XSS whitelist configuration FAQ (#3148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: add XSS whitelist configuration FAQ * docs: add XSS whitelist configuration FAQ * docs: 优化img白名单别表 * docs: 更新img白名单,移除重复的style属性 --- examples/sites/demos/pc/webdoc/faq.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/examples/sites/demos/pc/webdoc/faq.md b/examples/sites/demos/pc/webdoc/faq.md index 5d55b4ad5..0feb68fd9 100644 --- a/examples/sites/demos/pc/webdoc/faq.md +++ b/examples/sites/demos/pc/webdoc/faq.md @@ -85,3 +85,28 @@ module.exports = { transpileDependencies: ['@opentiny/fluent-editor', 'quill'] } ``` + +## 5、通过 `@opentiny/utils` 配置 `xss` 白名单(v3.21.0 开始支持) + +目前进行严格的过滤,建议使用 `JS-XSS` 进行处理。对不符合要求的代码片段做删除处理,若开发者在开发期间有其他 `HTML` 标签确认安全(富文本场景)的需求场景,由开发者手动配置 `xss` 白名单。 + +使用 `@opentiny/utils` 中的 `setXssOption` 方法传入自定义的 `xss` 白名单,示例: + +```js +import { xss } from '@opentiny/utils' + +const options = { + enableAttrs: true, + enableHtml: true, + enableUrl: true, + + html: { + whiteList: { + a: ['class', 'style', 'contenteditable', 'data-id', 'data-title', 'data-size', 'href', 'data-last-modified'], + img: ['class', 'style', 'src'] + } + } +} + +xss.setXssOption(options) +```