SessionStart permission check false-positives on Windows when bash isn't Git-Bash/MSYS
Summary
hooks/scripts/check-setup.sh prints a misleading permission warning on
Windows when the hook happens to run under a bash that isn't Git-Bash/MSYS,
even though the config file's actual Windows ACL is already correctly
locked down.
Environment
- Windows 11
- Git for Windows (MSYS2 bash) installed and used interactively
bashalso resolves to at least two other binaries on PATH:C:\Windows\system32\bash.exeand one under...\AppData\Local\Microsoft\WindowsApps\bash.exe(both legacy WSL launcher shims)
What happened
At session start, the hook printed:
/watch: WARNING — /c/Users/<user>/.config/watch/.env has permissions 644 (should be 600).
Fix: chmod 600 /c/Users/<user>/.config/watch/.envBut the file's real NTFS ACL (checked with icacls) grants access to
exactly one identity — the owning user, Full Control, not inherited:
AzureAD\<user>:(F)No Everyone, Authenticated Users, BUILTIN\Users, or INTERACTIVE —
i.e. nothing the script's own Windows-ACL branch would have flagged. Running
check-setup.sh directly under the Git-Bash MSYS bash produces no
warning at all, confirming the file itself is fine.
Root cause
The script decides which check to run based on uname -s:
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*)
# real icacls-based ACL check
;;
*)
# generic `stat -c '%a'` check — treats the synthetic POSIX bits
# MSYS/WSL report as if they were real Unix permissions
;;
esacThis assumes uname -s reliably identifies "am I on a Windows-flavored
shell." But on Windows, a bare bash invocation can resolve to several
different interpreters depending on the caller's PATH order (Git-Bash/MSYS,
either of the WSL bash.exe launcher stubs, etc.), and not all of them
self-report as MINGW*/MSYS*/CYGWIN* — even when the file being checked
is still an NTFS path governed by a Windows ACL, not real POSIX permission
bits. Whatever spawned this particular hook invocation apparently fell into
the *) branch, so it ran the synthetic-bits stat check instead of the
real ACL check, and reported a false positive.
Suggested fix
Key the branch off whether Windows ACL tooling is actually reachable for
this path (icacls + a resolvable Windows path via cygpath or a
/c/...//mnt/c/... pattern), rather than off uname -s. Fall back to the
POSIX stat check only when ACL tooling isn't available, and only when
uname -s doesn't look Windows-flavored either — otherwise stay silent
rather than print a fix that may not apply.
-# Warn if the secrets file has loose permissions.
-if [[ -f "$CONFIG_FILE" ]]; then
- case "$(uname -s)" in
- MINGW*|MSYS*|CYGWIN*)
- # POSIX bits are synthetic on Windows noacl mounts (chmod is a no-op there);
- # the NTFS ACL is what governs access, so check that instead.
- winpath=$(cygpath -w "$CONFIG_FILE" 2>/dev/null || echo "")
- if [[ -n "$winpath" ]] && command -v icacls >/dev/null 2>&1; then
- if icacls "$winpath" 2>/dev/null | grep -qiE 'Everyone|Authenticated Users|BUILTIN\\Users|INTERACTIVE'; then
- echo "/watch: WARNING — $CONFIG_FILE has a loose NTFS ACL (broad groups have access)."
- echo " Fix: icacls \"$winpath\" /inheritance:r /grant:r \"${USERNAME:-}:F\""
- fi
- fi
- ;;
- *)
- perms=$(stat -c '%a' "$CONFIG_FILE" 2>/dev/null || stat -f '%Lp' "$CONFIG_FILE" 2>/dev/null || echo "")
- if [[ -n "$perms" && "$perms" != "600" && "$perms" != "400" ]]; then
- echo "/watch: WARNING — $CONFIG_FILE has permissions $perms (should be 600)."
- echo " Fix: chmod 600 $CONFIG_FILE"
- fi
- ;;
- esac
-fi
+# Warn if the secrets file has loose permissions.
+#
+# Prefer the real Windows ACL check whenever Windows tooling is reachable,
+# rather than gating on `uname -s` (MINGW*/MSYS*/CYGWIN*). That gate is
+# fragile: on Windows, a bare `bash` can resolve to several different
+# interpreters depending on how the hook is spawned (Git-Bash/MSYS, one of
+# the WSL `bash.exe` launcher shims on PATH, etc.), and not all of them
+# self-report as MINGW/MSYS/CYGWIN even when the file in question is still
+# an NTFS path governed by an ACL, not real POSIX permission bits. Checking
+# for icacls + a resolvable Windows path directly avoids depending on which
+# bash flavor happens to run this script.
+if [[ -f "$CONFIG_FILE" ]]; then
+ winpath=""
+ if command -v cygpath >/dev/null 2>&1; then
+ winpath=$(cygpath -w "$CONFIG_FILE" 2>/dev/null || echo "")
+ elif [[ "$CONFIG_FILE" =~ ^/(mnt/)?([A-Za-z])/(.*)$ ]]; then
+ # Best-effort manual conversion when cygpath isn't on PATH (e.g. some
+ # WSL setups): /c/foo/bar or /mnt/c/foo/bar -> C:\foo\bar
+ drive="${BASH_REMATCH[2]^^}"
+ rest="${BASH_REMATCH[3]//\//\\}"
+ winpath="${drive}:\\${rest}"
+ fi
+
+ if [[ -n "$winpath" ]] && command -v icacls >/dev/null 2>&1; then
+ if icacls "$winpath" 2>/dev/null | grep -qiE 'Everyone|Authenticated Users|BUILTIN\\Users|INTERACTIVE'; then
+ echo "/watch: WARNING — $CONFIG_FILE has a loose NTFS ACL (broad groups have access)."
+ echo " Fix: icacls \"$winpath\" /inheritance:r /grant:r \"${USERNAME:-}:F\""
+ fi
+ else
+ # No Windows ACL tooling reachable — this is either a genuine POSIX
+ # filesystem (Linux/macOS) where stat bits are real, or an unusual
+ # environment we can't verify via ACL. Only warn in the former case;
+ # staying silent beats confidently printing a fix that may not apply.
+ case "$(uname -s 2>/dev/null)" in
+ MINGW*|MSYS*|CYGWIN*) : ;; # Windows shell without icacls on PATH — can't verify, stay silent.
+ *)
+ perms=$(stat -c '%a' "$CONFIG_FILE" 2>/dev/null || stat -f '%Lp' "$CONFIG_FILE" 2>/dev/null || echo "")
+ if [[ -n "$perms" && "$perms" != "600" && "$perms" != "400" ]]; then
+ echo "/watch: WARNING — $CONFIG_FILE has permissions $perms (should be 600)."
+ echo " Fix: chmod 600 $CONFIG_FILE"
+ fi
+ ;;
+ esac
+ fi
+fiTested locally: silent against a real owner-only ACL (icacls shows only
the owning user, Full Control), and confirmed the detection regex still
fires correctly against a sample broad-grant ACL (BUILTIN\Users /
Everyone present). No change in behavior on genuine Linux/macOS, since
icacls simply won't exist there and it falls through to the same stat
check as before.
Happy to open this as a PR instead if preferred.
Source: bradautomates/claude-video