fix(security): fail on chmod error in github-auth.sh token persistence (#2375)

Remove `|| true` from chmod call that restricts token file permissions.
If chmod fails, authentication now aborts with an error instead of
silently leaving ~/.config/gh/hosts.yml world-readable.

Fixes #2374

Agent: security-auditor

Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
A 2026-03-09 05:18:07 -07:00 committed by GitHub
parent 882f404bb1
commit f23da1523b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -319,7 +319,10 @@ EOF
return 1
}
# Restrict token file permissions to owner-only (prevents exposure on multi-user systems)
chmod 600 "${HOME}/.config/gh/hosts.yml" 2>/dev/null || true
chmod 600 "${HOME}/.config/gh/hosts.yml" || {
log_error "Failed to restrict token file permissions — aborting to prevent credential exposure"
return 1
}
export GITHUB_TOKEN="${_gh_token}"
elif gh auth status &>/dev/null; then
log_info "Authenticated with GitHub CLI"