Skip to content

v0.1.11 — security + supply-chain hardening + perf - #184

Merged
thehoff merged 12 commits into
developfrom
release/v0.1.11
May 26, 2026
Merged

thehoff merged 12 commits into
developfrom
release/v0.1.11

Conversation

@thehoff

@thehoff thehoff commented May 26, 2026

Copy link
Copy Markdown
Owner

v0.1.11 — security + supply-chain hardening + perf

Bundles 7 closed issues across 3 PR clusters from one heavy hardening day.

What's in this release

🔒 Security (#180, #181, #182)

  • security(supply-chain): downgrades.jsonl + supply_chain.jsonl capture inline credentials #180 — credentials no longer captured in audit logs. Both downgrades.jsonl and supply_chain.jsonl previously serialised the raw shell command verbatim, capturing inline tokens (curl Authorization headers, env-var assignments to *_TOKEN/*_KEY/*_SECRET, GitHub PAT prefixes, URL basic-auth, git-credential-helper \npassword=…, CLI flag values). A real-world 24h scan of one user's log surfaced 27 unique 40-hex tokens + 15 Authorization: token <hex> headers in cleartext. Fixed at the log-write boundary in both gates + the tirith blob (which echoes cmd back in findings). Ships a new contextcrawler security --scrub-logs [--dry-run] CLI that retroactively cleans existing on-disk logs (deep-walks every string, atomic rewrite via temp file, timestamped backup).

  • fix(supply-chain): honour inline-prefix CONTEXTCRAWLER_SUPPLY_CHAIN=off bypass #181 — CONTEXTCRAWLER_SUPPLY_CHAIN=off now honoured as an inline prefix. The gate's own error messages tell users:

    Overrides: rerun with CONTEXTCRAWLER_SUPPLY_CHAIN=off, or add the package …
    

    but the gate only checked the shell environment, not the inline-prefix form (CONTEXTCRAWLER_SUPPLY_CHAIN=off pip install x scopes the assignment to the subprocess, not the hook). Users followed the documented bypass and were still blocked. Now parses leading POSIX-style assignments off the cmd and honours =off, =0, =false, =no. Must be a prefix (mid-cmd && FOO=bar does not bypass).

  • fix(supply-chain): retry transient HTTP errors so a single blip doesn't blackout the gate #182 — retry on transient HTTP errors. A single transient registry/OSV blip previously turned the whole install into Verdict::Unavailable (no retry, first error wins). 5 unavailable verdicts in 24h on one user, all on pip install for normal packages with the network up. Now: 1 retry, 5s per-attempt timeout, 250ms backoff. Retried only on Transport(_) and Status(500..600, _). 4xx is terminal — don't punish a rate-limiter with another request. Worst-case 10.25s/call, well under CHECK_WALL_BUDGET = 25s.

🛠 Supply-chain hardening (#145, #147, #149)

  • fix(supply-chain): parse_package_args robustness (PEP 508 extras, inline #, flag values) #145 — parse_package_args robustness. Three orthogonal false-positives fixed:

    • pip install celery[redis] — PEP 508 extras suffix now stripped before PyPI lookup (was 404 → Unavailable).
    • pip install flask # production — inline # comment now terminates the args loop (was slurping # and production as packages, both 404'd, cascading to Ask).
    • --platform linux_x86_64, --python-version 3.11, --trusted-host pypi.org, etc. — full pip value-consuming flag set extracted into a named PIP_VALUE_CONSUMING_FLAGS const; previously only -t/--target/--index-url were known and other values were misclassified as packages.
  • harden(supply-chain): add Ecosystem::Unknown variant for depth-cap synthetic Unvettable #147 — Ecosystem::Unknown variant for depth-cap synthetic. When recursion hits MAX_RECURSION_DEPTH and surfaces an unvettable, it was hardcoded to Ecosystem::Npm — a deep-nested PyPI/mixed-shell payload was labelled [npm] in the surfaced finding. Verdict was always correct; label is now too. Cascade arms added in 3 existing matches (lockfile unvettable text, config lookup, registry routing) all paired with unvettable: Some(...) so unreachable in practice; structured for compile-time exhaustiveness.

  • perf(supply-chain): O(n^2) hot paths in claimed-span dedup and dedup_installs #149 — O(n²) → O(n) dedup + O(log n) claimed-span check. Mechanical refactor, no behaviour change. dedup_installs now uses a HashSet keyed on a stable canonical signature (sorted packages for order-independence). Claimed-span overlap-check uses BTreeMap<usize, usize> with range(..=start).next_back(). Stress test: 5,000 dedup completes in single-digit ms (was 25M pairwise comparisons); 200-segment install detect in <250ms.

🧹 CI (#183)

📐 Process / docs

Test coverage

Module Tests Notes
core::secret_redact 16 All redaction patterns + idempotency + PATH-must-not-be-redacted invariant
hooks::tirith_gate 6 3 original + 3 for scrub_logs_in (full + dry-run + missing-files)
hooks::supply_chain_gate 173 138 baseline + 8 inline-bypass + 6 retry-policy + 21 from #145/#147/#149
tests::branding_lint 5 clap-aware sub-rule + all 4 pre-existing

200+ tests green across the touched stack. No regressions.

Upgrade notes

  • No breaking changes.
  • New user-facing CLI: contextcrawler security --scrub-logs [--dry-run].
  • The #182 retry change reduces per-attempt HTTP timeout from 8s → 5s; worst case per call (with 1 retry) is now 10.25s vs the previous 8s single-shot. Within CHECK_WALL_BUDGET = 25s either way; expect slightly more resilience under flaky upstream registries.
  • Existing audit logs are NOT automatically scrubbed on upgrade. Run contextcrawler security --scrub-logs once after install if you've used inline credentials in shell commands (curl headers, env-var literals, gh auth login --with-token, etc.).

Empirical proof — real-world 24h scan

Pattern Before After
Authorization: token <hex> in audit logs 15 0
40-hex tokens captured 27 0
GitHub PAT prefixes 0 0

Closes

#75, #77, #145, #147, #149, #180, #181, #182, #183

thehoff and others added 12 commits May 26, 2026 13:09
…aks (#75)

Adds branding_lint_clap_doc_comments_fail_on_rtk — explicit FORBIDDEN_TOKENS list (RTK savings/adoption/equivalent/artifacts/etc.) for clap doc-comments. New rule passes; merging.

Note: the existing branding_lint_no_unrecognised_rtk_references_in_src failure on develop is unrelated (pre-existing leaks in src/hooks/init.rs:28,3031,3051,5125).
…ated decisions

Design-only PR — 4 new files under docs/contributing/. No production code.
Fixes 4 RTK leaks in src/hooks/init.rs. 5/5 branding_lint tests green; 160/160 init tests still green.
PEP 508 extras stripped; # inline comments terminate args; full pip value-flag set consumed. 18 new tests.
Depth-cap synthetic now labelled Unknown instead of hardcoded Npm. Cascade arms added in 3 existing matches.
HashSet-based dedup + BTreeMap-based claimed-span overlap-check.
…#180)

Both gates serialised the raw shell command verbatim into JSONL on disk.
Last-24h scan of a single user's downgrades.jsonl found 27 40-hex tokens
and 15 `Authorization: token <hex>` headers captured in cleartext at a
predictable path.

Add `core::secret_redact::redact` and apply it at both write sites
(`tirith_gate::log_downgrade`, `supply_chain_gate::log_event`).

Covered patterns:
- URL basic-auth (`https://user:pw@host`)
- `Authorization: token|Bearer <value>` headers
- GitHub PAT prefixes (gho_/ghp_/ghs_/ghu_/github_pat_)
- Env-var assignments to credential-shaped names
  (matches `*_TOKEN`/`*_KEY`/`*_SECRET`/`*_PASSWORD`/`*_PAT`/`*_APIKEY`/`*_AUTH`
   and bare equivalents; leaves PATH/HOME/etc. alone)
- CLI flags `--token`/`--auth-token`/`--password`/`--api-key`/`--secret`,
  space-separated or `=`-attached

Conservative scrubber: prefer false negatives over corrupting the
diagnostic value of the log. Zero-copy fast path (`Cow::Borrowed`) when
the cmd has nothing to scrub. Idempotent.

15 unit tests cover each pattern + idempotency + the
PATH-must-not-be-redacted invariant.

Out of scope: backfill scrub utility for existing logs (follow-up),
log rotation, encryption at rest.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#180)

Two follow-ups after a real-world scrub of one user's existing logs found
30 surviving secret-shaped strings:

1) The `tirith` field in downgrades.jsonl is spliced in verbatim from the
   tirith subprocess output. That blob frequently echoes the original
   command (and any inline credentials) back inside its findings. Apply
   the same redactor to it before splicing.

2) git-credential-helper feeds creds over a pipe as
   `protocol=...\nhost=...\nusername=...\npassword=<TOKEN>` where the
   `\n` is a literal two-char escape. From the regex engine's POV,
   `password` lives mid-word and `\b` doesn't anchor. Add a targeted
   pattern that matches `(\\n|\\r)(password|token|secret|auth)=...` and
   preserves the escape prefix in the replacement.

Add a unit test for the git-credential-helper case + document the one
remaining known limitation (`T=<40-hex>` one-letter aliases can't be
safely caught by name-shape alone without false-positiving git SHAs).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
#180)

Closes the final acceptance item on #180. The redactor lives in
core::secret_redact; this exposes it as a one-shot CLI action that
deep-walks every string in both audit JSONL files and rewrites them
atomically through a temp file, with a timestamped backup left alongside.

Behaviour:
- `contextcrawler security --scrub-logs` — live rewrite, prints per-file
  stats (lines / changed / unparseable) and backup path.
- `contextcrawler security --scrub-logs --dry-run` — same scan + report,
  no files touched. Useful before committing to a rewrite.
- Unparseable lines (e.g. heredoc-with-embedded-newlines records that
  broke JSONL framing) get a raw-line redaction fallback so noise can't
  smuggle secrets through.

Refactored the I/O core into `scrub_logs_in(&Path, dry_run)` so it's
unit-testable against a tempdir. Public `ScrubReport` / `ScrubFileReport`
structs expose per-file counts for callers that want to drive it
programmatically.

Three new tests:
- credentials in both cmd AND nested tirith blob are stripped + backup
  written
- dry-run reports counts without mutating files
- missing files are skipped gracefully

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ff bypass (#181)

The gate's own error messages explicitly tell users:

    Overrides: rerun with CONTEXTCRAWLER_SUPPLY_CHAIN=off, or add the package …

But that hint is misleading. `CONTEXTCRAWLER_SUPPLY_CHAIN=off pip install …`
scopes the assignment to the `pip install` subprocess — the gate has
already run by then and only reads its own process env. So the user
follows the documented bypass, is still blocked, and concludes the gate
is buggy.

Add `cmd_has_leading_assignment(cmd, name, allowed)` and call it from
`check()` after the existing `std::env::var` branch. It parses leading
POSIX-style `NAME=VALUE` tokens in the cmd string, stops at the first
non-assignment token (so mid-cmd `&& FOO=bar` does not bypass), and
returns true if `name` appears with one of the allowed values.

Conservative on value parsing — bareword values only. The bypass values
we care about are short (`off`/`0`/`false`/`no`), and supporting shell
quoting here would just create a different surprise.

Tests: 8 unit tests cover the documented form, sibling assignments,
value variants, the must-be-prefix invariant, defensive `=on` rejection,
exact-value-match guard, invalid identifiers, and empty cmd. The
existing `std::env::var` bypass path is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…'t blackout the gate (#182)

Five `Verdict::Unavailable` events in one user's 24h logs traced to a
single failed registry/OSV call early in the package loop. Once the
first transient error fires, `transient_err.get_or_insert(e)` captures
it, the loop moves on without further upstream calls succeeding into
findings, and `check()` falls through to `Verdict::Unavailable` even
though a retry would have cleared it.

Add a retry-with-backoff to `http_get_json` and `http_post_json`:

- 1 retry max (2 attempts total) to keep the worst-case per-call within
  the CHECK_WALL_BUDGET = 25s.
- Per-attempt timeout dropped from 8s to 5s. Total per-call worst case:
  5s + 250ms backoff + 5s = ~10.25s. Two slow packages still fit.
- Retry only on retryable error shapes:
  * `ureq::Error::Transport(_)` — DNS hiccup, connection reset, read
    timeout. Exactly the class that produced the user's blackouts.
  * `ureq::Error::Status(500..600, _)` — registry unhealthy / transient
    overload. Worth a single retry.
- 4xx is terminal — `404` (no such package), `401/403` (auth),
  `422` (malformed), `429` (rate-limit) all need *something other than
  immediate retry*. Bouncing harder against a rate-limiter just makes
  it worse.

The retry-or-not policy is lifted into a `HttpErrTag`-keyed pure
function (`is_retryable_http_err_tag`) so it can be unit-tested without
constructing a real `ureq::Response`/`ureq::Transport`. Six new tests:
5xx-retryable, 4xx-not-retryable, 2xx/3xx-not-retryable defensive case,
transport-retryable, and a budget-arithmetic guard that ensures the
retry math always fits inside CHECK_WALL_BUDGET — so a future
loosening of the constants can't silently push worst-case beyond the
deadline.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… retry-on-transient (#180/#181/#182)

Bundles 5 commits across three issues:
- #180: secret redaction at log-write boundary + scrub-logs CLI
- #181: inline-prefix CONTEXTCRAWLER_SUPPLY_CHAIN=off bypass
- #182: retry on transient HTTP errors

195/195 tests green across the security stack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

harden(branding-lint): clap-aware sub-rule to catch /// doc-comment leaks before they reach --help

1 participant