Bug Audit — Dissect, Then Verify
Do NOT run a generic checklist. Instead: read the code, extract every auditable entity, then exhaustively question each one.
Phase 1: Dissect (10-15 min)
Read all project files. Build 7 tables. These tables ARE the audit — everything found here gets verified in Phase 2.
Table 1: API Endpoints
For every route in server-side code:
CODEBLOCK0
For each endpoint, ask:
- - Can I call this without authentication?
- Can I pass 0, negative, NaN, huge numbers, arrays, objects?
- Can I skip a prerequisite API and call this directly?
- What happens if I call this 100 times per second?
- Does the response leak sensitive data (openid, internal IDs, full user objects)?
Table 2: State Machines
For every boolean/enum state variable (isGameOver, battleState, Game.running, phase, mode...):
CODEBLOCK1
For each variable, ask:
- - If the game/session ends, does this get reset?
- If I start a new round immediately, will stale state from the previous round affect it?
- Are there race conditions between setters?
Table 3: Timers
For every setTimeout/setInterval:
CODEBLOCK2
For each timer, ask:
- - Is the handle stored for cleanup?
- If the game ends / user disconnects / page navigates, does this still fire?
- If it fires after cleanup, does it reference destroyed objects?
Table 4: Numeric Values
For every user-influenceable number (cost, score, damage, lootValue, kills, quantity...):
CODEBLOCK3
For each value, ask:
- - Is the server-side cap realistic? (kills cap 200 but max enemies is 50?)
- Can the client send a value the server trusts without verification?
- Float precision issues? (accumulated math → 290402.0000000001)
Table 5: Data Flows (Critical!)
For every pair of related APIs (buy→use, start→complete, pay→deliver, login→action):
CODEBLOCK4
This is where the biggest bugs hide. For each flow, ask:
- - Can I call Step 2 without ever calling Step 1? (raid-result without buy)
- Can I call Step 1 once but Step 2 many times? (buy once, submit results 10 times)
- Is there a one-time token linking them? If not, this is a critical vulnerability.
- Can I call Step 1 with cost=0 then Step 2 with high reward?
Table 6: Resource Ledger
For every in-game resource (coins, gems, items, XP, energy...):
CODEBLOCK5
For each resource, ask:
- - Is there any inflow without a corresponding cost? (free coins from quest with no cooldown)
- Can any outflow go negative? (sell item → coins, but what if coins overflow?)
- Are items in safe-box excluded from ALL outflows? (trade, sell, merge, fuse, gift)
- Is there a loop? (buy item A → sell for more than cost → repeat)
Table 7: Concurrency Hotspots (TOCTOU)
For every operation that reads-then-writes shared state (balance check→deduct, stock check→reserve, coupon check→redeem):
CODEBLOCK6
This catches race conditions that single-request testing misses. For each operation, ask:
- - Is the read-then-write atomic? (SQL
UPDATE x=x-1 WHERE x>=1 is atomic; SELECT then UPDATE is NOT) - Can two concurrent requests both pass the check and both execute the write? (double-spend)
- Is there a mutex/lock/transaction? If using SQLite, is WAL mode enabled for concurrent reads?
- For multi-step flows: can request A be between steps while request B starts the same flow?
Phase 2: Verify (main audit)
Go through every row in every table. For each row, determine:
- - 🔴 Critical: exploitable security hole, data loss, crash
- 🟡 Medium: logic error, inconsistency, performance issue
- 🟢 Minor: code quality, edge case, UX issue
- ✅ OK: verified correct
Output format:
CODEBLOCK7
Do NOT stop when you run out of "inspiration". You stop when every row in every table has been verified ✅ or flagged 🔴/🟡/🟢. This is exhaustive, not heuristic.
Phase 3: Red Team / Blue Team
After verifying all tables, switch to adversarial mode. Read references/redblue.md for the full playbook.
Structure
The playbook has 4 parts:
- 1. Universal Chains (5) — apply to ALL projects: Auth Bypass, Injection, Rate Abuse, Data Leakage, Concurrency/Race Conditions
- Type-Specific Chains — pick sections matching the project:
- 🎮 Game: Skip-Pay-Collect, Economic Loop, State Manipulation, Anti-Cheat Bypass
- 📊 Data Tool: Data Access Control, Data Integrity, Scheduled Task Abuse
- 🔌 API Service: Key/Token Abuse, Upstream Dependency, Response Manipulation
- 🤖 Bot: Message Injection, Bot State Abuse
- 🔧 WeChat: OAuth & Identity, WebView Compatibility, H5 Hybrid
- 📈 Platform: Cross-Service Trust, Multi-Tenant Isolation
- 3. Blue Team Defense — for each finding, verify 4 layers: Prevention → Detection → Containment → Recovery
- Execution Guide — step-by-step for the auditor
How to Run
- 1. From Phase 1 dissection, identify project type(s) — a project can match multiple types
- Run ALL 5 Universal Chains
- Run type-specific chains matching the project
- For each 🔴 finding: verify all 4 Blue Team layers
- For each 🟡 finding: verify Layer 1 (Prevention) at minimum
Phase 4: Supplement
After red/blue team, run generic checks as a final safety net. Read references/modules.md and pick sections matching the project:
- - 🔒 Security (S1-S3): CORS, XSS, SQLi, brute force — if project has users
- 🔐 Crypto (C1): Hardcoded secrets, weak hashing, plaintext storage, insecure random — all projects
- 📊 Data (D1-D3): Timezone, atomic ops, float precision — if project has DB
- ⚡ Performance (P1-P2): Memory leaks, hot paths — if project is large/realtime
- 🎮 Game (G1-G4): State guards, rendering, config — if project is a game
- 🔧 WeChat (W1-W3): ES6 compat, CDN, debugging — if runs in WeChat WebView
- 🔌 API (A1-A3): Interface standards, rate limiting — if project is an API service
- 🤖 Bot (B1): Timeout, dedup, sensitive words — if project is a bot
- 🚀 Deploy (R1-R2): PM2, nginx, SSL, SDK overwrite — all projects
- 🧪 Error Handling (E1-E2): Network errors, server errors, graceful degradation — all projects
- 📱 UX Robustness (U1-U2): Error states, edge case UX — all projects with UI
- 📦 Supply Chain (SC1): npm audit, dependency vulnerabilities, lockfile integrity — all Node.js projects
- 📝 Logging (L1): Security event logging, audit trail completeness — all projects with users
Phase 5: Regression + Verify
- - Check that fixes didn't introduce new bugs
- After modular split: verify cross-file variable/function reachability
- Live smoke test: homepage 200, key APIs return JSON, login works, core feature functional
Phase 6: Archive
Update project docs with: date, tables built, bugs found/fixed, key pitfalls for next audit.
Key Principles
- 1. Tables first, checking second. Building the tables IS the hard work. Once you have them, verification is mechanical.
- Exhaustive, not heuristic. Don't stop when you "feel done." Stop when every row is verified.
- Think like an attacker. For every API: "How would I exploit this?" For every value: "What if I send garbage?"
- Data flows are where critical bugs hide. The link (or lack thereof) between related APIs is the #1 source of exploitable vulnerabilities.
- Generic checklists are supplements, not the main event. They catch known patterns; the tables catch project-specific logic bugs.
Reference Files
- -
references/modules.md — Generic audit modules (Security, Crypto, Data, Performance, Game, WeChat, API, Bot, Deploy, Error Handling, UX, Supply Chain, Logging) for Phase 4 supplementary checks. - INLINECODE6 — Red team attack chains (universal + 6 project types) and blue team defense verification playbook for Phase 3.
- INLINECODE7 — Real-world pitfall lookup table from 200+ bugs, plus WeChat WebView remote debugging techniques.
Bug Audit — 剖析,然后验证
不要运行通用检查清单。相反:阅读代码,提取每一个可审计的实体,然后穷尽地质疑每一个。
第一阶段:剖析(10-15分钟)
阅读所有项目文件。构建7张表格。这些表格就是审计本身——这里发现的所有内容都将在第二阶段进行验证。
表1:API端点
针对服务端代码中的每一条路由:
| # | 方法 | 路径 | 需要认证? | 参数已验证? | 前置条件 | 返回值 | 攻击向量 |
针对每个端点,询问:
- - 我能否在没有认证的情况下调用它?
- 我能否传入0、负数、NaN、超大数字、数组、对象?
- 我能否跳过前置API直接调用它?
- 如果我每秒调用100次会发生什么?
- 响应是否泄露了敏感数据(openid、内部ID、完整的用户对象)?
表2:状态机
针对每个布尔/枚举状态变量(isGameOver、battleState、Game.running、phase、mode……):
| # | 变量 | 由谁设置 | 由谁读取 | 初始值 | 何时重置? | 能否跨生命周期泄漏? |
针对每个变量,询问:
- - 如果游戏/会话结束,这个变量会被重置吗?
- 如果我立即开始新的一轮,上一轮的过期状态会影响它吗?
- 设置器之间存在竞态条件吗?
表3:定时器
针对每个setTimeout/setInterval:
| # | 类型 | 延迟 | 创建位置 | 清除位置 | 如果生命周期在触发前结束会怎样? |
针对每个定时器,询问:
- - 句柄是否被存储以便清理?
- 如果游戏结束/用户断开连接/页面导航离开,它仍然会触发吗?
- 如果在清理后触发,它是否会引用已销毁的对象?
表4:数值
针对每个受用户影响的数值(cost、score、damage、lootValue、kills、quantity……):
| # | 名称 | 来源(客户端/服务端/配置) | 已验证? | 最小值 | 最大值 | 如果为0会怎样? | 如果为负数会怎样? |
针对每个数值,询问:
- - 服务端的上限是否合理?(kills上限200但最大敌人是50?)
- 客户端能否发送一个服务端未经验证就信任的值?
- 浮点数精度问题?(累积计算 → 290402.0000000001)
表5:数据流(关键!)
针对每一对相关的API(buy→use、start→complete、pay→deliver、login→action):
| # | 步骤1 API | 步骤2 API | 它们之间的令牌/链接? | 能否跳过步骤1? | 能否重放步骤1? |
这是最大bug隐藏的地方。针对每个流程,询问:
- - 我能否在不调用步骤1的情况下调用步骤2?(不购买就获取raid-result)
- 我能否调用步骤1一次但步骤2多次?(购买一次,提交结果10次)
- 是否有一次性令牌连接它们?如果没有,这就是一个严重漏洞。
- 我能否以cost=0调用步骤1,然后以高奖励调用步骤2?
表6:资源账本
针对每个游戏内资源(coins、gems、items、XP、energy……):
| # | 资源 | 所有流入(增加资源的API/事件) | 所有流出(减少资源的API/事件) | 每日限制? | 是否有任何流入可以是无限的? |
针对每个资源,询问:
- - 是否有任何没有对应成本的流入?(来自任务的免费金币且无冷却时间)
- 是否有任何流出可能变为负数?(出售物品→获得金币,但如果金币溢出呢?)
- 保险箱中的物品是否被排除在所有流出之外?(交易、出售、合并、融合、赠送)
- 是否存在循环?(购买物品A→以高于成本的价格出售→重复)
表7:并发热点(TOCTOU)
针对每个读取然后写入共享状态的操作(余额检查→扣除、库存检查→预留、优惠券检查→兑换):
| # | 操作 | 读取步骤 | 写入步骤 | 原子性? | 如果2个请求同时到达会怎样? |
这能捕获单请求测试遗漏的竞态条件。针对每个操作,询问:
- - 读取然后写入的操作是原子的吗?(SQL UPDATE x=x-1 WHERE x>=1 是原子的;SELECT 然后 UPDATE 不是)
- 两个并发请求能否都通过检查并都执行写入?(双重消费)
- 是否有互斥锁/锁/事务?如果使用SQLite,是否启用了WAL模式以支持并发读取?
- 对于多步骤流程:请求A能否在步骤之间时,请求B启动相同的流程?
第二阶段:验证(主要审计)
遍历每张表中的每一行。针对每一行,确定:
- - 🔴 严重:可利用的安全漏洞、数据丢失、崩溃
- 🟡 中等:逻辑错误、不一致、性能问题
- 🟢 次要:代码质量、边界情况、用户体验问题
- ✅ 正常:已验证正确
输出格式:
Bug N: [🔴/🟡/🟢] 简要描述
不要在你灵感枯竭时停止。 当每张表中的每一行都已被验证为✅或被标记为🔴/🟡/🟢时,你才停止。这是穷尽式的,而非启发式的。
第三阶段:红队 / 蓝队
在验证完所有表格后,切换到对抗模式。阅读 references/redblue.md 获取完整剧本。
结构
剧本包含4个部分:
- 1. 通用攻击链(5条) — 适用于所有项目:认证绕过、注入、速率滥用、数据泄露、并发/竞态条件
- 类型特定攻击链 — 选择与项目匹配的部分:
- 🎮 游戏:跳过支付-收集、经济循环、状态操纵、反作弊绕过
- 📊 数据工具:数据访问控制、数据完整性、定时任务滥用
- 🔌 API服务:密钥/令牌滥用、上游依赖、响应操纵
- 🤖 机器人:消息注入、机器人状态滥用
- 🔧 微信:OAuth与身份、WebView兼容性、H5混合
- 📈 平台:跨服务信任、多租户隔离
- 3. 蓝队防御 — 针对每个发现,验证4个层面:预防 → 检测 → 遏制 → 恢复
- 执行指南 — 审计员的分步指南
如何运行
- 1. 从第一阶段的剖析中,确定项目类型——一个项目可以匹配多种类型
- 运行所有5条通用攻击链
- 运行与项目匹配的类型特定攻击链
- 针对每个🔴发现:验证所有4个蓝队层面
- 针对每个🟡发现:至少验证第1层(预防)
第四阶段:补充
在红/蓝队之后,运行通用检查作为最终安全网。阅读 references/modules.md 并选择与项目匹配的部分:
- - 🔒 安全(S1-S3):CORS、XSS、SQLi、暴力破解——如果项目有用户
- 🔐 加密(C1):硬编码密钥、弱哈希、明文存储、不安全的随机数——所有项目
- 📊 数据(D1-D3):时区、原子操作、浮点精度——如果项目有数据库
- ⚡ 性能(P1-P2):内存泄漏、热点路径——如果项目是大规模/实时
- 🎮 游戏(G1-G4):状态守卫、渲染、配置——如果项目是游戏
- 🔧 微信(W1-W3):ES6兼容性、CDN、调试——如果在微信WebView中运行
- 🔌 API(A1-A3):接口标准、速率限制——如果项目是API服务
- 🤖 机器人(B1):超时、去重、敏感词——如果项目是机器人
- 🚀 部署(R1-R2):PM2、nginx、SSL、SDK覆盖——所有项目
- 🧪 错误处理(E1-E2):网络错误、服务器错误、优雅降级——所有项目
- 📱 用户体验鲁棒性(U1-U2):错误状态、边界情况用户体验——所有有UI的项目
- 📦 供应链(SC1):npm审计、依赖漏洞、锁文件完整性——所有Node.js项目
- 📝 日志记录(L1):安全事件日志记录、审计追踪完整性——所有有用户的项目
第五阶段:回归 + 验证
- - 检查修复是否引入了新bug
- 模块拆分后:验证跨文件的变量/函数可达性
- 实时冒烟测试:首页200、关键API返回JSON、登录正常、核心功能可用
第六阶段:归档
更新项目文档,包含:日期、构建的表格、发现/修复的