Repository navigation
Commit 8bebd8b
Rewrite Git.execute() command parameter docstring
gitpython-developers#2146 identifies two issues with gitpython-developers#2144's :param command: rewrite,
which this fixes by reworking the block as four paragraphs:
1. Description: a sequence of program arguments is recommended; a
string is also accepted, but its meaning is strongly
platform-dependent.
2. Platform-specific string handling. By default, a shell is not
used. On Unix-like systems the whole string is the program name
(so multi-word strings raise GitCommandNotFound); on Windows the
OS parses the string itself, so multi-word strings can work but
are not portable. This corrects gitpython-developers#2144's claim that with
shell=False the string "is passed as a single executable name to
subprocess.Popen" -- accurate on Unix-like systems, but on
Windows subprocess.Popen forwards the string to CreateProcessW
and Windows command-line parsing produces argv.
3. shell=True / Git.USE_SHELL warning. The shell interprets
metacharacters such as ;, |, &, $(...) (on POSIX), and ^ (on
Windows) as syntax; untrusted text in the command can then
execute arbitrary OS commands. Cross-references USE_SHELL for
the long-form discussion (which has the attack examples and
history).
4. shlex.split caveat. Producing a sequence automatically via
shlex.split is far safer than shell=True (so gitpython-developers#2144's
harm-reduction note is preserved), but qualified: shlex.split
parses POSIX shell syntax on all systems and the result is
still unsafe for anything but fixed, fully trusted strings.
Calls out the f-string-then-shlex.split anti-pattern explicitly
-- whitespace or quoting in an untrusted interpolated value can
still inject arguments. For input derived in any way from
untrusted data, build the argument sequence yourself, while
ensuring each argument is fully sanitized.
Add a related paragraph to :param shell: noting that, on Unix-like
systems, shlex.split may serve in rare cases as a transitional
step when migrating existing string-command shell=True calls, with
extreme care, and cross-referencing :param command: for the risks.
Removes gitpython-developers#2144's hedged "possible security implications" wording
and its implicit recommendation of shlex.split as a general
string-to-argv splitter, in favor of named mechanisms and a
narrow, qualified mention. Documentation only; behavior is
unchanged.
For gitpython-developers#2146.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7b83f7a commit 8bebd8b
1 file changed
Lines changed: 27 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 | + | |
1144 | 1156 | | |
1145 | 1157 | | |
1146 | 1158 | | |
| |||
1208 | 1220 | | |
1209 | 1221 | | |
1210 | 1222 | | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
1211 | 1228 | | |
1212 | 1229 | | |
1213 | 1230 | | |
| |||
0 commit comments