用途
该技能面向安全工程师,用于对 JavaScript/TypeScript 代码执行静态应用安全测试(SAST)。当被要求对 JS/TS 代码进行 SAST 扫描或安全审查时使用。
主要能力
通过 ESLint 配合安全插件检测以下风险:
| 规则 | 风险 |
|---|---|
| detect-eval-with-expression | 通过 eval() 导致的远程代码执行 |
| detect-non-literal-regexp | ReDoS(正则表达式拒绝服务) |
| detect-unsafe-regex | 指数级回溯导致的 ReDoS |
| detect-no-csrf-before-method-override | CSRF 绕过 |
| detect-possible-timing-attacks | 时序侧信道泄露 |
| detect-object-injection | 原型污染 / 注入 |
| detect-child-process | 通过 child_process 的命令注入 |
| detect-non-literal-fs-filename | 路径遍历 |
使用方式
前置条件
安装带安全插件的 ESLint:
npm install --save-dev eslint eslint-plugin-security
# For TypeScript: also install @typescript-eslint/parser
验证安装:
npx eslint --version
操作步骤
-
确定目标——确定要扫描的 JS/TS 文件或目录。
-
运行扫描:
npx eslint --plugin security --rule 'security/detect-unsafe-regex: error' \
--rule 'security/detect-non-literal-regexp: warn' \
--rule 'security/detect-eval-with-expression: error' \
--rule 'security/detect-no-csrf-before-method-override: error' \
--rule 'security/detect-possible-timing-attacks: warn' \
--rule 'security/detect-object-injection: warn' \
--format json --output-file eslint-security-results.json \
<target-path>
或者,如果项目已在 .eslintrc 中配置了安全插件:
npx eslint --format json --output-file eslint-security-results.json <target-path>
- 解析结果——读取 JSON 输出并呈现发现项:
| # | Severity | Rule | File:Line | Finding | Remediation |
|---|
- 汇总——按严重程度提供问题总数,优先呈现关键发现,并给出具体修复建议。
适用场景
适用于对 JavaScript 或 TypeScript 代码进行 SAST 扫描或安全审查的场景。
限制
资料未提供关于收费、价格、平台支持范围或检测效果保证的说明。