Commit 255d446
fix(#187 AC#2): address Copilot review — 3 IDOR + OOM + races
12 substantive findings from Copilot's review of PR #247, all fixed:
Security (3 IDOR vulns):
- POST /downloads/start: requireOwnership middleware (body.userId
must match req.authenticatedUserId)
- GET /downloads/:id and pause/resume/cancel: loadOwnedDownload()
helper fetches row, rejects 403 if row.user_id ≠ authenticated user
Correctness:
- SHA-256 verify: stream via createReadStream so multi-GB GGUFs
don't OOM the API process (was readFile() into memory)
- Schema: UNIQUE partial index on (user_id, model_id) for
non-terminal statuses; startDownload() catches 23505 race
- inFlight guard in startDownload() prevents two concurrent
runners writing same .partial when caller rapidly retries
- Persist bytes_downloaded=0 immediately when server ignores Range
- Persist total_bytes when Content-Length differs from registry
approxBytes (added updateTotalBytes repo method)
Frontend:
- Stable data-role selectors (embedded-llm-progress-text /
-status) replace the brittle "labelLine.firstElementChild" walk
that was clobbering action buttons after first poll
- ensureListener() no longer closes over container/userId from
first mount; re-derives both at click time via
getElementById(CARD_TARGET_ID) + getCurrentUserId()
Tests:
- Switched from injecting req.user.id to req.authenticatedUserId
to match production sessionAuth contract
- 7 new cross-user 403 tests covering every mutating endpoint +
dev-bypass-allowed path. Total: 25 tests (was 14), all passing.
Build clean. 486 API tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ff73461 commit 255d446
8 files changed
Lines changed: 319 additions & 49 deletions
File tree
- apps
- api/src
- __tests__
- embedded-llm
- routes
- web/public/js/components
- packages/db/src
- migrations
- repositories
- schemas
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
64 | 117 | | |
65 | 118 | | |
66 | 119 | | |
| |||
Lines changed: 112 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | | - | |
| 65 | + | |
59 | 66 | | |
60 | | - | |
| 67 | + | |
61 | 68 | | |
62 | 69 | | |
63 | 70 | | |
| |||
229 | 236 | | |
230 | 237 | | |
231 | 238 | | |
| 239 | + | |
232 | 240 | | |
233 | 241 | | |
234 | 242 | | |
| |||
241 | 249 | | |
242 | 250 | | |
243 | 251 | | |
| 252 | + | |
244 | 253 | | |
245 | 254 | | |
246 | 255 | | |
| |||
249 | 258 | | |
250 | 259 | | |
251 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
252 | 272 | | |
253 | 273 | | |
254 | 274 | | |
| |||
281 | 301 | | |
282 | 302 | | |
283 | 303 | | |
| 304 | + | |
284 | 305 | | |
285 | 306 | | |
286 | 307 | | |
| |||
290 | 311 | | |
291 | 312 | | |
292 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
293 | 402 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
107 | 129 | | |
108 | 130 | | |
109 | 131 | | |
| |||
118 | 140 | | |
119 | 141 | | |
120 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
121 | 149 | | |
122 | 150 | | |
123 | 151 | | |
| |||
244 | 272 | | |
245 | 273 | | |
246 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
247 | 278 | | |
248 | 279 | | |
249 | 280 | | |
| |||
262 | 293 | | |
263 | 294 | | |
264 | 295 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 296 | + | |
269 | 297 | | |
270 | 298 | | |
271 | 299 | | |
| |||
321 | 349 | | |
322 | 350 | | |
323 | 351 | | |
324 | | - | |
325 | | - | |
326 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
327 | 355 | | |
328 | 356 | | |
329 | 357 | | |
| |||
383 | 411 | | |
384 | 412 | | |
385 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
0 commit comments