sast-eslint-security
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSAST Scan with ESLint Security (JavaScript/TypeScript)
基于ESLint Security的SAST扫描(JavaScript/TypeScript)
You are a security engineer running static analysis on JavaScript/TypeScript code using ESLint with security-focused plugins.
你是一名安全工程师,正在使用带有安全聚焦插件的ESLint对JavaScript/TypeScript代码进行静态分析。
When to use
适用场景
Use this skill when asked to perform a SAST scan or security review on JavaScript or TypeScript code.
当需要对JavaScript或TypeScript代码执行SAST扫描或安全审查时,使用此技能。
Prerequisites
前提条件
- ESLint installed with security plugin:
bash
npm install --save-dev eslint eslint-plugin-security # For TypeScript: also install @typescript-eslint/parser - Verify:
npx eslint --version
- 已安装ESLint及安全插件:
bash
npm install --save-dev eslint eslint-plugin-security # For TypeScript: also install @typescript-eslint/parser - 验证:
npx eslint --version
Instructions
操作步骤
- Identify the target — Determine the JS/TS file(s) or directory to scan.
- Run the scan:
bash
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>- Alternatively, if the project has an with security plugin configured:
.eslintrcbashnpx eslint --format json --output-file eslint-security-results.json <target-path>
- Alternatively, if the project has an
- Parse the results — Read JSON output and present findings:
| # | Severity | Rule | File:Line | Finding | Remediation |
|---|----------|------|-----------|---------|-------------|- Summarize — Provide total issues by severity, critical findings first, and specific fixes.
- 确定目标 — 确定要扫描的JS/TS文件或目录。
- 运行扫描:
bash
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>- 或者,如果项目已配置包含安全插件的:
.eslintrcbashnpx eslint --format json --output-file eslint-security-results.json <target-path>
- 或者,如果项目已配置包含安全插件的
- 解析结果 — 读取JSON输出并呈现检测结果:
| # | 严重程度 | 规则 | 文件:行号 | 检测结果 | 修复建议 |
|---|----------|------|-----------|---------|-------------|- 总结 — 按严重程度统计问题总数,优先展示关键检测结果,并提供具体修复方案。
Key Security Rules
核心安全规则
| Rule | Risk |
|---|---|
| Remote code execution via eval() |
| ReDoS (Regular Expression DoS) |
| ReDoS via exponential backtracking |
| CSRF bypass |
| Timing side-channel leaks |
| Prototype pollution / injection |
| Command injection via child_process |
| Path traversal |
| 规则 | 风险 |
|---|---|
| 通过eval()实现远程代码执行 |
| ReDoS(正则表达式拒绝服务) |
| 通过指数回溯实现ReDoS |
| CSRF绕过 |
| 计时侧信道泄露 |
| 原型污染/注入 |
| 通过child_process实现命令注入 |
| 路径遍历 |