Repository navigation
Commit 6c4cd6a
committed
fix(util): redact URL credentials in config values on the command line
`remove_password_if_present` is applied to every command line that
GitPython logs or stores in `GitCommandError` and the other
`CommandError` subclasses. It redacted an argument only when the whole
argument was a URL with userinfo, or when it was an
`http.extraHeader=Authorization: ...` assignment. Two common forms were
missed:
- A URL that is the value of a configuration assignment, such as
`-c http.proxy=http://user:pass@proxy:3128` or
`-c remote.origin.url=https://user:token@host/repo`. The text before
`://` contains `=`, so `urlsplit` finds no scheme and no userinfo, and
the argument was kept verbatim.
- The `--config=<key>=<value>` form, which is what `transform_kwargs`
produces for a `config=...` keyword argument. The leading `--config=`
defeated both checks, so even
`--config=http.extraHeader=Authorization: Bearer <token>` was printed
in full.
For example, after
`repo.git.set_persistent_git_options(c="http.proxy=http://user:secret@proxy:3128")`
every failing command raised a `GitCommandError` whose message contained
`user:secret`, and the same text reached the log when command tracing is
on.
The URL redaction moves into a small `_redact_url_credentials` helper.
`remove_password_if_present` strips a leading `--config=` before the
extra header check, and when the whole argument is not a URL with
userinfo it tries the assignment after `--config=` (which covers
`url.<base>.insteadOf` keys that carry credentials) and then the value
after the first `=`. Only the userinfo is replaced, so the key and the
rest of the URL stay readable, and arguments without a URL are returned
unchanged. Arguments that were already redacted produce the same output
as before.
Adds `test_remove_password_from_config_values` to `test/test_util.py`.
Its five redaction cases fail before this change and pass after it, and
the existing redaction tests still pass. `ruff check`, `ruff format
--check` and `mypy` are clean.1 parent 9d3aff0 commit 6c4cd6a
2 files changed
Lines changed: 65 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
655 | 672 | | |
656 | 673 | | |
657 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
658 | 679 | | |
659 | 680 | | |
660 | 681 | | |
661 | 682 | | |
662 | 683 | | |
663 | 684 | | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
668 | 690 | | |
669 | 691 | | |
670 | 692 | | |
671 | 693 | | |
672 | 694 | | |
673 | 695 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
| 696 | + | |
690 | 697 | | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
691 | 709 | | |
692 | 710 | | |
693 | 711 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
856 | 856 | | |
857 | 857 | | |
858 | 858 | | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
859 | 886 | | |
860 | 887 | | |
861 | 888 | | |
| |||
0 commit comments