初始化
This commit is contained in:
56
.cursor/skills/security-audit/references/audit-commands.md
Normal file
56
.cursor/skills/security-audit/references/audit-commands.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Security Audit — 检查命令与代码示例
|
||||
|
||||
> 主流程见 SKILL.md,本文档为 PHP/前端/密钥/CodeGuard 的完整检查命令和最佳实践。
|
||||
|
||||
## 依赖扫描
|
||||
|
||||
```bash
|
||||
npm audit --audit-level=high
|
||||
composer audit
|
||||
```
|
||||
|
||||
## PHP 检查命令
|
||||
|
||||
```bash
|
||||
vendor/bin/phpstan analyse --level=max
|
||||
rg -n "eval\(|exec\(|system\(|passthru\(|shell_exec\(|popen\(" --type php --glob '!vendor/**'
|
||||
rg -n "unserialize\(" --type php --glob '!vendor/**'
|
||||
rg -n "include\s*\\\$|require\s*\\\$" --type php --glob '!vendor/**'
|
||||
rg -n "Db::raw\(|DB::select\(.*\\\$" --type php --glob '!vendor/**'
|
||||
```
|
||||
|
||||
## 前端检查命令
|
||||
|
||||
```bash
|
||||
rg -n "v-html" --glob '*.vue' --glob '*.ts'
|
||||
rg -n "eval\(|new Function\(" --glob '*.ts' --glob '!node_modules/**'
|
||||
rg -n "\.innerHTML\s*=|\.outerHTML\s*=" --glob '*.vue' --glob '!node_modules/**'
|
||||
rg -n "localStorage\.(set|get)Item.*[Tt]oken" --glob '*.ts' --glob '!node_modules/**'
|
||||
rg -n "target=\"_blank\"" --glob '*.vue' | rg -v "noopener"
|
||||
```
|
||||
|
||||
## 密钥扫描命令
|
||||
|
||||
```bash
|
||||
# 通用、AWS、GitHub、Stripe、Google、JWT、私钥、数据库连接串
|
||||
rg -rn "(?i)(api.?key|secret|password|token)\s*[=:]\s*['\"][a-zA-Z0-9]{8,}" --glob '!vendor/**' --glob '!node_modules/**'
|
||||
rg -rn "A(KIA|GPA|IDA|ROA)[0-9A-Z]{16}" ...
|
||||
rg -rn "gh[pousr]_[a-zA-Z0-9]{36}" ...
|
||||
rg -rn "sk_live_|pk_live_|sk_test_[a-zA-Z0-9]{24}" ...
|
||||
rg -rn "AIza[a-zA-Z0-9_\-]{35}" ...
|
||||
rg -rn "eyJ[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-]+" ...
|
||||
rg -rn "BEGIN\s+(RSA\s+)?PRIVATE\s+KEY" ...
|
||||
rg -rn "(mysql|mongodb|redis|postgres)://[^:]+:[^@]+" ...
|
||||
```
|
||||
|
||||
## CORS 集中配置
|
||||
|
||||
❌ Controller 内单独设置 Allow-Origin: *。✅ CorsMiddleware 集中配置,env('CORS_ORIGIN'),Allow-Credentials 与 Allow-Origin: * 不共存。
|
||||
|
||||
## 密码哈希
|
||||
|
||||
❌ md5/sha1、PASSWORD_BCRYPT 无 cost。✅ PASSWORD_ARGON2ID(memory_cost 65536, time_cost 4)或 PASSWORD_BCRYPT cost=12。验证用 password_verify,升级用 password_needs_rehash。
|
||||
|
||||
## CodeGuard 增强
|
||||
|
||||
IDOR:find/findOrFail($request/$id) 未附加所有权 → 应 $user->orders()->findOrFail($id)。Mass Assignment:fill($request->all())、create/update($request->all())。Session:setcookie 需 Secure+HttpOnly+SameSite。禁用算法:md5/sha1、AES-ECB。文件上传:不用 getClientFilename() 原始名,用 UUID;MIME 用 finfo magic bytes。SSRF:Guzzle/curl 对用户 URL 需域名白名单。
|
||||
Reference in New Issue
Block a user