summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks/sg-python.sh
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-11-19 19:33:41 +0000
committerClaude <noreply@anthropic.com>2026-11-19 19:34:17 +0000
commit4fa3475d3a7f58ffe75930c6aa8ae56e80496447 (patch)
treea69575a4cb65dd84cc77030a7a862d04ad58bf20 /plugins/security-guidance/hooks/sg-python.sh
parentdf9699a55c56707e9948a32951ea356638ea8519 (diff)
security-guidance: keep the interpreter check working through a .bat shimmhegazy/sg-pyenv-win-probe
pyenv-win's python names end in a batch file. In its released version (3.1.1) cmd.exe read the ">=" in the check as a redirect: every hook left an empty "(3" file in the project, and the interpreter was rejected. With no other Python no hook ran. The check now uses only characters that arrive unchanged. On Windows a name that loses the argument counts as unable to read the hook script, so the launcher goes on to its real interpreter. See #7172. Co-authored-by: mhegazy <mhegazy@anthropic.com>
Diffstat (limited to 'plugins/security-guidance/hooks/sg-python.sh')
-rwxr-xr-xplugins/security-guidance/hooks/sg-python.sh8
1 files changed, 7 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/sg-python.sh b/plugins/security-guidance/hooks/sg-python.sh
index 74927965..a5aa62a0 100755
--- a/plugins/security-guidance/hooks/sg-python.sh
+++ b/plugins/security-guidance/hooks/sg-python.sh
@@ -107,7 +107,12 @@ probe() {
# PYTHONSAFEPATH (3.11+, ignored before): the probe needs the standard
# library only, so Python is told not to add its usual first entry to the
# import path. For this call alone; the hook's environment is unchanged.
- PYTHONSAFEPATH=1 exec "$@" -c 'import os, sys; t = (sys.argv[1:] or [""])[0]; sys.exit(3) if t and not (os.path.isfile(t) and os.access(t, os.R_OK)) else print(f"{sys.version_info[0]}.{sys.version_info[1]}"); sys.platform == "win32" and sys.version_info >= (3, 10) and print(sys.executable)' "$SG_TARGET" 2>/dev/null
+ #
+ # The code can reach cmd.exe through a .bat shim (pyenv-win), so it is one
+ # line of characters that arrive unchanged: a ">=" was read as a redirect
+ # and left a stray file. See #7172. On Windows a name that loses the
+ # argument also exits 3, so that pass 4 can start its real interpreter.
+ PYTHONSAFEPATH=1 exec "$@" -c 'import os, sys; t = (sys.argv[1:] or [""])[0]; sys.exit(3) if sys.platform == "win32" and not sys.argv[1:] or t and not (os.path.isfile(t) and os.access(t, os.R_OK)) else print(f"{sys.version_info[0]}.{sys.version_info[1]}"); sys.platform == "win32" and sys.version_info.__ge__((3, 10)) and print(sys.executable)' "$SG_TARGET" 2>/dev/null
}
# Use as `ask ... || { note_unreadable "<name>"; continue; }` (see ask below).
@@ -449,6 +454,7 @@ EOF
done
for cmd in "python3" "python" "py -3"; do
case "$sg_unreadable" in *"|$cmd|"*) ;; *) continue ;; esac
+ # The same limits on the code as in probe.
# shellcheck disable=SC2086
c=$(PYTHONSAFEPATH=1 $cmd -c 'import sys; print(sys.executable)' 2>/dev/null) || continue
c=${c%$'\r'} # native Windows Python prints CRLF