docs: add XSS whitelist configuration FAQ (#3148)

* docs: add XSS whitelist configuration FAQ

* docs: add XSS whitelist configuration FAQ

* docs: 优化img白名单别表

* docs: 更新img白名单,移除重复的style属性
This commit is contained in:
ajaxzheng 2025-03-19 11:11:29 +08:00 committed by GitHub
parent 34b72337a4
commit 4517eded00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 0 deletions

View File

@ -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)
```