Commit 4fe9966
Refactor Git.execute() command docstring after gitpython-developers#2144
Rework :param command: as four parts:
1. Brief parameter description, with a recommendation to pass a
sequence and a platform-dependent note on string handling: on
POSIX a string is the program name, on Windows the OS splits it
into argv. Corrects gitpython-developers#2144's claim that with shell=False the
string is "passed as a single executable name to
subprocess.Popen" -- accurate on POSIX, but on Windows
subprocess.Popen forwards the string to CreateProcessW, which
tokenizes via Windows command-line parsing.
2. shell=True (or Git.USE_SHELL) explanation: it sends the command
to the platform shell rather than executing it directly, and
the shell interprets ;, |, &, $(...), etc. as syntax. With
untrusted text in the command -- paths, branch names, URLs,
etc. -- this is arbitrary OS command execution. Cross-references
Git.USE_SHELL for the long-form discussion.
3. shlex.split explanation: runs no shell, so the
command-injection risk does not apply, but its POSIX shell
rules on Windows match neither the shell=False OS argv parsing
nor the shell=True cmd.exe parsing. Untrusted whitespace or
quoting can therefore shift token boundaries, injecting extra
arguments into git's option parser.
4. Asymmetric conclusion: build the sequence form directly;
shell=True is the more dangerous route (arbitrary command
execution), but no automatic-splitting route is safe with
untrusted input.
Replaces gitpython-developers#2144's hedged "possible security implications" wording
with named mechanisms; preserves the asymmetry between command
injection (shell=True) and argument injection (shlex.split on
Windows). No worked examples (verbosity); the existing USE_SHELL
docstring carries the full attack discussion. Documentation only;
behavior is unchanged.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7b83f7a commit 4fe9966
1 file changed
Lines changed: 24 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1131 | 1131 | | |
1132 | 1132 | | |
1133 | 1133 | | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
1144 | 1158 | | |
1145 | 1159 | | |
1146 | 1160 | | |
| |||
0 commit comments