Commit c2ea35a
fix(security): close CodeQL go/command-injection in runGit (#55)
CodeQL alert #33 (Critical): exec.Command("git", ...) in runGit
received user-controlled strings (commit message bytes from author /
subject, and paths from note keys). Although exec.Command uses argv
(no shell) which makes the standard shell-injection vector inert, git
itself has flag-based attack surface (e.g. `--upload-pack=cmd`,
`-c core.sshCommand=...`) that CodeQL is right to flag.
Defense in depth:
1. `runGit` now enforces:
- notesDir must be non-empty and must not start with "-" (prevents
it being parsed as a git top-level flag).
- args[0] must be in a closed allow-list of subcommands (init /
config / add / log). Commit is deliberately routed elsewhere
(see #2).
- Any arg after a literal "--" must satisfy filepath.IsLocal —
this continues the sanitiser from PR #44 and is what CodeQL
recognises.
2. `gitCommit` is a new helper that runs `git commit --no-gpg-sign
-F -` and pipes the message via stdin. The message bytes therefore
never appear in argv, cutting the only remaining taint flow from
user input to exec.Command args.
3. autoCommit's commit call switched from runGit(..., "commit", "-m",
msg) to gitCommit(notesDir, msg).
Tested locally: 104/104 tests passing in internal/notes/.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8e9809f commit c2ea35a
1 file changed
Lines changed: 66 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
103 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
104 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
105 | 148 | | |
106 | 149 | | |
107 | 150 | | |
| |||
117 | 160 | | |
118 | 161 | | |
119 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
120 | 185 | | |
121 | 186 | | |
122 | 187 | | |
| |||
216 | 281 | | |
217 | 282 | | |
218 | 283 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 284 | + | |
223 | 285 | | |
224 | 286 | | |
225 | 287 | | |
| |||
0 commit comments