@tamsensedev/runner 0.13.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +5 -5
  2. package/README.md +76 -57
  3. package/dist/cli.js +757 -379
  4. package/dist/cli.js.map +1 -1
  5. package/dist/recorder.cjs.map +1 -1
  6. package/library/.claude-plugin/plugin.json +5 -5
  7. package/library/THIRD_PARTY_NOTICES.md +123 -123
  8. package/library/agents/code-architect.md +67 -67
  9. package/library/agents/code-explorer.md +61 -61
  10. package/library/agents/code-reviewer.md +73 -73
  11. package/library/agents/code-simplifier.md +62 -62
  12. package/library/agents/design-critic.md +52 -52
  13. package/library/agents/second-opinion.md +64 -64
  14. package/library/agents/security-auditor.md +86 -86
  15. package/library/agents/silent-failure-hunter.md +70 -70
  16. package/library/agents/test-coverage-analyzer.md +78 -78
  17. package/library/agents/test-runner.md +48 -48
  18. package/library/agents/ui-tester.md +50 -50
  19. package/library/licenses/Apache-2.0.txt +202 -202
  20. package/library/skills/accessibility/SKILL.md +144 -144
  21. package/library/skills/accessibility/references/wcag-checks.md +168 -168
  22. package/library/skills/addressing-review-feedback/SKILL.md +109 -109
  23. package/library/skills/app-screens/SKILL.md +96 -96
  24. package/library/skills/app-screens/references/shell-kpis-charts.md +108 -108
  25. package/library/skills/app-screens/references/states-density-phone.md +54 -54
  26. package/library/skills/app-screens/references/tables-forms-settings.md +104 -104
  27. package/library/skills/avoiding-generic-ai-design/SKILL.md +92 -92
  28. package/library/skills/avoiding-generic-ai-design/references/tells.md +112 -112
  29. package/library/skills/clean-commits/SKILL.md +85 -85
  30. package/library/skills/design-review/SKILL.md +107 -107
  31. package/library/skills/design-review/references/critique-passes.md +101 -101
  32. package/library/skills/design-review/references/screenshot-procedure.md +121 -121
  33. package/library/skills/differential-security-review/LICENSE +427 -427
  34. package/library/skills/differential-security-review/SKILL.md +105 -105
  35. package/library/skills/differential-security-review/references/adversarial.md +115 -115
  36. package/library/skills/differential-security-review/references/methodology.md +145 -145
  37. package/library/skills/differential-security-review/references/patterns.md +108 -108
  38. package/library/skills/false-positive-check/LICENSE +427 -427
  39. package/library/skills/false-positive-check/SKILL.md +95 -95
  40. package/library/skills/false-positive-check/references/bug-class-verification.md +128 -128
  41. package/library/skills/false-positive-check/references/deep-verification.md +113 -113
  42. package/library/skills/false-positive-check/references/evidence-templates.md +93 -93
  43. package/library/skills/false-positive-check/references/false-positive-patterns.md +122 -122
  44. package/library/skills/false-positive-check/references/gate-reviews.md +36 -36
  45. package/library/skills/false-positive-check/references/standard-verification.md +80 -80
  46. package/library/skills/focused-implementation/SKILL.md +104 -104
  47. package/library/skills/implementation-plan/SKILL.md +66 -66
  48. package/library/skills/interface-design/SKILL.md +144 -144
  49. package/library/skills/interface-design/references/craft-defaults.md +130 -130
  50. package/library/skills/interface-design/references/new-direction.md +62 -62
  51. package/library/skills/interface-design/references/writing.md +52 -52
  52. package/library/skills/interface-polish/SKILL.md +103 -103
  53. package/library/skills/interface-polish/references/detail-rules.md +154 -154
  54. package/library/skills/interface-polish/references/worst-case-data.md +158 -158
  55. package/library/skills/motion-design/SKILL.md +106 -106
  56. package/library/skills/motion-design/references/recipes.md +243 -243
  57. package/library/skills/postgres-performance/SKILL.md +97 -97
  58. package/library/skills/postgres-performance/references/rules.md +265 -265
  59. package/library/skills/project-orientation/SKILL.md +77 -77
  60. package/library/skills/reviewing-changes/SKILL.md +183 -183
  61. package/library/skills/safe-database-changes/SKILL.md +111 -111
  62. package/library/skills/safe-database-changes/references/backfills.md +75 -75
  63. package/library/skills/safe-database-changes/references/migration-tools.md +69 -69
  64. package/library/skills/safe-database-changes/references/postgres-ddl.md +199 -199
  65. package/library/skills/security-review/SKILL.md +132 -132
  66. package/library/skills/security-review/references/checks-by-area.md +107 -107
  67. package/library/skills/security-review/references/do-not-report.md +86 -86
  68. package/library/skills/spec-writing/SKILL.md +144 -144
  69. package/library/skills/systematic-debugging/SKILL.md +130 -130
  70. package/library/skills/systematic-debugging/references/flaky-tests.md +51 -51
  71. package/library/skills/systematic-debugging/references/root-cause-tracing.md +55 -55
  72. package/library/skills/task-interview/SKILL.md +84 -84
  73. package/library/skills/test-driven-development/SKILL.md +116 -116
  74. package/library/skills/test-driven-development/references/writing-good-tests.md +85 -85
  75. package/library/skills/ui-testing/SKILL.md +102 -102
  76. package/library/skills/ui-testing/references/headless-check.md +295 -295
  77. package/library/skills/ui-testing/references/local-stand.md +51 -51
  78. package/library/skills/ui-testing/references/playwright-patterns.md +134 -134
  79. package/library/skills/ui-testing/references/recording.md +61 -61
  80. package/library/skills/verification-before-completion/SKILL.md +113 -113
  81. package/library/skills/web-interface-guidelines/SKILL.md +202 -202
  82. package/package.json +46 -46
