Skip to content

fix(CostTracker): stop false BYPASS alerts on manifests + fix dead x-api-key detector#1321

Open
ugiya wants to merge 1 commit into
danielmiessler:mainfrom
ugiya:fix/costtracker-classification-hardening
Open

fix(CostTracker): stop false BYPASS alerts on manifests + fix dead x-api-key detector#1321
ugiya wants to merge 1 commit into
danielmiessler:mainfrom
ugiya:fix/costtracker-classification-hardening

Conversation

@ugiya

@ugiya ugiya commented May 30, 2026

Copy link
Copy Markdown

What you see (the symptom)

On a normal PAI install, the hourly CostTracker cron pops a macOS cost alert (#1319) for package.json dependency declarations, while a broken detector regex silently misses real raw x-api-key calls (#1320). This PR fixes both and hardens the classifier.

What this changes

  • SDK-pattern-gated manifest exemptionpackage.json/lockfile dependency declarations classify legit, but --bare/raw-HTTP inside a manifest's scripts still classify bypass (an earlier naive fix masked them).
  • Fix the x-api-key regex\| (literal pipe) → (anthropic|sk-ant) alternation; the detector was matching nothing.
  • Raw-HTTP patterns now classify bypass, not unknown.
  • Stable id+kind per RISK_PATTERN; baseline keyed on file:line:patternId so note/classification changes no longer churn the baseline ("phantom NEW").
  • Exact-basename manifest match (not endsWith); drop dead bun.lockb; exclude config-with-scripts (deno.json/composer.json); LEGIT_HINTS win before the manifest check.
  • Add CostTracker.test.ts (bun test, 13 cases) incl. the --bare-in-package.json regression, baseline-key stability, and the regex fix.

Verification

bun test → 13 pass / 0 fail. Local scan → bypass 0; alert-check → no alerts.

Not in this PR (follow-ups)

  • First-run UX: don't alarm "NEW since baseline" when no baseline exists.
  • Notification: multiple alerts render as one run-on line; separate them and include the offending file path.

Fixes #1319
Fixes #1320

🤖 Generated with Claude Code

…ifier

Reworks the manifest false-positive fix after two review passes:
- Exempt dependency manifests/lockfiles ONLY for SDK-dependency patterns
  (kind-gated), so `--bare`/raw-HTTP inside a manifest's scripts still
  classify as bypass (the v1 fix masked them).
- Fix the x-api-key RISK_PATTERN regex: `\\|` was a literal pipe, not
  alternation, so the detector never matched real code -> x-api-key.*(anthropic|sk-ant).
- Raw-HTTP patterns now classify bypass, not unknown.
- Stable id+kind per RISK_PATTERN; baseline keyed on file:line:patternId
  so note/classification changes no longer churn the baseline.
- Exact-basename manifest match (not endsWith); drop dead bun.lockb;
  exclude config-with-scripts files (deno.json/composer.json); LEGIT_HINTS
  win before the manifest check.
- Add CostTracker.test.ts (bun test, 13 cases) incl. the --bare-in-package.json
  regression, baseline-key stability, and the regex fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant