diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1db4374..ae1e709 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -42,7 +42,7 @@ jobs: check-latest: false - name: initialize - uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9 + uses: github/codeql-action/init@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0 with: languages: go queries: security-and-quality @@ -52,6 +52,6 @@ jobs: run: go build ./... - name: analyze - uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9 + uses: github/codeql-action/analyze@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0 with: category: '/language:go' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 106e467..ad43f0f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,7 +42,7 @@ jobs: # .github/action-allowlist.txt for the scoping rationale. Never # blocking — this is observation, not enforcement. - name: Harden Runner - uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 + uses: step-security/harden-runner@dc2769abcc0fcfbadfc1df54081c1608579ef6b2 # v2.22.2 with: egress-policy: audit diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index c687156..581ead4 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -42,7 +42,7 @@ jobs: persist-credentials: false - name: run scorecard - uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4 + uses: ossf/scorecard-action@fa7117db83c52d787ae5a89f350999701505d78e # v2.5.0 with: results_file: results.sarif results_format: sarif @@ -54,6 +54,6 @@ jobs: publish_results: true - name: upload SARIF - uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9 + uses: github/codeql-action/upload-sarif@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0 with: sarif_file: results.sarif diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e2a357..1e2eeed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,38 @@ hardening pass done ahead of open-sourcing — is preserved in ## [Unreleased] +## [0.1.2] — 2026-10-27 + ### Security -- **Go toolchain bumped to 1.26.9** for GO-2026-6617 (HTTP/2 server crash - from an HPACK encoder race in `net/http`, fixed in 1.26.9). +- **Go toolchain bumped to 1.26.10** for GO-2026-6809 (`crypto/x509`, + reachable from ctxcop's code, fixed in 1.26.10) and GO-2026-6617 (HTTP/2 + server crash from an HPACK encoder race in `net/http`, fixed in 1.26.9). +- **Vulnerable indirect dependencies bumped.** govulncheck found none of + these reachable from ctxcop's code; they're patched anyway: + `github.com/google/cel-go` v0.30.0 (GO-2026-6094), `golang.org/x/text` + v0.41.0 (GO-2026-5970, GO-2026-6629), `github.com/klauspost/compress` + v1.18.7 (GO-2026-5841), and `golang.org/x/crypto` v0.56.0 (GO-2026-6303, + GO-2026-6354, GO-2026-6355). GO-2026-5932 (the unmaintained + `x/crypto/openpgp` package) has no fixed version; ctxcop doesn't import it. + +### Added +- **Redis AUTH detection: four embedded rules covering the leak shapes + upstream has no answer for.** A bare Redis password has no token prefix + and no key=value shape — the two forms gitleaks-class rules detect — so + the plain AUTH command line as error logs show it, the node-redis + structured error form (args array and JSON), redis-cli `-a`/`--pass` + invocations, and RESP protocol dumps (raw CRLF, escaped, space-flattened) + all passed through unredacted. Rules are ported rule-for-rule from + [webflow/secrets-scrubber](https://github.com/webflow/secrets-scrubber) + (Santiago Moreno), whose project was built around a real Redis key leak + into an AI session; RE2 forbids its JS lookaheads, so its + reference-value heuristic became a per-rule CEL filter. Every rule + carries a minimum-length floor (16 for plain AUTH, 8 elsewhere) — a + sub-8-char finding trips Splice's over-redact backstop against + unrelated lines carrying the same short form. Port deviation: the RESP + rule requires the `*N` array header (all of secrets-scrubber's RESP + fixtures carry it) so prose dollar-amounts near the word auth do not + redact. ### Fixed - **Hooks drain stdin before exiting.** A paused hook (or one with an off @@ -99,4 +128,6 @@ ctxcop's first public release. - Full line-by-line detail, including issue references, is in the [pre-1.0 dev log](docs/dev-log/CHANGELOG-pre-1.0.md). +[0.1.2]: https://github.com/webflow/ctxcop/releases/tag/v0.1.2 +[0.1.1]: https://github.com/webflow/ctxcop/releases/tag/v0.1.1 [0.1.0]: https://github.com/webflow/ctxcop/releases/tag/v0.1.0 diff --git a/THREATMODEL.md b/THREATMODEL.md index dc0a430..f65c305 100644 --- a/THREATMODEL.md +++ b/THREATMODEL.md @@ -213,6 +213,16 @@ the approach, not bugs: shaped to evade the ruleset are not in scope — ctxcop assumes the agent and tools are not actively cooperating in exfiltration. +- **Bare Redis AUTH residuals.** The embedded redis-auth rules cover + the common leak shapes (plain AUTH lines, node-redis structured + errors, RESP dumps, redis-cli flags; ported from + webflow/secrets-scrubber) but keep their floors and framing + requirements: shorter passwords, RESP dumps with an empty + (`$0`-bulk) ACL username, and any RESP command other than AUTH pass + through. Floors exist because a sub-8-char finding trips Splice's + over-redact backstop against unrelated lines carrying the same + short form. + ## Out of scope These are documented non-goals, listed so it's clear what *not* to diff --git a/docs/detection.md b/docs/detection.md index 67f9a01..ba9d86d 100644 --- a/docs/detection.md +++ b/docs/detection.md @@ -9,7 +9,7 @@ what every hook scans. built-in recursive codec decoding (base64/hex/percent/unicode) so secrets that were encoded before they reached the tool output are still caught. -2. **ctxcop embedded pack** — eight high-confidence single-purpose +2. **ctxcop embedded pack** — twelve high-confidence single-purpose patterns shipped in the binary. Same shape as gitleaks rules but tuned for the CLI-output threat model: where gitleaks requires a `\b` boundary (so credentials glued to surrounding text by tools @@ -27,6 +27,19 @@ what every hook scans. | `ctxcop-gitlab-pat` | `glpat-` | | `ctxcop-slack-token` | `xox[bpoars]-` | | `ctxcop-stripe-secret-key` | `(sk\|rk)_(live\|test)_` | + | `ctxcop-redis-auth-command` | bare `AUTH [user] ` command lines (16+, upper/digit gate) | + | `ctxcop-redis-auth-array` | `AUTH` in quoted args arrays / JSON (node-redis error form) | + | `ctxcop-redis-auth-resp` | `AUTH` in RESP protocol dumps (raw / escaped / flattened CRLF) | + | `ctxcop-redis-auth-cli` | `redis-cli` `-a` / `--pass` flag arguments | + + The redis-auth rules close a structural gap in the upstream ruleset: + a bare Redis password has no token prefix and no key=value shape, the + two forms gitleaks-class rules detect. Ported from + [webflow/secrets-scrubber](https://github.com/webflow/secrets-scrubber) + (rule-for-rule from its four redis-auth rules; RE2 forbids its JS + lookaheads, so its reference-value heuristic became the per-rule CEL + filter). Redaction span is the whole match: the AUTH verb, RESP + framing, and ACL username vanish with the password. 3. **`~/.ctxcop/*.toml`** — every `.toml` file in the user rules dir, loaded in alphabetical order. Drop org-specific credential patterns diff --git a/go.mod b/go.mod index ca98e6f..def7cdf 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/webflow/ctxcop -go 1.26.9 +go 1.26.10 require ( github.com/BurntSushi/toml v1.6.0 github.com/betterleaks/betterleaks v1.2.0 github.com/spf13/viper v1.21.0 go.yaml.in/yaml/v3 v3.0.5 - golang.org/x/sys v0.47.0 + golang.org/x/sys v0.49.0 ) require ( @@ -28,14 +28,14 @@ require ( github.com/gitleaks/go-gitdiff v0.9.1 // indirect github.com/go-sprout/sprout v1.0.3 // indirect github.com/go-viper/mapstructure/v2 v2.4.0 // indirect - github.com/google/cel-go v0.29.0 // indirect + github.com/google/cel-go v0.30.0 // indirect github.com/google/go-github/v72 v72.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/h2non/filetype v1.1.3 // indirect github.com/hashicorp/go-version v1.7.0 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect - github.com/klauspost/compress v1.18.4 // indirect + github.com/klauspost/compress v1.18.7 // indirect github.com/klauspost/pgzip v1.2.6 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -60,10 +60,10 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect github.com/ulikunitz/xz v0.5.15 // indirect go4.org v0.0.0-20260112195520-a5071408f32f // indirect - golang.org/x/crypto v0.52.0 // indirect + golang.org/x/crypto v0.56.0 // indirect golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect - golang.org/x/sync v0.20.0 // indirect - golang.org/x/text v0.37.0 // indirect + golang.org/x/sync v0.22.0 // indirect + golang.org/x/text v0.41.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect google.golang.org/protobuf v1.36.11 // indirect diff --git a/go.sum b/go.sum index a63c19f..0c46932 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/go-sprout/sprout v1.0.3/go.mod h1:cFFzpnyGGry3cmN0UNCAM1f7AGok6vPVabe github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/google/cel-go v0.29.0 h1:fEG+Ja3YRwNOqnQxTyJwoByAUAvTuxUGiro/jhrm4F4= -github.com/google/cel-go v0.29.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8= +github.com/google/cel-go v0.30.0 h1:ll54AkzKunWkBn9wSoiUXbFZXYZTkdJGNXTBXUoolGo= +github.com/google/cel-go v0.30.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -64,8 +64,8 @@ github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c= -github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4= +github.com/klauspost/compress v1.18.7 h1:aUyZsS4kH3QTKurYhAOwAHxllVPnOthb3vPfnF1Ehjw= +github.com/klauspost/compress v1.18.7/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU= github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= @@ -146,21 +146,21 @@ go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= go4.org v0.0.0-20260112195520-a5071408f32f h1:ziUVAjmTPwQMBmYR1tbdRFJPtTcQUI12fH9QQjfb0Sw= go4.org v0.0.0-20260112195520-a5071408f32f/go.mod h1:ZRJnO5ZI4zAwMFp+dS1+V6J6MSyAowhRqAE+DPa1Xp0= -golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988= -golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc= +golang.org/x/crypto v0.56.0 h1:GUh5Ii4J5jtcseSMiRqr1jXCNHoxjeV9Fmekc2oLy6Y= +golang.org/x/crypto v0.56.0/go.mod h1:OMW5y6CY9l38uPLmxU6l6pwcXp1obtLo3e6gT7gQR2I= golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrCPyJZ+eyRsABUPs1mz4= golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk= golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw= golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= -golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= -golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= +golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= -golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= -golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= +golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA= +golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= +golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= +golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 h1:fCvbg86sFXwdrl5LgVcTEvNC+2txB5mgROGmRL5mrls= google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217/go.mod h1:+rXWjjaukWZun3mLfjmVnQi18E1AsFbDN9QdJ5YXLto= diff --git a/internal/rules/embedded/ctxcop.toml b/internal/rules/embedded/ctxcop.toml index eff0275..923a472 100644 --- a/internal/rules/embedded/ctxcop.toml +++ b/internal/rules/embedded/ctxcop.toml @@ -192,3 +192,88 @@ id = "sourcegraph-access-token" description = "Sourcegraph access token (prefixed forms only; bare 40-hex dropped — collides with Git SHAs)" regex = '''(?i)\b(\b(sgp_(?:[a-fA-F0-9]{16}|local)_[a-fA-F0-9]{40}|sgp_[a-fA-F0-9]{40})\b)(?:\\?['"\x60]|[\s;]|\\[nr]|$)''' keywords = ["sgp_"] + +# Redis authentication credentials. Ported from webflow/secrets-scrubber +# (built around a real Redis key leak into an AI session), where betterleaks +# upstream has a structural gap: a bare Redis password carries no +# self-identifying token prefix and no key=value assignment structure, the +# two shapes gitleaks-class rules detect. Four leak shapes passed through +# unredacted upstream + embedded as of v0.1.1: the plain AUTH command line +# as error logs and pasted history show it, the node-redis structured error +# form (args array and JSON rendering), redis-cli invocations, and RESP +# protocol dumps in all three encodings they appear in logs (raw CRLF, +# escaped CRLF, space-flattened). +# +# Adaptations from the secrets-scrubber JS originals to RE2 + CEL-filter +# semantics: +# 1. Reference-value exclusion ($VAR refs, process.env chains, template +# placeholders must pass) moves from a replace-callback heuristic into +# a per-rule CEL filter on the captured secret. +# 2. The plain-AUTH "value must contain an uppercase letter or digit" +# gate becomes the `[a-z]*[A-Z0-9]` prefix, preserving the secret-span +# start. +# 3. RESP bulk values exclude whitespace and backslash instead of the JS +# tempered-dot lookahead (RE2 has none). Real passwords contain neither. +# 4. The RESP rule additionally requires the `*N` array header every real +# RESP command dump carries — the JS original does not anchor on it, +# but without it a dollar-amount next to the literal word "auth" in +# prose would redact an innocent trailing word. All of +# secrets-scrubber's RESP fixtures carry the header, so recall on the +# leak shapes is unchanged. +# +# Span semantics: these rules redact the whole match (AUTH verb, framing, +# and ACL username vanish with the password), matching the bearer-token +# rule's house style. The db-connection-uri rule keeps the host only +# because its regex deliberately ends at `@`. +# +# Every rule carries a minimum-length floor: a sub-8-char finding trips +# Splice's over-redact backstop against lines sharing its tiny secret form +# (a stray `/` swept every slash-bearing line during development). The +# plain-AUTH rule keeps secrets-scrubber's 16+ floor; array, RESP, and cli +# rules use 8. +[[rules]] +id = "ctxcop-redis-auth-command" +description = "Redis AUTH command line: optional ACL user then a 16+ char password (upper or digit required)" +regex = '''(?m)(?:^|[^A-Za-z0-9_])AUTH[ \t]+(?:[A-Za-z0-9_.-]{1,64}[ \t]+)?([a-z]*[A-Z0-9][^\s'"`]{15,})''' +keywords = ["auth"] +filter = ''' +matchesAny(finding["secret"], [ + "^[$<{%\\[]", + "^(?i)(?:process|env|os|self|config|secrets?|var|vars)\\." +]) +''' + +[[rules]] +id = "ctxcop-redis-auth-array" +description = "Redis AUTH in structured args / JSON: quoted AUTH, optional user, 8+ char quoted password" +regex = '''['"]AUTH['"]\s*,\s*(?:['"][^'"]{1,64}['"]\s*,\s*)?['"]([^'"]{8,})['"]''' +keywords = ["auth"] +filter = ''' +matchesAny(finding["secret"], [ + "^[$<{%\\[]", + "^(?i)(?:process|env|os|self|config|secrets?|var|vars)\\." +]) +''' + +[[rules]] +id = "ctxcop-redis-auth-resp" +description = "Redis AUTH in RESP protocol dumps (raw/escaped/flattened CRLF): password bulk string after the AUTH command bulk" +regex = '''(?i)\*[0-9]+(?:\\r\\n|\r\n|\n|\r| )\$4(?:\\r\\n|\r\n|\n|\r| )auth(?:\\r\\n|\r\n|\n|\r| )(?:(?:\$[0-9]+(?:\\r\\n|\r\n|\n|\r| ))?[^\s\\]+(?:\\r\\n|\r\n|\n|\r| ))?\$[0-9]+(?:\\r\\n|\r\n|\n|\r| )([^\s\\]+)''' +keywords = ["auth"] +filter = ''' +matchesAny(finding["secret"], [ + "^[$<{%\\[]" +]) +''' + +[[rules]] +id = "ctxcop-redis-auth-cli" +description = "redis-cli password flag arguments (the -a/--pass flags)" +regex = '''\bredis-cli\b[^\n|;&]*?[ \t](?:-a|--pass)[ \t]+['"]?([^\s'"]{8,})''' +keywords = ["redis-cli"] +filter = ''' +matchesAny(finding["secret"], [ + "^[$<{%\\[]", + "^(?i)(?:process|env|os|self|config|secrets?|var|vars)\\." +]) +''' diff --git a/internal/rules/redis_auth_rules_test.go b/internal/rules/redis_auth_rules_test.go new file mode 100644 index 0000000..376c370 --- /dev/null +++ b/internal/rules/redis_auth_rules_test.go @@ -0,0 +1,152 @@ +package rules + +import "testing" + +// Redis AUTH coverage (ctxcop-redis-auth-* rules). Ported from +// webflow/secrets-scrubber, which was built around a real Redis key leak +// into an AI session. Positive shapes are the leak forms; negative shapes +// are secrets-scrubber's own false-positive suite plus the gates added in +// the port. Every literal is split via join() so no contiguous +// credential-shaped string sits in this file. +func TestRedisAuthRulesMatchAndAreGated(t *testing.T) { + token := join("Zk3", "mQ9vLp2XwR7tY", "bN4cH8dF") // 24-char fake + user := "svc" + + cases := []struct { + name string + content string + want string // rule ID that must fire + notWant string // rule ID that must NOT fire + }{ + // Plain AUTH command line. + { + name: "plain AUTH command in an error line", + content: join("AbortError: AUTH ", token, " failed"), + want: "ctxcop-redis-auth-command", + }, + { + name: "AUTH with ACL username", + content: join("AUTH ", user, " ", token), + want: "ctxcop-redis-auth-command", + }, + { + // secrets-scrubber's prose gate: a status phrase after the + // AUTH verb is not a password. + name: "prose after AUTH verb is left alone", + content: "AUTH rotation-complete", + notWant: "ctxcop-redis-auth-command", + }, + { + name: "env-var reference value is left alone", + content: "AUTH $REDIS_PASS", + notWant: "ctxcop-redis-auth-command", + }, + { + name: "process.env reference value is left alone", + content: "password: process.env.REDIS_PASS", + notWant: "ctxcop-redis-auth-command", + }, + // Structured args / JSON (node-redis error form). + { + name: "node-redis args array without user", + content: join("args: [ 'AUTH', '", token, "' ]"), + want: "ctxcop-redis-auth-array", + }, + { + name: "node-redis JSON array with user", + content: join(`["AUTH","`, user, `","`, token, `"]`), + want: "ctxcop-redis-auth-array", + }, + { + name: "pretty-printed JSON with newline between elements", + content: join("[\"AUTH\",\n \"", token, "\"]"), + want: "ctxcop-redis-auth-array", + }, + { + name: "array value under 8-char floor is left alone", + content: `["AUTH","svc","short"]`, + notWant: "ctxcop-redis-auth-array", + }, + { + name: "array process.env value is left alone", + content: `["AUTH","svc","process.env.REDIS_PASS"]`, + notWant: "ctxcop-redis-auth-array", + }, + // RESP protocol dumps. + { + name: "RESP dump, raw CRLF, no user", + content: join("*2\r\n$4\r\nAUTH\r\n$24\r\n", token, "\r\n"), + want: "ctxcop-redis-auth-resp", + }, + { + name: "RESP dump, raw CRLF, with ACL user", + content: join("*3\r\n$4\r\nAUTH\r\n$3\r\n", user, "\r\n$24\r\n", token, "\r\n"), + want: "ctxcop-redis-auth-resp", + }, + { + name: "RESP dump, escaped CRLF text form", + content: join("*2\\r\\n$4\\r\\nAUTH\\r\\n$24\\r\\n", token, "\\r\\n"), + want: "ctxcop-redis-auth-resp", + }, + { + name: "RESP dump, space-flattened, lowercase command", + content: join("*2 $4 auth $24 ", token, " done"), + want: "ctxcop-redis-auth-resp", + }, + { + // Other RESP commands must stay untouched. + name: "RESP GET dump is left alone", + content: "*2\r\n$3\r\nGET\r\n$24\r\nsome:cache:key:abc12345\r\n", + notWant: "ctxcop-redis-auth-resp", + }, + { + // Port deviation from secrets-scrubber: the RESP rule requires + // the *N array header, so headerless prose dollar-amounts near + // the word auth do not redact. + name: "flattened AUTH without array header is left alone", + content: join("$4 auth $24 ", token, " done"), + notWant: "ctxcop-redis-auth-resp", + }, + // redis-cli flags. + { + name: "redis-cli -a with other flags", + content: join("redis-cli -h host --tls -a ", token, " ping"), + want: "ctxcop-redis-auth-cli", + }, + { + name: "redis-cli --pass quoted", + content: join("redis-cli --pass '", token, "' info"), + want: "ctxcop-redis-auth-cli", + }, + { + name: "redis-cli -a bare", + content: join("redis-cli -a ", token), + want: "ctxcop-redis-auth-cli", + }, + { + name: "redis-cli env-var reference is left alone", + content: "redis-cli -a $REDIS_PASS ping", + notWant: "ctxcop-redis-auth-cli", + }, + { + // Floor guard: a sub-8-char "secret" trips Splice's + // over-redact backstop against unrelated lines carrying the + // same short form. + name: "redis-cli 7-char value under floor is left alone", + content: "redis-cli --pass short12 ping", + notWant: "ctxcop-redis-auth-cli", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + fired := firedRules(t, tc.content) + if tc.want != "" && !fired[tc.want] { + t.Fatalf("expected %s to fire; fired=%v", tc.want, keys(fired)) + } + if tc.notWant != "" && fired[tc.notWant] { + t.Fatalf("expected %s NOT to fire; fired=%v", tc.notWant, keys(fired)) + } + }) + } +} diff --git a/testing/elicit-mcp/uv.lock b/testing/elicit-mcp/uv.lock index c09dea8..466658a 100644 --- a/testing/elicit-mcp/uv.lock +++ b/testing/elicit-mcp/uv.lock @@ -276,7 +276,7 @@ wheels = [ [[package]] name = "mcp" -version = "2.0.0" +version = "2.2.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "anyio" }, @@ -294,22 +294,22 @@ dependencies = [ { name = "typing-inspection" }, { name = "uvicorn", marker = "sys_platform != 'emscripten'" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/74/33/32d4dff2c95bb5d897c3ef4c83649a08996b17b58f0a326d2495d4c81179/mcp-2.0.0.tar.gz", hash = "sha256:0f440e735c13ece8bb19bc62cf0b86f4313448432fbb77d35e14034f4e050728", size = 1662284, upload-time = "2026-07-28T13:45:32.346Z" } +sdist = { url = "https://files.pythonhosted.org/packages/76/31/ac54fb0fdd5b37de704486e288bba4fbbb463f24cfcfedbede407b854513/mcp-2.2.0.tar.gz", hash = "sha256:2dc37ecb1974becdcebdbf7561e7c15a07dbbf20ba21ba16c3593b3038b3afbd", size = 4084129, upload-time = "2026-09-07T16:06:23.439Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/67/72/7d7897418912c1d12e87556630dfb7bf0eac71160e9bef8b447960804ee3/mcp-2.0.0-py3-none-any.whl", hash = "sha256:1cb4c75d2d2c7b8c1d756355e5d82a39f2822cc7f13e22a2051d7ca3592349d6", size = 349980, upload-time = "2026-07-28T13:45:28.853Z" }, + { url = "https://files.pythonhosted.org/packages/1b/ff/8e7eade68b8a28f7da0ed1085544341b51f9c935dbf6b95c76b7edfea6a0/mcp-2.2.0-py3-none-any.whl", hash = "sha256:bde982589473a060ae145e3406e9a5333fe538c97229ba841f5a7f92be004f81", size = 365656, upload-time = "2026-09-07T16:06:19.711Z" }, ] [[package]] name = "mcp-types" -version = "2.0.0" +version = "2.2.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "pydantic" }, { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/bb/56/9b8e1c152f61f6c6b07c4b5896c88c7d0ae90bac6ee6306f852fcc5c1eb0/mcp_types-2.0.0.tar.gz", hash = "sha256:d7d939b9285c9961ae8866ba75ef85da34d12bafe276efbf4eb6a131786d8379", size = 66632, upload-time = "2026-07-28T13:45:33.804Z" } +sdist = { url = "https://files.pythonhosted.org/packages/ae/91/762d7755d971aff8a28d75f7961656148edf27875c8026e6385aaab08ae7/mcp_types-2.2.0.tar.gz", hash = "sha256:d3ed53703ddd10d9c6399f29d322bb66f3f67ab41348ac8556ba23e07fedefad", size = 65892, upload-time = "2026-09-07T16:06:25.187Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/f5/4c/c78d78c3d52b0ac594ad7cc8ef5972adfe070e3597a8a4c6ce0cd39196ea/mcp_types-2.0.0-py3-none-any.whl", hash = "sha256:6b2de797ca2797f568b79529e1b25948e34de511bcc0bd82fef1039a6d1b8eb0", size = 69649, upload-time = "2026-07-28T13:45:30.713Z" }, + { url = "https://files.pythonhosted.org/packages/8f/d7/6ffba5d8cd5dd9b8a19478875c50e04945314ba5074e84d749283f27f62d/mcp_types-2.2.0-py3-none-any.whl", hash = "sha256:ea476b73ee86709ab5abc9452385ed36cc05907e582355622e294595c9a04f13", size = 69106, upload-time = "2026-09-07T16:06:21.461Z" }, ] [[package]]