Commit 22e4084
committed
Reject dangling and non-absolute paths in AttachedFiles
Two correctness fixes uncovered while reviewing the AttachedFiles plumbing:
1. App.Run was recording att.FilePath on the session before
processFileAttachment had a chance to verify the file existed or
was a regular file. A user typing @some/missing/path or
@some/directory in the editor would silently propagate that
broken reference to every sub-agent created in the rest of the
session.
processFileAttachment now returns a bool meaning "the path resolves
to a real, regular file we attempted to surface" and App.Run only
records on true. Content-handling failures (too large to inline,
unsupported MIME, transient read errors) still record the path
because a sub-agent may have larger limits or different tools than
the parent.
2. AddAttachedFile is documented as taking an absolute path but
accepted any string. A buggy caller could leak a relative path
into the sub-agent's system prompt, where it would be ambiguous.
Add a filepath.IsAbs guard that silently drops non-absolute paths
(with a debug log) and update the doc comment.
Also clarify the Session.AttachedFiles field comment to mention all
three entry points (editor @-mention, /attach directive, --attach CLI
flag) and extend TestAddAttachedFile / TestWithAttachedFiles to cover
the new validation.
Assisted-By: docker-agent1 parent 86641e4 commit 22e4084
3 files changed
Lines changed: 48 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | 305 | | |
310 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
311 | 313 | | |
312 | 314 | | |
313 | 315 | | |
| |||
348 | 350 | | |
349 | 351 | | |
350 | 352 | | |
351 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
352 | 361 | | |
353 | 362 | | |
354 | 363 | | |
| |||
364 | 373 | | |
365 | 374 | | |
366 | 375 | | |
367 | | - | |
| 376 | + | |
368 | 377 | | |
369 | 378 | | |
370 | 379 | | |
371 | 380 | | |
372 | 381 | | |
373 | | - | |
| 382 | + | |
374 | 383 | | |
375 | 384 | | |
376 | 385 | | |
377 | 386 | | |
378 | 387 | | |
379 | 388 | | |
380 | | - | |
| 389 | + | |
381 | 390 | | |
382 | 391 | | |
383 | 392 | | |
| |||
387 | 396 | | |
388 | 397 | | |
389 | 398 | | |
390 | | - | |
| 399 | + | |
391 | 400 | | |
392 | 401 | | |
393 | 402 | | |
394 | 403 | | |
395 | 404 | | |
396 | | - | |
| 405 | + | |
397 | 406 | | |
398 | 407 | | |
399 | 408 | | |
| |||
406 | 415 | | |
407 | 416 | | |
408 | 417 | | |
409 | | - | |
| 418 | + | |
410 | 419 | | |
411 | 420 | | |
412 | 421 | | |
413 | 422 | | |
414 | 423 | | |
415 | 424 | | |
416 | | - | |
| 425 | + | |
417 | 426 | | |
418 | 427 | | |
419 | 428 | | |
| |||
441 | 450 | | |
442 | 451 | | |
443 | 452 | | |
| 453 | + | |
| 454 | + | |
444 | 455 | | |
445 | 456 | | |
446 | 457 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
144 | 146 | | |
145 | 147 | | |
146 | 148 | | |
| |||
489 | 491 | | |
490 | 492 | | |
491 | 493 | | |
492 | | - | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
493 | 499 | | |
494 | 500 | | |
495 | 501 | | |
496 | 502 | | |
497 | 503 | | |
498 | 504 | | |
499 | 505 | | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
500 | 510 | | |
501 | 511 | | |
502 | 512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
| |||
93 | 101 | | |
94 | 102 | | |
95 | 103 | | |
96 | | - | |
| 104 | + | |
97 | 105 | | |
98 | 106 | | |
0 commit comments