Source index · Technical reference · Home

UNRELEASED DEVELOPMENT SNAPSHOT · READ-ONLY EXCERPT

hooks/shared/secret-scan-block/run.sh

This is the cited technical source at local revision 275a354, inspected on 22 September 2026. It differs from the public release. This reference publishes only the cited sections, not an installable release or the development branch.

Line numbers refer to the complete recorded file. Uncited lines are omitted. Full-file SHA-256: 05094fb9eec7ddcd2f6dc623d526bffe1b831fa4105f5493282fb42ed3e644cc.

1#!/usr/bin/env bash
2# secret-scan-block — Lintel JUSTIFIED-BLOCK hook
3# Blocks git commit/push if Tier 1 secret pattern in staged content.
5# NOT `set -e` (issue I1 / claude-code #60490): under -e an upstream grep/tr
6# returning non-zero would exit this script BEFORE the blocking `exit 2`, and
7# Claude Code treats any non-2 exit as NON-blocking — the secret commits through.
8# Explicit exits only (0 = allow, 2 = block); -u/pipefail kept for correctness.
9set -uo pipefail
11source "$(dirname "${BASH_SOURCE[0]}")/../_input.sh"
12CMD="$(hook_input command "${1:-}")"
13[ -z "$CMD" ] && exit 0
15# Match against a FLATTENED copy: a line-continuation newline between `git` and
16# the subcommand defeats a line-oriented grep (silent fail-open), and a newline
… omitted uncited lines …
24# Unified audit writer (hooks/shared/<name>/ → repo-root → bin/). Idempotent source.
25command -v audit_log >/dev/null 2>&1 || source "$(dirname "${BASH_SOURCE[0]}")/../../../bin/_audit.sh"
26# Shared detection patterns (defined once). Block hook → strict `tier1` (high-confidence only).
27source "$(dirname "${BASH_SOURCE[0]}")/../_patterns.sh"
29# Fire on any git commit/push, however the command is phrased: `git commit`,
30# `git -C path commit`, `/usr/bin/git push`, `true && git commit`, `cd x && git
31# commit -am`. The old `^git` anchor was trivially bypassed (security battletest
32# K2). Word-boundary match on both `git` and the subcommand.
33if ! printf '%s' "$CMD_FLAT" | grep -qE '(^|[^A-Za-z0-9_-])git([[:space:]]|$).*\b(commit|push)\b'; then
34 exit 0
35fi
37# Override path — checked BEFORE everything else so an explicit override always
38# audits (battletest H8: the override branch sat after the matcher and an inline
39# `LINTEL_OVERRIDE_SECRET=1 git commit` left no record). Honor either the hook's
40# own env OR the token in the command string the operator typed.
41# Honor the override via the hook's env OR a LEADING env-assignment on the
42# command (`LINTEL_OVERRIDE_SECRET=1 [VAR=v ...] git commit …`) — NEVER the token
43# appearing inside a quoted arg / -m message (review P0: that re-opened a
44# forgeable fail-open). The anchored prefix is what the operator actually types.
45if [ "${LINTEL_OVERRIDE_SECRET:-}" = "1" ] || printf '%s' "$CMD_FLAT" | grep -qE '^[[:space:]]*([A-Za-z_][A-Za-z0-9_]*=[^[:space:]]*[[:space:]]+)*LINTEL_OVERRIDE_SECRET=1([[:space:]]|=|$)'; then
46 reason="${LINTEL_OVERRIDE_REASON:-no-reason-given}"
47 audit_log "hooks" "secret_scan_block" "hook=secret-scan-block" "tier=OVERRIDDEN" "override=true" "reason=$reason" "blocked=false"