@torus-engineering/tas-kit 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ # TAS Kit — Pre-commit Security Hook
2
+
3
+ Fast, deterministic scan of staged files on every `git commit`. Blocks commits
4
+ that contain hardcoded secrets, private keys, `.env` files, or (optionally)
5
+ findings from a deeper AI-powered audit.
6
+
7
+ ## Files
8
+
9
+ | File | Role |
10
+ |---|---|
11
+ | `security-scan.js` | Vanilla Node scanner. No runtime deps. Reads `tas.yaml` for config. |
12
+ | `pre-commit` | Shell wrapper invoked by git. Calls the scanner via `node`. |
13
+ | `README.md` | This file. |
14
+
15
+ ## How it gets wired
16
+
17
+ The installer offers two modes during `npx @torus-engineering/tas-kit install`:
18
+
19
+ ### 1. Husky mode (recommended for Node/TS projects)
20
+
21
+ Adds `husky` to devDependencies, sets a `"prepare": "husky"` script, and creates
22
+ `.husky/pre-commit` that sources `.tas/hooks/pre-commit`. The hook is shared
23
+ across the team via git — anyone cloning the repo gets it after `npm install`.
24
+
25
+ ### 2. Native mode (works for any stack)
26
+
27
+ Copies `.tas/hooks/pre-commit` directly into `.git/hooks/pre-commit` (and
28
+ `chmod +x` on Unix). Local to each clone — each teammate has to re-run the
29
+ installer or copy the hook themselves. Zero Node dependency added.
30
+
31
+ ### 3. Skip
32
+
33
+ No hook wiring. You can always run `/tas-security --staged` manually, or wire
34
+ it later by re-running the installer.
35
+
36
+ ## 3-Tier Scan
37
+
38
+ | Tier | When | What runs | Blocks? | Cost |
39
+ |---|---|---|---|---|
40
+ | 1 | Always | Built-in regex on staged files (~45 secret patterns) | Yes, if severity ∈ `block_on` | < 1s |
41
+ | 2 | If tool on PATH | `gitleaks` or `trufflehog` — community-maintained rules | Yes, if severity ∈ `block_on` | 2–10s |
42
+ | 3 | Opt-in, **local only** | AI deep scan via `claude` / `codex` / `gemini`, writes `docs/security-report.md` | **No — report-only** | 15–60s |
43
+
44
+ **Tier 1 & 2** are the hard gate — they stop obvious credential leaks on every
45
+ commit.
46
+
47
+ **Tier 3** is optional and local-only. It's designed for devs who want a
48
+ second-opinion AI review before pushing. Uses your personal Claude Code (or
49
+ Codex / Gemini) subscription — no per-call API charges because quota resets
50
+ on a rolling window. Output goes to `docs/security-report.md`; if you want
51
+ reviewers to see it, `git add` it into your commit. This tier is deliberately
52
+ NOT wired into CI — running it there would burn paid API tokens, and PR
53
+ review already gives humans a chance to catch issues.
54
+
55
+ ## Config (in `tas.yaml`)
56
+
57
+ ```yaml
58
+ security:
59
+ pre_commit_hook: true # false → disable hook without uninstalling
60
+ external_scanner: auto # auto | gitleaks | trufflehog | none — tier 2
61
+ tool: claude # claude | codex | gemini | none — tier 3 AI
62
+ deep_scan_on_every_commit: false
63
+ block_on: [critical, high]
64
+ allow_bypass: true
65
+ ```
66
+
67
+ - **pre_commit_hook** — master switch. `false` → scanner exits early.
68
+ - **external_scanner** — tier 2 control.
69
+ - `auto` (default) → try `gitleaks` first, then `trufflehog`. Silent skip if
70
+ neither is on PATH. Zero cost when not installed.
71
+ - `gitleaks` / `trufflehog` → force that specific tool; warn if missing.
72
+ - `none` → disable tier 2 entirely.
73
+ - **tool** — tier 3 AI CLI. Must be on `PATH` when deep scan is triggered.
74
+ - **deep_scan_on_every_commit** — `false` = skip tier 3 locally (default).
75
+ `true` = also invoke `tool` on the staged diff every commit (slow).
76
+ - **block_on** — severities that cause exit code 1. Medium/Low always pass.
77
+ - **allow_bypass** — cosmetic: when `true`, scanner prints bypass hints.
78
+ Git always honors `--no-verify` regardless.
79
+
80
+ ## Installing tier 2 scanners (optional)
81
+
82
+ **gitleaks** — fastest, purpose-built for pre-commit:
83
+ - Windows: `scoop install gitleaks` or download binary from releases
84
+ - macOS: `brew install gitleaks`
85
+ - Linux: `brew install gitleaks` or apt/download
86
+
87
+ **trufflehog** — slower but can verify secrets against live APIs:
88
+ - Windows: `scoop install trufflehog`
89
+ - macOS: `brew install trufflehog`
90
+ - Linux: `curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin`
91
+
92
+ No action needed if you don't want tier 2 — the hook silently skips it.
93
+
94
+ ## Behavior on CI
95
+
96
+ If `CI=true` (or `CI=1`) is in the environment, the scanner force-enables
97
+ deep scan regardless of `deep_scan_on_every_commit`. This lets CI gates run
98
+ the full AI audit even when local commits stay fast.
99
+
100
+ ## Bypass
101
+
102
+ ```
103
+ SKIP_SECURITY_SCAN=1 git commit -m "..."
104
+ git commit --no-verify -m "..."
105
+ ```
106
+
107
+ Document the reason in the commit body when bypassing.
108
+
109
+ ## What the fast scan catches
110
+
111
+ - AWS access keys (`AKIA...`)
112
+ - GitHub / Slack / Google API tokens
113
+ - Private keys (RSA, OpenSSH, EC, DSA, PGP)
114
+ - Hardcoded secrets: `api_key|secret|password|token = "..."` patterns
115
+ - JWTs embedded in source
116
+ - DB connection strings with credentials
117
+ - `.env` files staged (except `.env.example` / `.sample` / `.template`)
118
+
119
+ Binary files, large files (>2MB), and common asset extensions are skipped.
120
+
121
+ ## What deep scan catches (when enabled)
122
+
123
+ OWASP Top 10, injection, authz flaws, unsafe deserialization — whatever the
124
+ configured AI CLI reports. Output must follow the grep-friendly format:
125
+
126
+ ```
127
+ <SEVERITY> | <file:line> | <description>
128
+ ```
129
+
130
+ Anything not in that format is ignored. If the tool reports `NO FINDINGS`,
131
+ scan passes.
132
+
133
+ ## Extending
134
+
135
+ - **Add a pattern:** edit `PATTERNS` array in `security-scan.js`.
136
+ - **Change tool invocation:** edit the `tools` map (bin + args).
137
+ - **Report findings to `docs/security-report.md`:** not done by default.
138
+ Use `/tas-security` command for a proper run that writes the report.
@@ -0,0 +1,26 @@
1
+ #!/bin/sh
2
+ # TAS Kit — pre-commit security hook
3
+ #
4
+ # Invoked by either:
5
+ # - husky (.husky/pre-commit sources this file), or
6
+ # - native git hook (.git/hooks/pre-commit is a copy of this file)
7
+ #
8
+ # Delegates to .tas/hooks/security-scan.js. Exits 0 if ok, 1 to block commit.
9
+
10
+ if ! command -v node >/dev/null 2>&1; then
11
+ echo "[TAS Security] node not found on PATH — skipping scan" >&2
12
+ exit 0
13
+ fi
14
+
15
+ REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"
16
+ if [ -z "$REPO_ROOT" ]; then
17
+ exit 0
18
+ fi
19
+
20
+ SCANNER="$REPO_ROOT/.tas/hooks/security-scan.js"
21
+ if [ ! -f "$SCANNER" ]; then
22
+ echo "[TAS Security] Scanner not found at $SCANNER — did you run 'npx @torus-engineering/tas-kit install'?" >&2
23
+ exit 0
24
+ fi
25
+
26
+ exec node "$SCANNER"