关于 frontend-security
frontend-security 用于审计前端代码库中的漏洞和缺失的防护措施,涵盖常见攻击模式、依赖风险检查、严重程度分类及修复建议。
主要功能
- 01搜索 XSS 模式
- 02检查 CSRF 防护
- 03检查 CSP 和输入验证
- 04检查依赖中的漏洞
- 05按严重程度分类发现
- 06提供修复建议
适用场景
- 01审计前端代码库
- 02检查 React 或 DOM 用法中的 XSS 风险
- 03检查表单和请求的 CSRF 风险
- 04评估 Node.js 和 npm 依赖
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ schalkneethling/ webdev-agent-skills --skill frontend-security安装后在 Claude Code 中输入/frontend-security确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/csp-configuration.mdcsrf-protection.mddom-security.mdfile-upload-security.mdframework-patterns.mdinput-validation.mdjwt-security.mdnodejs-npm-security.mdxss-prevention.md详细介绍
前端安全审计技能
对前端代码库进行全面的安全审计,以识别漏洞、不良实践和缺失的防护措施。
审计流程
- 扫描危险模式 - 在代码库中搜索已知的漏洞迹象
- 审查框架特定风险 - 检查是否存在绕过框架安全机制的模式
- 验证防御措施 - 检查 CSP、CSRF 令牌和输入验证
- 检查依赖项 - 审查 npm/node 依赖项是否存在漏洞
- 报告发现 - 按严重程度分类,并提供修复建议
需要搜索的严重漏洞模式
XSS 指标(搜索优先级:高)
# React dangerous patterns
grep -rn "dangerouslySetInnerHTML" --include="*.jsx" --include="*.tsx" --include="*.js"
# Direct DOM manipulation
grep -rn "\.innerHTML\s*=" --include="*.js" --include="*.ts" --include="*.jsx" --include="*.tsx"
grep -rn "\.outerHTML\s*=" --include="*.js" --include="*.ts"
grep -rn "document\.write" --include="*.js" --include="*.ts"
# URL-based injection
grep -rn "location\.href\s*=" --include="*.js" --include="*.ts"
grep -rn "location\.replace" --include="*.js" --include="*.ts"
grep -rn "window\.open" --include="*.js" --include="*.ts"
# Eval and code execution
grep -rn "eval\s*(" --include="*.js" --include="*.ts"
grep -rn "new Function\s*(" --include="*.js" --include="*.ts"
grep -rn "setTimeout\s*(\s*['\"]" --include="*.js" --include="*.ts"
grep -rn "setInterval\s*(\s*['\"]" --include="*.js" --include="*.ts"
# Twig unescaped output
grep -rn "|raw" --include="*.twig" --include="*.html.twig"
grep -rn "{% autoescape false %}" --include="*.twig"
CSRF 指标
# Forms without CSRF tokens
grep -rn "<form" --include="*.html" --include="*.jsx" --include="*.tsx" --include="*.twig"
# State-changing requests without protection
grep -rn "fetch\s*(" --include="*.js" --include="*.ts" | grep -E "(POST|PUT|DELETE|PATCH)"
grep -rn "axios\.(post|put|delete|patch)" --include="*.js" --include="*.ts"
敏感数据泄露
# localStorage/sessionStorage with sensitive data
grep -rn "localStorage\." --include="*.js" --include="*.ts"
grep -rn "sessionStorage\." --include="*.js" --include="*.ts"
# Hardcoded secrets
grep -rn "api[_-]?key\s*[:=]" --include="*.js" --include="*.ts" --include="*.env"
grep -rn "secret\s*[:=]" --include="*.js" --include="*.ts"
grep -rn "password\s*[:=]" --include="*.js" --include="*.ts"
参考文档
根据发现的问题加载以下参考资料:
- 发现 XSS 漏洞:参见
references/xss-prevention.md - CSRF 问题:参见
references/csrf-protection.md - DOM 操作问题:参见
references/dom-security.md - 需要审查 CSP:参见
references/csp-configuration.md - 输入处理问题:参见
references/input-validation.md - Node.js/NPM 审计:参见
references/nodejs-npm-security.md - 框架特定模式:参见
references/framework-patterns.md - 文件上传处理:参见
references/file-upload-security.md - JWT 实现:参见
references/jwt-security.md
严重程度分类
严重 - 可利用的 XSS、身份验证绕过、机密信息泄露 高 - 缺少 CSRF 防护、不安全的 DOM 操作、SQL 注入攻击向量 中 - CSP 薄弱、缺少安全标头、输入验证不当 低 - 信息泄露、已弃用的函数、欠佳的实践
报告格式
## Security Audit Report
### Summary
- Critical: X findings
- High: X findings
- Medium: X findings
- Low: X findings
### Critical Findings
#### [CRITICAL-001] Title
- **Location**: file:line
- **Pattern**: Code snippet
- **Risk**: Description of the vulnerability
- **Remediation**: How to fix
- **Reference**: OWASP link
### High Findings
[...]
OWASP 参考链接
如需全面的指导,请直接参考以下 OWASP 备忘单:
- XSS 防护:https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
- DOM XSS 防护:https://cheatsheetseries.owasp.org/cheatsheets/DOM_based_XSS_Prevention_Cheat_Sheet.html
- CSRF 防护:https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html
- CSP:https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html
- 输入验证:https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html
- HTML5 安全:https://cheatsheetseries.owasp.org/cheatsheets/HTML5_Security_Cheat_Sheet.html
- DOM 覆盖:https://cheatsheetseries.owasp.org/cheatsheets/DOM_Clobbering_Prevention_Cheat_Sheet.html
- Node.js 安全:https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html
- NPM 安全:https://cheatsheetseries.owasp.org/cheatsheets/NPM_Security_Cheat_Sheet.html
- AJAX 安全:https://cheatsheetseries.owasp.org/cheatsheets/AJAX_Security_Cheat_Sheet.html
- 文件上传:https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html
- 错误处理:https://cheatsheetseries.owasp.org/cheatsheets/Error_Handling_Cheat_Sheet.html
- JWT 安全:https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.html
- 用户隐私:https://cheatsheetseries.owasp.org/cheatsheets/User_Privacy_Protection_Cheat_Sheet.html
- gRPC 安全:https://cheatsheetseries.owasp.org/cheatsheets/gRPC_Security_Cheat_Sheet.html
评论
支持 Markdown