Commit 5f542b7
committed
Refuse to extract symbolic links in archives that point outside the course directory.
Currently when extracting zip or tar archives in the file manager, any
symbolic link in the archive is extracted assuming the link itself is in
the course directory. That is a security vulnerability as a link could
point to something like `/etc` and give unsecure access to system files.
So this refuses to extract symbolic links in archives that point outside
the course directory. The way that this works is it actually does create
the links, but then it prunes any links that point outside the course
directory. This is so that `realpath` can be used, and is the only way
to properly validate the links. Naively attempting to collapse `..`
instances in the path does not work reliably (see the note for the
`canonpath` method at https://metacpan.org/pod/File::Spec::Unix), and I
was able to subvert that to achieve a functional link to outside of the
course directory. Note that broken symbolic links must also be
rejected. This is because `realpath` does not work for these, and so
there is no way to validate them as being links that point inside the
course directory. In fact, it is possible to devise a broken symbolic
link that combined with a valid symbolic link in another archive file,
becomes a link to a location outside of the course directory (and I did
so in testing).
Note this means that the only symbolic links allowed in a course are the
required symbolic links (`Library`, `Contrib`, and `Student_Orientation`
at this point), and those that are created by a system administrator.
Also note that symbolic links in a course archive are still restored as
before when unarchiving a course. It is considered the responsibility
of the system administrator to validate links in a course archive.
This fixes the last of the security vulnerabilities that @Alex-Jordan
found. Note that this was initially coded by Claude, but I largely
rewrote what Claude created.1 parent 65e11c7 commit 5f542b7
1 file changed
Lines changed: 55 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
499 | 514 | | |
500 | 515 | | |
501 | 516 | | |
| |||
511 | 526 | | |
512 | 527 | | |
513 | 528 | | |
514 | | - | |
| 529 | + | |
515 | 530 | | |
516 | 531 | | |
517 | 532 | | |
| |||
526 | 541 | | |
527 | 542 | | |
528 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
529 | 548 | | |
530 | 549 | | |
531 | 550 | | |
| |||
546 | 565 | | |
547 | 566 | | |
548 | 567 | | |
549 | | - | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
550 | 573 | | |
551 | 574 | | |
552 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
553 | 581 | | |
554 | 582 | | |
555 | 583 | | |
| |||
561 | 589 | | |
562 | 590 | | |
563 | 591 | | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
564 | 596 | | |
565 | 597 | | |
566 | 598 | | |
| |||
584 | 616 | | |
585 | 617 | | |
586 | 618 | | |
587 | | - | |
588 | | - | |
| 619 | + | |
589 | 620 | | |
590 | 621 | | |
591 | 622 | | |
592 | 623 | | |
| 624 | + | |
593 | 625 | | |
594 | 626 | | |
595 | 627 | | |
596 | 628 | | |
597 | 629 | | |
598 | 630 | | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
599 | 636 | | |
600 | 637 | | |
601 | 638 | | |
| |||
629 | 666 | | |
630 | 667 | | |
631 | 668 | | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
632 | 683 | | |
633 | 684 | | |
634 | 685 | | |
| |||
0 commit comments