Skip to content

Commit 319377c

Browse files
committed
增加安全规范
1 parent 5841cba commit 319377c

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

docs/reference/configuration/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ module.exports = {
10721072
'./tsconfig.test.json',
10731073
],
10741074
},
1075-
// $ pnpm add -D eslint@^8.0.0 eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-config-airbnb-typescript @typescript-eslint/eslint-plugin@^7.0.0 @typescript-eslint/parser@^7.0.0 eslint-plugin-no-unsanitized eslint-plugin-react-perf @tanstack/eslint-plugin-query eslint-plugin-unicorn eslint-plugin-promise eslint-plugin-regexp eslint-plugin-jsdoc eslint-plugin-eslint-comments
1075+
// $ pnpm add -D eslint@^8.0.0 eslint-config-airbnb eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-config-airbnb-typescript @typescript-eslint/eslint-plugin@^7.0.0 @typescript-eslint/parser@^7.0.0 eslint-plugin-no-unsanitized eslint-plugin-risxss eslint-plugin-react-perf @tanstack/eslint-plugin-query eslint-plugin-unicorn eslint-plugin-promise eslint-plugin-regexp eslint-plugin-jsdoc eslint-plugin-eslint-comments
10761076
extends: [
10771077
'airbnb',
10781078
'airbnb/hooks',
@@ -1092,6 +1092,9 @@ module.exports = {
10921092
'plugin:jsdoc/recommended-typescript',
10931093
'plugin:eslint-comments/recommended',
10941094
],
1095+
plugin: [
1096+
'risxss',
1097+
],
10951098
rules: {
10961099
// React 17+ 不用再引入 React
10971100
'react/react-in-jsx-scope': 'off',
@@ -1100,6 +1103,12 @@ module.exports = {
11001103
'unicorn/prevent-abbreviations': 'off',
11011104
// Airbnb 更喜欢使用 forEach
11021105
'unicorn/no-array-for-each': 'off',
1106+
// null 在项目中是常见场景
1107+
'unicorn/no-null': 'off',
1108+
// airbnb风格指南要求"基本文件名应该完全匹配其默认导出的名称"
1109+
'unicorn/filename-case': 'off',
1110+
// RisXSS 规则,预防 XSS 攻击
1111+
'risxss/catch-potential-xss-react': 'error',
11031112
},
11041113
overrides: [
11051114
{
@@ -1130,6 +1139,13 @@ module.exports = {
11301139
'plugin:no-unsanitized/recommended-legacy',
11311140
'plugin:tailwindcss/recommended',
11321141
],
1142+
plugin: [
1143+
'risxss',
1144+
],
1145+
rules: {
1146+
// RisXSS 规则,预防 XSS 攻击
1147+
'risxss/catch-potential-xss-vue': 'error',
1148+
},
11331149
};
11341150
```
11351151
</TabItem>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
sidebar_position: 8
3+
---
4+
5+
# 安全规范
6+
7+
## no-unsanitized
8+
9+
[`eslint-plugin-no-unsanitized`](https://github.com/mozilla/eslint-plugin-no-unsanitized) 旨在防止 XSS。它会扫描代码中可能将未净化的用户输入渲染到 DOM 中的危险模式。例如,它会警告你直接将用户输入传递给 `innerHTML``document.write` 或其他可能执行恶意脚本的 API。
10+
11+
```js
12+
// .eslintrc.js
13+
14+
module.exports = {
15+
extends: [
16+
'plugin:no-unsanitized/recommended-legacy',
17+
],
18+
};
19+
```
20+
21+
| 规则名称 | 错误级别 | 配置选项 | 描述 |
22+
|----------|----------|----------|------|
23+
| [`no-unsanitized/method`](https://github.com/mozilla/eslint-plugin-no-unsanitized/blob/main/docs/rules/method.md) | error | - | 检查 JavaScript 中不安全的 DOM 方法调用(如 `insertAdjacentHTML`),防止未经消毒的内容被插入页面,以避免 XSS 攻击 |
24+
| [`no-unsanitized/property`](https://github.com/mozilla/eslint-plugin-no-unsanitized/blob/main/docs/rules/property.md) | error | - | 检查 JavaScript 中不安全的 DOM 属性赋值(如 `innerHTML``outerHTML`),防止未经消毒的内容被插入页面,以避免 XSS 攻击 |
25+
26+
## RisXSS
27+
28+
[`eslint-plugin-risxss`](https://github.com/theodo/RisXSS) 是一个专门用于检测和预防 XSS 的 ESLint 插件。它的核心目标是在前端框架(如 React 和 Vue)中,自动识别出可能导致安全漏洞的代码模式。
29+
30+
```js
31+
// .eslintrc.js
32+
33+
module.exports = {
34+
plugin: [
35+
'risxss',
36+
],
37+
rules: {
38+
'risxss/catch-potential-xss-react': 'error',
39+
// 'risxss/catch-potential-xss-vue': 'error',
40+
},
41+
};
42+
```
43+
44+
| 规则名称 | 错误级别 | 配置选项 | 描述 |
45+
|----------|----------|----------|------|
46+
| [`risxss/catch-potential-xss-react`](https://github.com/theodo/RisXSS/blob/master/docs/rules/catch-potential-xss-react.md) | error | - | 用于检测 React 应用中潜在的 XSS 风险,例如对 `dangerouslySetInnerHTML` 的不安全使用。 |
47+
| [`risxss/catch-potential-xss-vue`](https://github.com/theodo/RisXSS/blob/master/docs/rules/catch-potential-xss-vue.md) | error | - | 用于检测 Vue 应用中潜在的 XSS 风险,例如对 `v-html` 指令的不安全使用。 |
48+

0 commit comments

Comments
 (0)