Repository navigation
Commit 447c8bf
committed
fix(submodule): apply git's transport policy to
`Submodule.update` clones a submodule from the URL recorded in
`.gitmodules`, and fetches the remotes of an initialized submodule, with
the transport policy git applies to a URL the user typed. Since git
2.38.1 (CVE-2022-39253) `protocol.file.allow` defaults to `user`, and
`git submodule update` runs its clones and fetches with
`GIT_PROTOCOL_FROM_USER=0`, so git refuses the `file` transport for a
URL that comes from `.gitmodules` unless `protocol.file.allow=always` is
configured. GitPython did not set that variable, so a `.gitmodules` like
[submodule "module"]
path = module
url = /path/on/the/victims/machine
made `Repo.submodule_update(init=True)` and `Submodule.update(init=True)`
clone that local repository into the checkout, and `RootModule.update`
fetch from such a URL when a new commit changed it, while
`git submodule update --init` fails with `fatal: transport 'file' not
allowed`. Whoever authored the superproject controls `.gitmodules`, so a
tool that updates the submodules of repositories it is given copied a
local repository of the author's choosing through git's local clone
path, which hardlinks objects and skips the fsck checks a transport
fetch applies.
`Submodule.update` now runs the clone and the fetch of every remote with
`GIT_PROTOCOL_FROM_USER=0`, and `RootModule.update` does the same for
the fetch from a changed URL. Git then applies its own policy: `http`,
`https`, `git` and `ssh` are unaffected, while `file` and any other
protocol whose `protocol.<name>.allow` is `user` is refused unless
`always` is configured, the same opt-in `git submodule update` honors.
`allow_unsafe_protocols=True` on `Submodule.update` keeps treating the
URL as the caller's, and a `GIT_PROTOCOL_FROM_USER` value in the `env`
passed to `update` still wins. `Submodule.add` is unchanged because its
URL is supplied by the caller.
The tests that update submodules from local repositories now set
`protocol.file.allow=always`, as the ones that call `git submodule add`
already did; the helper for that moved from `test/test_submodule.py` to
`test/lib/helper.py` as `patch_git_config` because
`test/test_submodule_no_fetch.py` and `test/test_docs.py` need it too.
Adds `test_update_applies_git_transport_policy_to_gitmodules_url` and
`test_root_update_applies_git_transport_policy_to_changed_url` in
`test/test_submodule.py`, which fail before this change and pass after.
`ruff check`, `ruff format --check` and `mypy` pass. The pytest suite
passes except for eight tests that fail the same way without this
change in a clone not prepared with `init-tests-after-clone.sh`..gitmodules URLs1 parent ccc4811 commit 447c8bf
6 files changed
Lines changed: 131 additions & 37 deletions
File tree
- git/objects/submodule
- test
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
364 | 379 | | |
365 | 380 | | |
366 | 381 | | |
| |||
849 | 864 | | |
850 | 865 | | |
851 | 866 | | |
852 | | - | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
853 | 871 | | |
854 | 872 | | |
855 | 873 | | |
| |||
900 | 918 | | |
901 | 919 | | |
902 | 920 | | |
903 | | - | |
| 921 | + | |
| 922 | + | |
904 | 923 | | |
905 | 924 | | |
906 | 925 | | |
| |||
987 | 1006 | | |
988 | 1007 | | |
989 | 1008 | | |
990 | | - | |
| 1009 | + | |
991 | 1010 | | |
992 | 1011 | | |
993 | 1012 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
| 309 | + | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
87 | 109 | | |
88 | 110 | | |
89 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| 482 | + | |
482 | 483 | | |
483 | 484 | | |
484 | 485 | | |
| |||
0 commit comments