Commit d016ea7
committed
backup: refuse dot-segment scratch paths in HandleBlob (PR #718, round 9)
Codex P1 round 11 (commit 9a63e32):
`HandleBlob` composed scratch paths with `filepath.Join(s.scratchRoot,
EncodeSegment([]byte(bucket)), EncodeSegment([]byte(object)))`.
EncodeSegment uses the RFC3986 unreserved set
(ALPHA/DIGIT/-/./_) — `/` is percent-encoded but `.` is preserved,
so the literal segment `..` survives unchanged. A crafted
`bucket=".."` and/or `object=".."` would resolve to
`<scratchRoot>/../...`, letting `writeFileAtomic` land outside the
decoder's controlled directory before `safeJoinUnderRoot` runs at
output time.
Add `scratchDirForBlob` which rejects `.` / `..` / "" bucket and
object literals at the encoder boundary so the spill-to-disk
step inherits the same containment invariant the final output
path enforces. Apply the same guard to `flushOrphanObject` which
shared the failure mode under `--include-orphans`.
(Multi-segment dot keys like `a/../b` continue to be caught at
Finalize via `safeJoinUnderRoot` because EncodeSegment keeps the
whole key in one filename segment that splits cleanly there.)
Tests:
- TestS3_HandleBlobRejectsScratchEscape: 5 sub-cases covering
bucket/object/both variants of `.`/`..` literals.
- TestS3_DotSegmentObjectKeyRejected updated to allow either
HandleBlob or Finalize to surface ErrS3MalformedKey, since
sole-dot keys are now caught earlier.1 parent 9a63e32 commit d016ea7
2 files changed
Lines changed: 107 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
415 | 423 | | |
416 | 424 | | |
417 | 425 | | |
418 | 426 | | |
419 | 427 | | |
420 | 428 | | |
421 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
422 | 433 | | |
423 | 434 | | |
424 | 435 | | |
| |||
434 | 445 | | |
435 | 446 | | |
436 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
437 | 469 | | |
438 | 470 | | |
439 | 471 | | |
| |||
682 | 714 | | |
683 | 715 | | |
684 | 716 | | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
685 | 721 | | |
686 | 722 | | |
687 | 723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
587 | 621 | | |
588 | 622 | | |
589 | 623 | | |
590 | 624 | | |
591 | 625 | | |
| 626 | + | |
592 | 627 | | |
593 | | - | |
594 | | - | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
595 | 662 | | |
596 | 663 | | |
597 | 664 | | |
| |||
0 commit comments