summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks/sg-python.sh
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-11-09 23:02:58 +0000
committerClaude <noreply@anthropic.com>2026-11-09 23:02:58 +0000
commit2b5afbb5bf7b86c7af0da191cb0c705e18f7a2dc (patch)
treea66e7eb47b0333ea483116d01875008c5b5b0490 /plugins/security-guidance/hooks/sg-python.sh
parent39e36b52c2212b69a1909edbf17806bf48ed0b47 (diff)
Merged candidate for security-guidance 2.0.19 with the launcher probe changemhegazy/sg2019batch
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.sh7
1 files changed, 5 insertions, 2 deletions
diff --git a/plugins/security-guidance/hooks/sg-python.sh b/plugins/security-guidance/hooks/sg-python.sh
index b1a5d5b9..f2d5bd8a 100755
--- a/plugins/security-guidance/hooks/sg-python.sh
+++ b/plugins/security-guidance/hooks/sg-python.sh
@@ -105,7 +105,10 @@ probe() {
# Only for `$(probe ...)`: the `exec` replaces that subshell instead of
# forking a second process from it.
[ "${BASH_SUBSHELL:-0}" -gt 0 ] || return 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
+ # 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
}
# Use as `ask ... || { note_unreadable "<name>"; continue; }` (see ask below).
@@ -409,7 +412,7 @@ done
for cmd in "python3" "python" "py -3"; do
case "$sg_unreadable" in *"|$cmd|"*) ;; *) continue ;; esac
# shellcheck disable=SC2086
- c=$($cmd -c 'import sys; print(sys.executable)' 2>/dev/null) || continue
+ c=$(PYTHONSAFEPATH=1 $cmd -c 'import sys; print(sys.executable)' 2>/dev/null) || continue
c=${c%$'\r'} # native Windows Python prints CRLF
[ -n "$c" ] || continue
if command -v cygpath >/dev/null 2>&1; then