scan-debug-skill 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,69 +1,69 @@
1
- # 安全合规规范 (Security)
2
-
3
- ## 规则详情
4
- * **XSS 防范**:
5
- * 严禁使用 `eval()`、`new Function()`。
6
- * 处理用户输入的 HTML 内容时,必须确保内容已经过 DOMPurify 等库的清洗,避免直接插入未过滤的 HTML。
7
- * **敏感信息**:代码中禁止硬编码密码、Token、密钥(AK/SK)、内网 IP 等敏感信息,应通过环境变量或配置接口获取。
8
- * **日志安全**:
9
- * 禁止在生产环境日志中输出敏感信息(如密码、Token 等)。
10
- * **变量命名**:若变量名无明确语义化(如 `data`, `info`, `res`),视为潜在敏感信息禁止直接打印。
11
- * **异常捕获**:**严禁直接打印 `error.stack` 或完整的 `error` 对象**。如无法确定 `error` 结构则不打印 `error`,必须按照 **模块名 + 方法名 + 错误简述** 的格式输出,防止堆栈信息泄露系统内部结构。
12
- * **链接安全**:使用 `target="_blank"` 打开外部链接时,必须添加 `rel="noopener noreferrer"` 以防止钓鱼攻击。
13
- * **正则安全**:确保正则表达式不会导致拒绝服务攻击 (ReDoS)。
14
-
15
- ## 示例:敏感信息处理
16
-
17
- **场景**:Sonar 提示 "Hardcoded passwords/tokens/keys should not be used"。
18
-
19
- **修复后代码**:
20
- ```javascript
21
- // Non-Compliant: 硬编码敏感信息
22
- // const API_KEY = "sk-123456789";
23
-
24
- // Compliant: 使用环境变量
25
- // 说明:确保环境变量在构建或运行时已正确注入
26
- const API_KEY = process.env.API_KEY;
27
- ```
28
-
29
- ## 示例:日志安全与异常处理
30
-
31
- **场景**:Sonar/安全扫描提示 "User credentials should not be printed" 或 "Stack traces should not be disclosed"。
32
-
33
- **修复后代码**:
34
- ```javascript
35
- /**
36
- * 处理用户登录
37
- * @param {string} username - 用户名
38
- * @param {string} password - 密码
39
- */
40
- async function handleLogin(username, password) {
41
- try {
42
- // 1. 敏感信息禁止打印
43
- // Non-Compliant (敏感数据): console.log(`Attempting login for ${username} with password ${password}`);
44
- // Non-Compliant (非语义化变量): console.log('Login info:', info); // info 语义不明确,可能包含敏感字段
45
- console.log(`Attempting login for user: ${username}`); // Compliant: 仅记录明确的非敏感标识
46
-
47
- await authService.login(username, password);
48
-
49
- } catch (error) {
50
- // 2. 异常捕获禁止泄露堆栈
51
- // Non-Compliant: console.error(error); 或 console.error(error.stack);
52
-
53
- // Compliant: 仅记录错误来源,不包含详细堆栈
54
- // 格式要求:模块名 + 方法名 + 错误简述
55
- console.error('LoginService: handleLogin 方法报错/接口请求失败');
56
- }
57
- }
58
- ```
59
-
60
- ## 示例:正则表达式安全 (ReDoS)
61
-
62
- **场景**:Sonar 提示 "Make sure the regex used here... cannot lead to denial of service"。
63
-
64
- **修复后代码**:
65
- ```javascript
66
- // Compliant: 优化正则结构,避免嵌套量词,防止 ReDoS 攻击
67
- // 说明:匹配一个或多个 'a' 后跟一个 'b'
68
- const regex = /a+b/;
69
- ```
1
+ # 安全合规规范 (Security)
2
+
3
+ ## 规则详情
4
+ * **XSS 防范**:
5
+ * 严禁使用 `eval()`、`new Function()`。
6
+ * 处理用户输入的 HTML 内容时,必须确保内容已经过 DOMPurify 等库的清洗,避免直接插入未过滤的 HTML。
7
+ * **敏感信息**:代码中禁止硬编码密码、Token、密钥(AK/SK)、内网 IP 等敏感信息,应通过环境变量或配置接口获取。
8
+ * **日志安全**:
9
+ * 禁止在生产环境日志中输出敏感信息(如密码、Token 等)。
10
+ * **变量命名**:若变量名无明确语义化(如 `data`, `info`, `res`),视为潜在敏感信息禁止直接打印。
11
+ * **异常捕获**:**严禁直接打印 `error.stack` 或完整的 `error` 对象**。如无法确定 `error` 结构则不打印 `error`,必须按照 **模块名 + 方法名 + 错误简述** 的格式输出,防止堆栈信息泄露系统内部结构。
12
+ * **链接安全**:使用 `target="_blank"` 打开外部链接时,必须添加 `rel="noopener noreferrer"` 以防止钓鱼攻击。
13
+ * **正则安全**:确保正则表达式不会导致拒绝服务攻击 (ReDoS)。
14
+
15
+ ## 示例:敏感信息处理
16
+
17
+ **场景**:Sonar 提示 "Hardcoded passwords/tokens/keys should not be used"。
18
+
19
+ **修复后代码**:
20
+ ```javascript
21
+ // Non-Compliant: 硬编码敏感信息
22
+ // const API_KEY = "sk-123456789";
23
+
24
+ // Compliant: 使用环境变量
25
+ // 说明:确保环境变量在构建或运行时已正确注入
26
+ const API_KEY = process.env.API_KEY;
27
+ ```
28
+
29
+ ## 示例:日志安全与异常处理
30
+
31
+ **场景**:Sonar/安全扫描提示 "User credentials should not be printed" 或 "Stack traces should not be disclosed"。
32
+
33
+ **修复后代码**:
34
+ ```javascript
35
+ /**
36
+ * 处理用户登录
37
+ * @param {string} username - 用户名
38
+ * @param {string} password - 密码
39
+ */
40
+ async function handleLogin(username, password) {
41
+ try {
42
+ // 1. 敏感信息禁止打印
43
+ // Non-Compliant (敏感数据): console.log(`Attempting login for ${username} with password ${password}`);
44
+ // Non-Compliant (非语义化变量): console.log('Login info:', info); // info 语义不明确,可能包含敏感字段
45
+ console.log(`Attempting login for user: ${username}`); // Compliant: 仅记录明确的非敏感标识
46
+
47
+ await authService.login(username, password);
48
+
49
+ } catch (error) {
50
+ // 2. 异常捕获禁止泄露堆栈
51
+ // Non-Compliant: console.error(error); 或 console.error(error.stack);
52
+
53
+ // Compliant: 仅记录错误来源,不包含详细堆栈
54
+ // 格式要求:模块名 + 方法名 + 错误简述
55
+ console.error('LoginService: handleLogin 方法报错/接口请求失败');
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## 示例:正则表达式安全 (ReDoS)
61
+
62
+ **场景**:Sonar 提示 "Make sure the regex used here... cannot lead to denial of service"。
63
+
64
+ **修复后代码**:
65
+ ```javascript
66
+ // Compliant: 优化正则结构,避免嵌套量词,防止 ReDoS 攻击
67
+ // 说明:匹配一个或多个 'a' 后跟一个 'b'
68
+ const regex = /a+b/;
69
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scan-debug-skill",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A set of code scanning and debugging skills, primarily for quick fixes of common SonarQube and Qianxin issues. | 一套代码扫描与调试技能,主要应用于 SonarQube 和奇安信常见问题的快速修复。",
5
5
  "bin": {
6
6
  "scan-debug-skill": "./bin/install.js"