@@ -1,145 +1,145 @@
1
- # Differential review methodology (phases 0 to 4)
2
-
3
- Read at the start of every differential security review. `<base>` is the base branch named in the task (for example `origin/main`); `<repo>` is the repository folder. Never check out another commit in the repository under review.
4
-
5
- ## Before phase 0: baseline context
6
-
7
- Understand what the code was supposed to do before the change. From the base version (`git -C <repo> show <base>:<path>`, or a detached worktree in a temp directory outside the repository), capture:
8
-
9
- - System-wide invariants: what must always be true (a user only sees their own account's data; a balance never goes negative).
10
- - Trust boundaries and privilege levels: who can do what, and where that is enforced.
11
- - Validation patterns: what gets checked where, and which checks are layered as defense in depth.
12
- - Call graphs for the critical functions the change touches.
13
- - How state changes flow (status transitions, money movement).
14
- - External dependencies and the assumptions made about them.
15
-
16
- This lets you spot when the change violates an invariant, breaks a layer of defense, or deviates from a system-wide pattern.
17
-
18
- ## Phase 0: intake and triage
19
-
20
- ```bash
21
- git -C <repo> log --oneline <base>..HEAD
22
- git -C <repo> diff --stat <base>...HEAD
23
- git -C <repo> diff --name-only <base>...HEAD
24
- ```
25
-
26
- Assess codebase size (count source files of the main languages, for example `git -C <repo> ls-files '*.ts' '*.py' '*.go' | wc -l`) and pick the strategy:
27
-
28
- - Small (under 20 files): deep analysis, read all dependencies.
29
- - Medium (20 to 200): focused analysis, one hop of dependencies.
30
- - Large (over 200): surgical, critical paths only.
31
-
32
- Give every changed file a risk level:
33
-
34
- - HIGH: auth, crypto, external calls, value transfer, validation removal, permission changes.
35
- - MEDIUM: business logic, state changes, new public APIs.
36
- - LOW: comments, tests, UI text, logging.
37
-
38
- ## Phase 1: changed code analysis
39
-
40
- For each changed file, highest risk first:
41
-
42
- 1. **Read both versions**, base and head.
43
- 2. **Analyse each diff region:**
44
- ```
45
- BEFORE: <exact code>
46
- AFTER: <exact code>
47
- CHANGE: <behavioural impact>
48
- SECURITY: <implications>
49
- ```
50
- 3. **Check the history of removed code.** When was it added, and why?
51
- ```bash
52
- git -C <repo> log -S "<removed code>" --oneline <base>
53
- git -C <repo> blame <base> -- <file>
54
- git -C <repo> show <commit>
55
- ```
56
- Red flags: removed code that came from a "fix", "security", "CVE" or "vulnerability" commit is CRITICAL until explained. Code added recently (under a month) and now removed is HIGH.
57
- 4. **Check for regressions** (code being re-added):
58
- ```bash
59
- git -C <repo> log -S "<added code>" -p <base>
60
- ```
61
- Pattern: added, removed for security, re-added now means a regression.
62
- 5. **Micro-adversarial questions** for each change:
63
- - What attack did the removed code prevent?
64
- - What new surface does the new code expose?
65
- - Can the modified logic be bypassed?
66
- - Are checks weaker? Are edge cases still covered?
67
- 6. **Write concrete attack scenarios** for anything suspicious:
68
- ```
69
- SCENARIO: <attack goal>
70
- PRECONDITIONS: <required state>
71
- STEPS:
72
- 1. <specific action>
73
- 2. <expected outcome>
74
- 3. <exploitation>
75
- WHY IT WORKS: <reference to the code change, file:line>
76
- IMPACT: <severity and scope>
77
- ```
78
-
79
- ## Phase 2: test coverage of changed code
80
-
81
- ```bash
82
- git -C <repo> diff --name-only <base>...HEAD | grep -v -i test
83
- git -C <repo> diff --name-only <base>...HEAD | grep -i test
84
- git -C <repo> grep -n "<functionName>" -- '*test*' '*spec*'
85
- ```
86
-
87
- Adapt the test file patterns to the project's layout. Risk elevation rules:
88
-
89
- - New function and no tests: raise MEDIUM to HIGH.
90
- - Modified validation and unchanged tests: HIGH.
91
- - Complex logic (over 20 lines) and no tests: HIGH.
92
-
93
- ## Phase 3: blast radius
94
-
95
- Count the callers of each modified function:
96
-
97
- ```bash
98
- git -C <repo> grep -n "<functionName>(" | wc -l
99
- ```
100
-
101
- Also check dynamic references (route tables, dependency injection, string-based lookups) where the language uses them.
102
-
103
- | Callers | Blast radius |
104
- |---|---|
105
- | 1 to 5 | LOW |
106
- | 6 to 20 | MEDIUM |
107
- | 21 to 50 | HIGH |
108
- | over 50 | CRITICAL |
109
-
110
- Priority matrix:
111
-
112
- | Change risk | Blast radius | Priority | Depth |
113
- |---|---|---|---|
114
- | HIGH | CRITICAL | P0 | Deep, all dependencies |
115
- | HIGH | HIGH or MEDIUM | P1 | Deep |
116
- | HIGH | LOW | P2 | Standard |
117
- | MEDIUM | CRITICAL or HIGH | P1 | Standard plus callers |
118
-
119
- ## Phase 4: deep context for HIGH risk changes
120
-
121
- For each HIGH risk changed function, using Read, Grep and code tracing:
122
-
123
- 1. **Map the function flow:** entry conditions (guards, middleware, decorators), state read, state written, external calls, return values and side effects.
124
- 2. **Trace internal calls:** list every function called and map their flows in turn.
125
- 3. **Trace external calls:** which trust boundaries are crossed, what is assumed about the other side's behaviour, whether a callback or re-entry is possible.
126
- 4. **Identify invariants:** what must always be true, what must never happen, and whether the change keeps them.
127
- 5. **Five whys:**
128
- - Why was this code changed?
129
- - Why did the original code exist?
130
- - Why might this break?
131
- - Why was this approach chosen?
132
- - Why could this fail in production?
133
-
134
- **Cross-cutting patterns:** find the validation and permission patterns repeated across the codebase and check whether the diff removed any instance:
135
-
136
- ```bash
137
- git -C <repo> grep -n "<repeated guard, e.g. requireRole(>"
138
- git -C <repo> diff <base>...HEAD | grep "^-.*<repeated guard>"
139
- ```
140
-
141
- Flag a removal that breaks defense in depth.
142
-
143
- Next: for HIGH risk changes, continue with [adversarial.md](adversarial.md).
144
-
145
- Part of the `differential-security-review` skill, adapted from https://github.com/trailofbits/skills/tree/main/plugins/differential-review (commit 5c99c03fb8a9ea568432ecbcba5d86e9f4ac2bf0), CC BY-SA 4.0. Changed: no checkouts, no external skills, commands made language-neutral and scoped to the repository folder.
1
+ # Differential review methodology (phases 0 to 4)
2
+
3
+ Read at the start of every differential security review. `<base>` is the base branch named in the task (for example `origin/main`); `<repo>` is the repository folder. Never check out another commit in the repository under review.
4
+
5
+ ## Before phase 0: baseline context
6
+
7
+ Understand what the code was supposed to do before the change. From the base version (`git -C <repo> show <base>:<path>`, or a detached worktree in a temp directory outside the repository), capture:
8
+
9
+ - System-wide invariants: what must always be true (a user only sees their own account's data; a balance never goes negative).
10
+ - Trust boundaries and privilege levels: who can do what, and where that is enforced.
11
+ - Validation patterns: what gets checked where, and which checks are layered as defense in depth.
12
+ - Call graphs for the critical functions the change touches.
13
+ - How state changes flow (status transitions, money movement).
14
+ - External dependencies and the assumptions made about them.
15
+
16
+ This lets you spot when the change violates an invariant, breaks a layer of defense, or deviates from a system-wide pattern.
17
+
18
+ ## Phase 0: intake and triage
19
+
20
+ ```bash
21
+ git -C <repo> log --oneline <base>..HEAD
22
+ git -C <repo> diff --stat <base>...HEAD
23
+ git -C <repo> diff --name-only <base>...HEAD
24
+ ```
25
+
26
+ Assess codebase size (count source files of the main languages, for example `git -C <repo> ls-files '*.ts' '*.py' '*.go' | wc -l`) and pick the strategy:
27
+
28
+ - Small (under 20 files): deep analysis, read all dependencies.
29
+ - Medium (20 to 200): focused analysis, one hop of dependencies.
30
+ - Large (over 200): surgical, critical paths only.
31
+
32
+ Give every changed file a risk level:
33
+
34
+ - HIGH: auth, crypto, external calls, value transfer, validation removal, permission changes.
35
+ - MEDIUM: business logic, state changes, new public APIs.
36
+ - LOW: comments, tests, UI text, logging.
37
+
38
+ ## Phase 1: changed code analysis
39
+
40
+ For each changed file, highest risk first:
41
+
42
+ 1. **Read both versions**, base and head.
43
+ 2. **Analyse each diff region:**
44
+ ```
45
+ BEFORE: <exact code>
46
+ AFTER: <exact code>
47
+ CHANGE: <behavioural impact>
48
+ SECURITY: <implications>
49
+ ```
50
+ 3. **Check the history of removed code.** When was it added, and why?
51
+ ```bash
52
+ git -C <repo> log -S "<removed code>" --oneline <base>
53
+ git -C <repo> blame <base> -- <file>
54
+ git -C <repo> show <commit>
55
+ ```
56
+ Red flags: removed code that came from a "fix", "security", "CVE" or "vulnerability" commit is CRITICAL until explained. Code added recently (under a month) and now removed is HIGH.
57
+ 4. **Check for regressions** (code being re-added):
58
+ ```bash
59
+ git -C <repo> log -S "<added code>" -p <base>
60
+ ```
61
+ Pattern: added, removed for security, re-added now means a regression.
62
+ 5. **Micro-adversarial questions** for each change:
63
+ - What attack did the removed code prevent?
64
+ - What new surface does the new code expose?
65
+ - Can the modified logic be bypassed?
66
+ - Are checks weaker? Are edge cases still covered?
67
+ 6. **Write concrete attack scenarios** for anything suspicious:
68
+ ```
69
+ SCENARIO: <attack goal>
70
+ PRECONDITIONS: <required state>
71
+ STEPS:
72
+ 1. <specific action>
73
+ 2. <expected outcome>
74
+ 3. <exploitation>
75
+ WHY IT WORKS: <reference to the code change, file:line>
76
+ IMPACT: <severity and scope>
77
+ ```
78
+
79
+ ## Phase 2: test coverage of changed code
80
+
81
+ ```bash
82
+ git -C <repo> diff --name-only <base>...HEAD | grep -v -i test
83
+ git -C <repo> diff --name-only <base>...HEAD | grep -i test
84
+ git -C <repo> grep -n "<functionName>" -- '*test*' '*spec*'
85
+ ```
86
+
87
+ Adapt the test file patterns to the project's layout. Risk elevation rules:
88
+
89
+ - New function and no tests: raise MEDIUM to HIGH.
90
+ - Modified validation and unchanged tests: HIGH.
91
+ - Complex logic (over 20 lines) and no tests: HIGH.
92
+
93
+ ## Phase 3: blast radius
94
+
95
+ Count the callers of each modified function:
96
+
97
+ ```bash
98
+ git -C <repo> grep -n "<functionName>(" | wc -l
99
+ ```
100
+
101
+ Also check dynamic references (route tables, dependency injection, string-based lookups) where the language uses them.
102
+
103
+ | Callers | Blast radius |
104
+ |---|---|
105
+ | 1 to 5 | LOW |
106
+ | 6 to 20 | MEDIUM |
107
+ | 21 to 50 | HIGH |
108
+ | over 50 | CRITICAL |
109
+
110
+ Priority matrix:
111
+
112
+ | Change risk | Blast radius | Priority | Depth |
113
+ |---|---|---|---|
114
+ | HIGH | CRITICAL | P0 | Deep, all dependencies |
115
+ | HIGH | HIGH or MEDIUM | P1 | Deep |
116
+ | HIGH | LOW | P2 | Standard |
117
+ | MEDIUM | CRITICAL or HIGH | P1 | Standard plus callers |
118
+
119
+ ## Phase 4: deep context for HIGH risk changes
120
+
121
+ For each HIGH risk changed function, using Read, Grep and code tracing:
122
+
123
+ 1. **Map the function flow:** entry conditions (guards, middleware, decorators), state read, state written, external calls, return values and side effects.
124
+ 2. **Trace internal calls:** list every function called and map their flows in turn.
125
+ 3. **Trace external calls:** which trust boundaries are crossed, what is assumed about the other side's behaviour, whether a callback or re-entry is possible.
126
+ 4. **Identify invariants:** what must always be true, what must never happen, and whether the change keeps them.
127
+ 5. **Five whys:**
128
+ - Why was this code changed?
129
+ - Why did the original code exist?
130
+ - Why might this break?
131
+ - Why was this approach chosen?
132
+ - Why could this fail in production?
133
+
134
+ **Cross-cutting patterns:** find the validation and permission patterns repeated across the codebase and check whether the diff removed any instance:
135
+
136
+ ```bash
137
+ git -C <repo> grep -n "<repeated guard, e.g. requireRole(>"
138
+ git -C <repo> diff <base>...HEAD | grep "^-.*<repeated guard>"
139
+ ```
140
+
141
+ Flag a removal that breaks defense in depth.
142
+
143
+ Next: for HIGH risk changes, continue with [adversarial.md](adversarial.md).
144
+
145
+ Part of the `differential-security-review` skill, adapted from https://github.com/trailofbits/skills/tree/main/plugins/differential-review (commit 5c99c03fb8a9ea568432ecbcba5d86e9f4ac2bf0), CC BY-SA 4.0. Changed: no checkouts, no external skills, commands made language-neutral and scoped to the repository folder.
@@ -1,108 +1,108 @@
1
- # Common vulnerability patterns in diffs
2
-
3
- Read during phase 1. Quick reference for detecting security problems in a change. Each `git diff` command assumes `git -C <repo> diff <base>...HEAD`, shortened below to `git diff <range>`.
4
-
5
- ## Security regressions
6
-
7
- **Pattern:** code previously removed for security reasons is added again.
8
-
9
- ```bash
10
- git log -S "<pattern>" --oneline -i --grep="security\|fix\|cve\|vuln" <base>
11
- ```
12
-
13
- Red flags: the earlier commit message mentions security, fix, CVE or vulnerability; the removal was recent (under six months); the current change gives no reason for re-adding it.
14
-
15
- ## Missing validation
16
-
17
- **Pattern:** a check, guard, assertion or schema rule removed without a replacement.
18
-
19
- ```bash
20
- git diff <range> | grep -E "^-.*(throw|assert|require|validate|schema|guard|check|return .*40[0-4])"
21
- ```
22
-
23
- Ask: was the validation moved elsewhere? Is it truly redundant? Does the removal expose something?
24
-
25
- ```diff
26
- async function withdraw(userId, amount) {
27
- - if (amount <= 0) throw new BadRequest('amount must be positive')
28
- - if (amount > await balanceOf(userId)) throw new BadRequest('insufficient funds')
29
- await ledger.debit(userId, amount)
30
- }
31
- ```
32
-
33
- Risk: negative withdrawals credit the account; overdrafts are possible.
34
-
35
- ## Access control bypass
36
-
37
- **Pattern:** a permission check removed or relaxed, or a route moved out of a protected group.
38
-
39
- ```bash
40
- git diff <range> | grep -E "^-.*(auth|guard|policy|permission|role|can[A-Z]|isAdmin|owner|tenant|accountId)"
41
- ```
42
-
43
- Ask: who can call this now? What is the new trust model? Was the check moved to the caller, and do all callers have it?
44
-
45
- ```diff
46
- - router.post('/settings', requireRole('admin'), updateSettings)
47
- + router.post('/settings', updateSettings)
48
- ```
49
-
50
- Risk: any user can change global settings.
51
-
52
- ## Double accounting
53
-
54
- **Pattern:** the same balance, stock or counter is changed twice for one logical event, often in two functions that each assume the other did not.
55
-
56
- ```js
57
- // request a refund
58
- balance[user] += amount // first credit
59
- // later, when the provider confirms
60
- balance[user] += amount // second credit: bug
61
- ```
62
-
63
- Impact: users are credited twice; the books do not balance.
64
-
65
- ## Races and check-then-act
66
-
67
- **Pattern:** a value is checked and then used in separate steps without a transaction, lock or unique constraint: coupon redemption, stock reservation, "only one active subscription", balance checks.
68
-
69
- Ask: what happens when two requests arrive at the same moment? Is there a database constraint that makes the second one fail?
70
-
71
- ## Unchecked results of external calls
72
-
73
- **Pattern:** the response of a payment provider, storage service, email API or child process is not checked, so a failure is treated as success.
74
-
75
- ```bash
76
- git diff <range> | grep -E "^\+.*(fetch\(|axios|request\(|\.send\(|\.charge\(|\.upload\(|exec\()"
77
- ```
78
-
79
- Risk: silent failures leave state inconsistent (order marked paid, charge failed).
80
-
81
- ## New external calls and outbound URLs
82
-
83
- **Pattern:** the change adds calls to other services or fetches URLs. Check where the URL and the data come from (SSRF), whether TLS verification stays on, and whether the response is validated before use.
84
-
85
- ## Denial of service
86
-
87
- **Pattern:** loops or queries over user-controlled sizes, unbounded batch endpoints, work that one request can multiply. Report as a note unless the task is about it; it does not block on its own.
88
-
89
- ## Smart contracts
90
-
91
- If the repository is a smart-contract project, also check: external calls made before state updates (re-entrancy), arithmetic in `unchecked` blocks or old compiler versions (overflow), security logic depending on block timestamps, two-step approvals open to front-running, and return values of token transfers that are ignored.
92
-
93
- ## Quick detection commands
94
-
95
- ```bash
96
- # removed checks
97
- git diff <range> | grep "^-" | grep -E "throw|assert|require|validate|guard|policy"
98
- # added external calls
99
- git diff <range> | grep "^+" | grep -E "fetch\(|axios|http\.|request\(|exec\(|spawn\("
100
- # changed visibility or exposure
101
- git diff <range> | grep -E "export |public |private |internal |router\.|app\.(get|post|put|delete)"
102
- # raw queries and raw HTML
103
- git diff <range> | grep "^+" | grep -E "raw|Unsafe|innerHTML|v-html|dangerouslySetInnerHTML"
104
- ```
105
-
106
- Next: methodology in [methodology.md](methodology.md), exploit scenarios in [adversarial.md](adversarial.md).
107
-
108
- Part of the `differential-security-review` skill, adapted from https://github.com/trailofbits/skills/tree/main/plugins/differential-review (commit 5c99c03fb8a9ea568432ecbcba5d86e9f4ac2bf0), CC BY-SA 4.0. Changed: examples and detection commands rewritten for web stacks, smart-contract patterns condensed into one section, added races, double accounting and outbound-call patterns for web applications.
1
+ # Common vulnerability patterns in diffs
2
+
3
+ Read during phase 1. Quick reference for detecting security problems in a change. Each `git diff` command assumes `git -C <repo> diff <base>...HEAD`, shortened below to `git diff <range>`.
4
+
5
+ ## Security regressions
6
+
7
+ **Pattern:** code previously removed for security reasons is added again.
8
+
9
+ ```bash
10
+ git log -S "<pattern>" --oneline -i --grep="security\|fix\|cve\|vuln" <base>
11
+ ```
12
+
13
+ Red flags: the earlier commit message mentions security, fix, CVE or vulnerability; the removal was recent (under six months); the current change gives no reason for re-adding it.
14
+
15
+ ## Missing validation
16
+
17
+ **Pattern:** a check, guard, assertion or schema rule removed without a replacement.
18
+
19
+ ```bash
20
+ git diff <range> | grep -E "^-.*(throw|assert|require|validate|schema|guard|check|return .*40[0-4])"
21
+ ```
22
+
23
+ Ask: was the validation moved elsewhere? Is it truly redundant? Does the removal expose something?
24
+
25
+ ```diff
26
+ async function withdraw(userId, amount) {
27
+ - if (amount <= 0) throw new BadRequest('amount must be positive')
28
+ - if (amount > await balanceOf(userId)) throw new BadRequest('insufficient funds')
29
+ await ledger.debit(userId, amount)
30
+ }
31
+ ```
32
+
33
+ Risk: negative withdrawals credit the account; overdrafts are possible.
34
+
35
+ ## Access control bypass
36
+
37
+ **Pattern:** a permission check removed or relaxed, or a route moved out of a protected group.
38
+
39
+ ```bash
40
+ git diff <range> | grep -E "^-.*(auth|guard|policy|permission|role|can[A-Z]|isAdmin|owner|tenant|accountId)"
41
+ ```
42
+
43
+ Ask: who can call this now? What is the new trust model? Was the check moved to the caller, and do all callers have it?
44
+
45
+ ```diff
46
+ - router.post('/settings', requireRole('admin'), updateSettings)
47
+ + router.post('/settings', updateSettings)
48
+ ```
49
+
50
+ Risk: any user can change global settings.
51
+
52
+ ## Double accounting
53
+
54
+ **Pattern:** the same balance, stock or counter is changed twice for one logical event, often in two functions that each assume the other did not.
55
+
56
+ ```js
57
+ // request a refund
58
+ balance[user] += amount // first credit
59
+ // later, when the provider confirms
60
+ balance[user] += amount // second credit: bug
61
+ ```
62
+
63
+ Impact: users are credited twice; the books do not balance.
64
+
65
+ ## Races and check-then-act
66
+
67
+ **Pattern:** a value is checked and then used in separate steps without a transaction, lock or unique constraint: coupon redemption, stock reservation, "only one active subscription", balance checks.
68
+
69
+ Ask: what happens when two requests arrive at the same moment? Is there a database constraint that makes the second one fail?
70
+
71
+ ## Unchecked results of external calls
72
+
73
+ **Pattern:** the response of a payment provider, storage service, email API or child process is not checked, so a failure is treated as success.
74
+
75
+ ```bash
76
+ git diff <range> | grep -E "^\+.*(fetch\(|axios|request\(|\.send\(|\.charge\(|\.upload\(|exec\()"
77
+ ```
78
+
79
+ Risk: silent failures leave state inconsistent (order marked paid, charge failed).
80
+
81
+ ## New external calls and outbound URLs
82
+
83
+ **Pattern:** the change adds calls to other services or fetches URLs. Check where the URL and the data come from (SSRF), whether TLS verification stays on, and whether the response is validated before use.
84
+
85
+ ## Denial of service
86
+
87
+ **Pattern:** loops or queries over user-controlled sizes, unbounded batch endpoints, work that one request can multiply. Report as a note unless the task is about it; it does not block on its own.
88
+
89
+ ## Smart contracts
90
+
91
+ If the repository is a smart-contract project, also check: external calls made before state updates (re-entrancy), arithmetic in `unchecked` blocks or old compiler versions (overflow), security logic depending on block timestamps, two-step approvals open to front-running, and return values of token transfers that are ignored.
92
+
93
+ ## Quick detection commands
94
+
95
+ ```bash
96
+ # removed checks
97
+ git diff <range> | grep "^-" | grep -E "throw|assert|require|validate|guard|policy"
98
+ # added external calls
99
+ git diff <range> | grep "^+" | grep -E "fetch\(|axios|http\.|request\(|exec\(|spawn\("
100
+ # changed visibility or exposure
101
+ git diff <range> | grep -E "export |public |private |internal |router\.|app\.(get|post|put|delete)"
102
+ # raw queries and raw HTML
103
+ git diff <range> | grep "^+" | grep -E "raw|Unsafe|innerHTML|v-html|dangerouslySetInnerHTML"
104
+ ```
105
+
106
+ Next: methodology in [methodology.md](methodology.md), exploit scenarios in [adversarial.md](adversarial.md).
107
+
108
+ Part of the `differential-security-review` skill, adapted from https://github.com/trailofbits/skills/tree/main/plugins/differential-review (commit 5c99c03fb8a9ea568432ecbcba5d86e9f4ac2bf0), CC BY-SA 4.0. Changed: examples and detection commands rewritten for web stacks, smart-contract patterns condensed into one section, added races, double accounting and outbound-call patterns for web applications.