security-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSecurity Review
安全审查
Overview
概述
Dedicated security review for code handling authentication, authorization, user input, APIs, databases, or credentials.
Core principle: Security issues require specialized attention beyond general code review.
Trigger: This review is MANDATORY when changes touch security-sensitive paths.
Announce at start: "I'm performing a security review of this code."
针对处理身份验证、授权、用户输入、API、数据库或凭据的代码进行专门的安全审查。
核心原则: 安全问题需要专门处理,不能仅依赖常规代码审查。
触发条件: 当变更触及安全敏感路径时,此审查为强制要求。
开始时声明: “我正在对这些代码进行安全审查。”
When Required
何时必须执行
This skill is MANDATORY when ANY of these files are modified:
| Pattern | Examples |
|---|---|
| src/auth/login.ts, lib/auth/session.js |
| src/security/encryption.ts |
| src/middleware/authenticate.ts |
| src/api/endpoints.ts |
| utils/passwordHash.ts |
| services/tokenService.ts |
| config/secrets.ts |
| lib/credentials.js |
| middleware/session.ts |
| src/routes/protected.ts |
| migrations/001_users.sql |
Check with:
bash
git diff --name-only HEAD~1 | grep -E '(auth|security|middleware|api|password|token|secret|credential|session|routes|\.sql)'当修改以下任一文件时,此 skill 为强制要求:
| 模式 | 示例 |
|---|---|
| src/auth/login.ts, lib/auth/session.js |
| src/security/encryption.ts |
| src/middleware/authenticate.ts |
| src/api/endpoints.ts |
| utils/passwordHash.ts |
| services/tokenService.ts |
| config/secrets.ts |
| lib/credentials.js |
| middleware/session.ts |
| src/routes/protected.ts |
| migrations/001_users.sql |
使用以下命令检查:
bash
git diff --name-only HEAD~1 | grep -E '(auth|security|middleware|api|password|token|secret|credential|session|routes|\.sql)'OWASP Top 10 Checklist
OWASP Top 10 检查清单
Review against each category:
针对每个类别进行检查:
1. Injection (A03:2021)
1. 注入(Injection,A03:2021)
| Check | Verify |
|---|---|
| SQL Injection | All queries use parameterized statements |
| Command Injection | No user input in shell commands, or properly escaped |
| LDAP Injection | LDAP queries use proper escaping |
| XPath Injection | XPath queries use parameterized approach |
| Template Injection | Template engines configured safely |
typescript
// VULNERABLE
db.query(`SELECT * FROM users WHERE id = '${userId}'`);
// SECURE
db.query('SELECT * FROM users WHERE id = ?', [userId]);| 检查项 | 验证方式 |
|---|---|
| SQL 注入 | 所有查询均使用参数化语句 |
| 命令注入 | shell 命令中不包含用户输入,或已正确转义 |
| LDAP 注入 | LDAP 查询使用正确的转义方式 |
| XPath 注入 | XPath 查询采用参数化方式 |
| 模板注入 | 模板引擎已安全配置 |
typescript
// VULNERABLE
db.query(`SELECT * FROM users WHERE id = '${userId}'`);
// SECURE
db.query('SELECT * FROM users WHERE id = ?', [userId]);2. Broken Authentication (A07:2021)
2. 身份验证失效(Broken Authentication,A07:2021)
| Check | Verify |
|---|---|
| Password Storage | Passwords hashed with bcrypt/argon2 (not MD5/SHA1) |
| Session Management | Secure, HttpOnly, SameSite cookies |
| Token Handling | JWTs signed, validated, short-lived |
| Brute Force Protection | Rate limiting on auth endpoints |
| Credential Exposure | No credentials in logs, errors, or responses |
| 检查项 | 验证方式 |
|---|---|
| 密码存储 | 密码使用 bcrypt/argon2 哈希,而非 MD5/SHA1 |
| Session 管理 | 使用安全的、具备 HttpOnly 和 SameSite 属性的 Cookie |
| Token 处理 | JWT 已签名、经过验证且有效期短 |
| 暴力破解防护 | 身份验证端点启用速率限制 |
| 凭据暴露 | 日志、错误或响应中不包含凭据 |
3. Sensitive Data Exposure (A02:2021)
3. 敏感数据暴露(Sensitive Data Exposure,A02:2021)
| Check | Verify |
|---|---|
| Data in Transit | HTTPS enforced, TLS 1.2+ |
| Data at Rest | Sensitive data encrypted |
| Secrets in Code | No hardcoded API keys, passwords, tokens |
| Error Messages | No sensitive info in error responses |
| Logging | No sensitive data logged |
bash
undefined| 检查项 | 验证方式 |
|---|---|
| 传输中的数据 | 强制使用 HTTPS 和 TLS 1.2+ |
| 静态数据 | 敏感数据已加密 |
| 代码中的 Secret | 不存在硬编码的 API key、密码或 token |
| 错误消息 | 错误响应中不包含敏感信息 |
| 日志 | 不记录敏感数据 |
bash
undefinedCheck for hardcoded secrets
Check for hardcoded secrets
grep -rE '(password|secret|api_key|token)\s*[:=]\s*["\047][^"\047]+["\047]' src/
undefinedgrep -rE '(password|secret|api_key|token)\s*[:=]\s*["\047][^"\047]+["\047]' src/
undefined4. XML External Entities (A05:2021)
4. XML 外部实体(XML External Entities,A05:2021)
| Check | Verify |
|---|---|
| XML Parsing | External entities disabled |
| DTD Processing | DTD processing disabled if not needed |
| 检查项 | 验证方式 |
|---|---|
| XML 解析 | 已禁用外部实体 |
| DTD 处理 | 如无需要,已禁用 DTD 处理 |
5. Broken Access Control (A01:2021)
5. 访问控制失效(Broken Access Control,A01:2021)
| Check | Verify |
|---|---|
| Authorization Checks | Every endpoint verifies permissions |
| Direct Object References | Object access validated against user |
| Privilege Escalation | Cannot elevate own privileges |
| CORS | Properly restricted origins |
| Method Restriction | Only allowed HTTP methods accepted |
| 检查项 | 验证方式 |
|---|---|
| 授权检查 | 每个端点均验证权限 |
| 直接对象引用 | 根据用户验证对象访问权限 |
| 权限提升 | 用户无法提升自身权限 |
| CORS | 已正确限制允许的 origin |
| 方法限制 | 仅接受允许的 HTTP 方法 |
6. Security Misconfiguration (A05:2021)
6. 安全配置错误(Security Misconfiguration,A05:2021)
| Check | Verify |
|---|---|
| Default Credentials | No default passwords in use |
| Error Handling | Stack traces not exposed to users |
| Security Headers | CSP, X-Frame-Options, etc. set |
| Debug Mode | Disabled in production |
| Unnecessary Features | Unused endpoints/features removed |
| 检查项 | 验证方式 |
|---|---|
| 默认凭据 | 未使用默认密码 |
| 错误处理 | 不向用户暴露堆栈跟踪信息 |
| 安全标头 | 已设置 CSP、X-Frame-Options 等标头 |
| 调试模式 | 生产环境中已禁用 |
| 不必要的功能 | 已移除未使用的端点或功能 |
7. Cross-Site Scripting (A03:2021)
7. 跨站脚本(Cross-Site Scripting,A03:2021)
| Check | Verify |
|---|---|
| Output Encoding | User input encoded before display |
| DOM XSS | innerHTML not used with user input |
| Template Safety | Template engine auto-escapes |
| CSP | Content Security Policy configured |
typescript
// VULNERABLE
element.innerHTML = userInput;
// SECURE
element.textContent = userInput;
// OR
element.innerHTML = DOMPurify.sanitize(userInput);| 检查项 | 验证方式 |
|---|---|
| 输出编码 | 用户输入在显示前经过编码 |
| DOM XSS | 不将用户输入直接赋给 innerHTML |
| 模板安全 | 模板引擎自动转义 |
| CSP | 已配置 Content Security Policy |
typescript
// VULNERABLE
element.innerHTML = userInput;
// SECURE
element.textContent = userInput;
// OR
element.innerHTML = DOMPurify.sanitize(userInput);8. Insecure Deserialization (A08:2021)
8. 不安全反序列化(Insecure Deserialization,A08:2021)
| Check | Verify |
|---|---|
| Object Deserialization | Untrusted data not deserialized |
| JSON Parsing | Safe JSON.parse usage |
| Type Validation | Deserialized objects validated |
| 检查项 | 验证方式 |
|---|---|
| 对象反序列化 | 不对不可信数据进行反序列化 |
| JSON 解析 | 安全使用 JSON.parse |
| 类型验证 | 已验证反序列化对象 |
9. Using Components with Known Vulnerabilities (A06:2021)
9. 使用存在已知漏洞的组件(Using Components with Known Vulnerabilities,A06:2021)
| Check | Verify |
|---|---|
| Dependency Audit | |
| Outdated Packages | No critically outdated dependencies |
| CVE Check | No known CVEs in dependencies |
bash
undefined| 检查项 | 验证方式 |
|---|---|
| 依赖项审计 | |
| 过期软件包 | 不存在严重过期的依赖项 |
| CVE 检查 | 依赖项中不存在已知 CVE |
bash
undefinedRun dependency audit
Run dependency audit
pnpm audit --prod
pnpm audit --prod
or
or
pip-audit
undefinedpip-audit
undefined10. Insufficient Logging & Monitoring (A09:2021)
10. 日志记录与监控不足(Insufficient Logging & Monitoring,A09:2021)
| Check | Verify |
|---|---|
| Auth Events | Login success/failure logged |
| Access Control | Permission denials logged |
| Input Validation | Validation failures logged |
| Sensitive Actions | Admin actions logged |
| Log Integrity | Logs protected from tampering |
| 检查项 | 验证方式 |
|---|---|
| 身份验证事件 | 记录登录成功和失败信息 |
| 访问控制 | 记录权限拒绝信息 |
| 输入验证 | 记录验证失败信息 |
| 敏感操作 | 记录管理员操作 |
| 日志完整性 | 日志受到保护,无法被篡改 |
Review Process
审查流程
Step 1: Identify Security-Sensitive Changes
第 1 步:识别安全敏感变更
bash
undefinedbash
undefinedList changed files matching security patterns
List changed files matching security patterns
git diff --name-only HEAD~1 | grep -E '(auth|security|middleware|api|password|token|secret|session)'
undefinedgit diff --name-only HEAD~1 | grep -E '(auth|security|middleware|api|password|token|secret|session)'
undefinedStep 2: Review Each File
第 2 步:审查每个文件
For each security-sensitive file:
- Read the entire file (not just diff)
- Check against all 10 OWASP categories
- Note any findings with severity
对于每个安全敏感文件:
- 阅读完整文件,而不只是 diff
- 对照全部 10 个 OWASP 类别进行检查
- 记录发现的问题及其严重性
Step 3: Check Dependencies
第 3 步:检查依赖项
bash
undefinedbash
undefinedAudit dependencies
Audit dependencies
pnpm audit --prod
pnpm audit --prod
Check for outdated
Check for outdated
pnpm outdated
undefinedpnpm outdated
undefinedStep 4: Document Findings
第 4 步:记录审查发现
Use severity levels:
| Severity | Description | Action |
|---|---|---|
| CRITICAL | Exploitable vulnerability, data breach risk | MUST fix before merge |
| HIGH | Significant security weakness | MUST fix before merge |
| MEDIUM | Defense-in-depth issue | SHOULD fix before merge |
| LOW | Minor improvement | MAY fix in future issue |
使用以下严重性级别:
| 严重性 | 说明 | 操作 |
|---|---|---|
| CRITICAL | 可利用的漏洞,存在数据泄露风险 | 合并前必须修复 |
| HIGH | 重大安全弱点 | 合并前必须修复 |
| MEDIUM | 纵深防御问题 | 合并前应该修复 |
| LOW | 轻微改进项 | 可以在后续 issue 中修复 |
Step 5: Add Security Section to Review Artifact
第 5 步:在审查产物中添加安全部分
Add to the main review artifact:
markdown
undefined向主审查产物中添加安全部分:
markdown
undefinedSecurity Review
Security Review
Security-Sensitive: YES
Reviewed By: [WORKER_ID or codex-subagent security-reviewer]
OWASP Categories Checked: 10/10
Security-Sensitive: YES
Reviewed By: [WORKER_ID or codex-subagent security-reviewer]
OWASP Categories Checked: 10/10
Security Findings
Security Findings
| # | OWASP Category | Severity | Finding | Status |
|---|---|---|---|---|
| 1 | A03 Injection | CRITICAL | SQL injection in findUser() | FIXED |
| 2 | A02 Sensitive Data | HIGH | API key in config.ts | DEFERRED #456 |
| 3 | A01 Access Control | MEDIUM | Missing auth on /admin | FIXED |
| # | OWASP Category | Severity | Finding | Status |
|---|---|---|---|---|
| 1 | A03 Injection | CRITICAL | SQL injection in findUser() | FIXED |
| 2 | A02 Sensitive Data | HIGH | API key in config.ts | DEFERRED #456 |
| 3 | A01 Access Control | MEDIUM | Missing auth on /admin | FIXED |
Dependency Audit
Dependency Audit
pnpm audit: 0 vulnerabilitiesSecurity Review Status: [PASS|ISSUES_FIXED|ISSUES_DEFERRED]
undefinedpnpm audit: 0 vulnerabilitiesSecurity Review Status: [PASS|ISSUES_FIXED|ISSUES_DEFERRED]
undefinedSecurity Review Artifact (Standalone)
安全审查产物(独立)
If security review is extensive, post as separate comment:
markdown
<!-- SECURITY_REVIEW:START -->如果安全审查内容较多,可作为单独的评论发布:
markdown
<!-- SECURITY_REVIEW:START -->Security Review
Security Review
| Property | Value |
|---|---|
| Issue | #123 |
| Reviewer | |
| Reviewed | 2025-12-29T10:30:00Z |
| Property | Value |
|---|---|
| Issue | #123 |
| Reviewer | |
| Reviewed | 2025-12-29T10:30:00Z |
Files Reviewed
Files Reviewed
- src/auth/login.ts
- src/middleware/authenticate.ts
- src/api/users.ts
- src/auth/login.ts
- src/middleware/authenticate.ts
- src/api/users.ts
OWASP Checklist Results
OWASP Checklist Results
| # | Category | Status | Notes |
|---|---|---|---|
| A01 | Broken Access Control | PASS | Auth middleware on all protected routes |
| A02 | Cryptographic Failures | PASS | bcrypt for passwords, TLS enforced |
| A03 | Injection | FIXED | Parameterized SQL queries now |
| A04 | Insecure Design | PASS | - |
| A05 | Security Misconfiguration | PASS | - |
| A06 | Vulnerable Components | PASS | pnpm audit clean |
| A07 | Auth Failures | PASS | Rate limiting, secure sessions |
| A08 | Data Integrity Failures | PASS | - |
| A09 | Logging Failures | NOTE | Consider adding auth failure logging |
| A10 | SSRF | N/A | No server-side requests |
| # | Category | Status | Notes |
|---|---|---|---|
| A01 | Broken Access Control | PASS | Auth middleware on all protected routes |
| A02 | Cryptographic Failures | PASS | bcrypt for passwords, TLS enforced |
| A03 | Injection | FIXED | Parameterized SQL queries now |
| A04 | Insecure Design | PASS | - |
| A05 | Security Misconfiguration | PASS | - |
| A06 | Vulnerable Components | PASS | pnpm audit clean |
| A07 | Auth Failures | PASS | Rate limiting, secure sessions |
| A08 | Data Integrity Failures | PASS | - |
| A09 | Logging Failures | NOTE | Consider adding auth failure logging |
| A10 | SSRF | N/A | No server-side requests |
Dependency Audit
Dependency Audit
found 0 vulnerabilitiesSecurity Review Status: PASS
<!-- SECURITY_REVIEW:END -->
undefinedfound 0 vulnerabilitiesSecurity Review Status: PASS
<!-- SECURITY_REVIEW:END -->
undefinedChecklist
检查清单
Before completing security review:
- All changed security-sensitive files reviewed
- All 10 OWASP categories checked
- Dependency audit run
- All CRITICAL/HIGH findings fixed
- Any deferred findings have tracking issues
- Security section added to review artifact
- Security-Sensitive marked YES in main artifact
完成安全审查前,确认以下事项:
- 已审查所有变更过的安全敏感文件
- 已检查全部 10 个 OWASP 类别
- 已运行依赖项审计
- 所有 CRITICAL/HIGH 问题均已修复
- 所有延期处理的问题均有跟踪事项
- 已在审查产物中添加安全部分
- 已在主产物中将 Security-Sensitive 标记为 YES
Integration
集成
This skill is triggered by:
- Changes to security-sensitive file patterns
- Explicit invocation
codex-subagent security-reviewer
This skill integrates with:
- - Security is criterion #4
comprehensive-review - - Verifies security review for sensitive changes
review-gate
This skill is enforced by:
- conditional rules
.codex/rules/security-sensitive.md - PR gate automation (block PR if security-sensitive without review)
此 skill 的触发方式包括:
- 变更涉及安全敏感文件模式
- 显式调用
codex-subagent security-reviewer
此 skill 与以下功能集成:
- ——安全是第 4 项标准
comprehensive-review - ——验证安全敏感变更是否已完成安全审查
review-gate
此 skill 通过以下机制强制执行:
- 条件规则
.codex/rules/security-sensitive.md - PR 门禁自动化(若安全敏感变更未经过审查,则阻止 PR)