Skip to content

Commit 4517ede

Browse files
authored
docs: add XSS whitelist configuration FAQ (#3148)
* docs: add XSS whitelist configuration FAQ * docs: add XSS whitelist configuration FAQ * docs: 优化img白名单别表 * docs: 更新img白名单,移除重复的style属性
1 parent 34b7233 commit 4517ede

File tree

1 file changed

+25
-0
lines changed
  • examples/sites/demos/pc/webdoc

1 file changed

+25
-0
lines changed

examples/sites/demos/pc/webdoc/faq.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,28 @@ module.exports = {
8585
transpileDependencies: ['@opentiny/fluent-editor', 'quill']
8686
}
8787
```
88+
89+
## 5、通过 `@opentiny/utils` 配置 `xss` 白名单(v3.21.0 开始支持)
90+
91+
目前进行严格的过滤,建议使用 `JS-XSS` 进行处理。对不符合要求的代码片段做删除处理,若开发者在开发期间有其他 `HTML` 标签确认安全(富文本场景)的需求场景,由开发者手动配置 `xss` 白名单。
92+
93+
使用 `@opentiny/utils` 中的 `setXssOption` 方法传入自定义的 `xss` 白名单,示例:
94+
95+
```js
96+
import { xss } from '@opentiny/utils'
97+
98+
const options = {
99+
enableAttrs: true,
100+
enableHtml: true,
101+
enableUrl: true,
102+
103+
html: {
104+
whiteList: {
105+
a: ['class', 'style', 'contenteditable', 'data-id', 'data-title', 'data-size', 'href', 'data-last-modified'],
106+
img: ['class', 'style', 'src']
107+
}
108+
}
109+
}
110+
111+
xss.setXssOption(options)
112+
```

0 commit comments

Comments
 (0)