security-audit-codebase
关于
This skill performs a comprehensive security audit of a codebase, scanning for exposed secrets, vulnerable dependencies, injection flaws, and OWASP Top 10 issues. It's designed for use before deployment, during periodic reviews, or when preparing for compliance audits. Developers can run it to automatically identify critical security vulnerabilities and misconfigurations.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/security-audit-codebase在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
安全審碼庫
行系統之安審於碼庫,以識其患與洩之密。
用時
- 發布或展項目之前乃用
- 既有項目之周期安審乃用
- 加認證、API 集、或用入處理之後乃用
- 私庫開源之前乃用
- 備合規之安審乃用
入
- 必要:所審之碼庫
- 可選:特察之處(密、依、注入、認證)
- 可選:合規之框(OWASP、ISO 27001、SOC 2)
- 可選:前審之得以比
法
第一步:掃洩之密
搜硬編密之模:
# API keys and tokens
grep -rn "sk-\|ghp_\|gho_\|github_pat_\|hf_\|AKIA" --include="*.{md,js,ts,py,R,json,yml,yaml}" .
# Generic secret patterns
grep -rn "password\s*=\s*['\"]" --include="*.{js,ts,py,R,json}" .
grep -rn "api[_-]key\s*[=:]\s*['\"]" --include="*.{js,ts,py,R,json}" .
grep -rn "secret\s*[=:]\s*['\"]" --include="*.{js,ts,py,R,json}" .
# Connection strings
grep -rn "postgresql://\|mysql://\|mongodb://" .
# Private keys
grep -rn "BEGIN.*PRIVATE KEY" .
得:未得實密——唯占位如 YOUR_TOKEN_HERE 或 [email protected]。
敗則:得實密,立刪之,輪換洩之憑據,以 git filter-branch 或 git-filter-repo 清史。視所洩之密為已破。
第二步:察 .gitignore 之覆
驗敏文件已排:
# Check that these are git-ignored
git check-ignore .env .Renviron credentials.json node_modules/
# Look for tracked sensitive files
git ls-files | grep -i "\.env\|\.renviron\|credentials\|secret"
得:諸敏文件(.env、.Renviron、credentials.json)皆列於 .gitignore,git ls-files 返無敏之追蹤文件。
敗則:敏文件已追,行 git rm --cached <file> 以解,加入 .gitignore,提交。文件留於盤而不再受版控。
第三步:審依
Node.js:
npm audit
npx audit-ci --moderate
Python:
pip-audit
safety check
R:
# Check for known vulnerabilities in packages
# No built-in tool, but verify package sources
renv::status()
得:依無高或要患。中與低之患書以審。
敗則:得要患,立以 npm audit fix 或 pip install --upgrade 更受影之包。更若引破,書其患而立修之計。
第四步:察注入之患
SQL 注入:
# Look for string concatenation in queries
grep -rn "paste.*SELECT\|paste.*INSERT\|paste.*UPDATE\|paste.*DELETE" --include="*.R" .
grep -rn "query.*\+.*\|query.*\$\{" --include="*.{js,ts}" .
諸庫之查皆宜用參查,非串拼。
命注入:
# Look for shell execution with user input
grep -rn "system\(.*paste\|exec(\|spawn(" --include="*.{R,js,ts,py}" .
XSS(跨站本):
# Look for unescaped user content in HTML
grep -rn "innerHTML\|dangerouslySetInnerHTML\|v-html" --include="*.{js,ts,jsx,tsx,vue}" .
得:無 SQL、命、XSS 注入之路。諸庫查用參、殼命避用控之入、HTML 出皆轉義。
敗則:得注入,以參查代查中之串拼,殼行前淨或轉用之入,以框安之渲法代 innerHTML 或 dangerouslySetInnerHTML。
第五步:審認證與授權
清單:
- 密以 bcrypt/argon2 散(非 MD5/SHA1)
- 會話令隨機而足長
- 認證令有期
- API 端察授權
- CORS 嚴配
- 變態之操啟 CSRF 之護
得:諸項皆過:密用強散、令隨機有期、端強授權、CORS 嚴、CSRF 護活。
敗則:依重排修:弱散與缺授權為要,CORS 與 CSRF 為高。書諸得附其重等。
第六步:察配之安
# Debug mode in production configs
grep -rn "debug\s*[=:]\s*[Tt]rue\|DEBUG\s*=\s*1" --include="*.{json,yml,yaml,toml,cfg}" .
# Permissive CORS
grep -rn "Access-Control-Allow-Origin.*\*\|cors.*origin.*\*" --include="*.{js,ts}" .
# HTTP instead of HTTPS
grep -rn "http://" --include="*.{js,ts,py,R}" . | grep -v "localhost\|127.0.0.1\|http://"
得:生產配中 debug 模已禁,CORS 不用通配,諸外網址用 HTTPS。
敗則:生產配 debug 模啟,立禁之。以明域代通配 CORS。將 http:// 之網址更為 https://,若端支之。
第七步:書其得
立審報:
# Security Audit Report
**Date**: YYYY-MM-DD
**Auditor**: [Name]
**Scope**: [Repository/Project]
**Status**: [PASS/FAIL/CONDITIONAL]
## Findings Summary
| Category | Status | Details |
|----------|--------|---------|
| Exposed secrets | PASS | No secrets found |
| .gitignore | PASS | Sensitive files excluded |
| Dependencies | WARN | 2 moderate vulnerabilities |
| Injection | PASS | Parameterized queries used |
| Auth/AuthZ | N/A | No authentication in scope |
| Configuration | PASS | Debug mode disabled |
## Detailed Findings
### Finding 1: [Title]
- **Severity**: Low / Medium / High / Critical
- **Location**: `path/to/file:line`
- **Description**: What was found
- **Recommendation**: How to fix
- **Status**: Open / Resolved
## Recommendations
1. Update dependencies to fix moderate vulnerabilities
2. [Additional recommendations]
得:完備之 SECURITY_AUDIT_REPORT.md 存於項目根,諸得依重分,各附特位、述、議。
敗則:得繁難一一書,依類聚而先要/高之得。無論結,皆生報以立基線。
驗
- 源無硬編之密
- .gitignore 覆諸敏文件
- 依無高/要之患
- 無注入之患
- 認證已正施(若適)
- 審報完備,諸得已處
陷
- 唯察當前之文件:git 史中之密仍洩。以
git log -p --all -S 'secret_pattern'察 - 忽開發之依:開發之依仍可引供應鏈之險
.gitignore之假安:.gitignore唯阻後追。已提交之文件需git rm --cached- 忽配文件:
docker-compose.yml、CI 配、展本常含密 - 不輪換已破之憑據:得而刪密不足。憑據必廢而再生
參
configure-git-repository— 正之 .gitignore 設write-claude-md— 書安之求setup-gxp-r-project— 受規之境之安
GitHub 仓库
相关推荐技能
subagent-driven-development
开发该Skill用于在当前会话中执行包含独立任务的实施计划,它会为每个任务分派一个全新的子代理并在任务间进行代码审查。这种"全新子代理+任务间审查"的模式既能保障代码质量,又能实现快速迭代。适合需要在当前会话中连续执行独立任务,并希望在每个任务后都有质量把关的开发场景。
qmd
开发这是一个本地搜索和索引的CLI工具,支持BM25、向量搜索和重排序功能。开发者可以用它快速索引本地文件(如Markdown文档)并进行混合搜索,特别适合代码库或文档的本地检索。它还提供MCP模式,能轻松集成到Claude开发环境中使用。
mcporter
开发mcporter Skill 让开发者能在Claude中直接管理和调用MCP服务器。它支持列出可用服务器、调用工具、处理OAuth认证以及管理服务器守护进程。开发者可以通过命令行式交互快速执行`mcporter list`查看服务器,或使用`mcporter call`直接调用工具,简化了MCP工作流程。
adk-deployment-specialist
开发这是一个用于部署和编排Google Vertex AI ADK智能体的Claude Skill,专为构建生产级多智能体系统而设计。它支持通过A2A协议进行智能体通信,提供代码执行沙箱和记忆库功能,并能处理智能体发现与任务提交。当开发者需要部署ADK智能体或编排多智能体协作时,可使用此Skill来简化Vertex AI Agent Engine的部署流程。
