Skip to content

fix(sanitizer): redact bare SendGrid API keys (TSK-007) - #104

Merged
jmlweb merged 2 commits into
mainfrom
hustle/maintainer/task-2026-11-16
Nov 16, 2026
Merged

jmlweb merged 2 commits into
mainfrom
hustle/maintainer/task-2026-11-16

Conversation

@jmlweb

@jmlweb jmlweb commented Nov 16, 2026

Copy link
Copy Markdown
Owner

What changed

  • src/core/sanitizer.ts: redactProviderTokens gets a SendGrid pattern, /\bSG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])/g → [REDACTED_SENDGRID_KEY]. The pattern ends with a negative lookahead, not \b, because keys can end in - or _ (same issue as the Google key fix). Before this change, bare SG.<22>.<43> keys had no provider pattern, and the opaque-id fallback misses base64url segments with _/-, so they leaked whole.
  • src/core/sanitizer.test.ts: new SendGrid API keys block. It covers a realistic key with _ and -, an all-letter key, and a key inside a curl command. Keys are built at runtime (['SG', id, secret].join('.')), so no literal key is committed. One test also checks the 22/43 segment lengths of the fixtures.
  • docs/SPECS.md: SendGrid is now in the provider list.
  • Backlog: TSK-007 moves from pending/ to complete/ with its progress log, plus learning LRN-006 (dev install notes).

Acceptance criteria

  1. sanitize replaces a bare SG.<22>.<43> key whole, including segments with _ or -. pnpm vitest run src/core/sanitizer.test.ts -t SendGrid: 3 of 4 failed before the pattern (the 4th checks fixture lengths only). All 4 pass after it. Output is exactly [REDACTED_SENDGRID_KEY].
  2. Tests cover a realistic key, an all-letter key and a key in surrounding text, built at runtime. See the SendGrid API keys describe block. git show HEAD | rg 'SG\.[A-Za-z0-9_-]{20,}\.' finds no matches, and GitHub push protection accepted the push.
  3. docs/SPECS.md lists SendGrid. See docs/SPECS.md:165.
  4. pnpm check && pnpm test pass. pnpm check exits 0. pnpm test passes 26 files and 471 tests. pnpm build also succeeds. All three were re-run on the committed tree after lint-staged.

How it was verified

Locally on Node 24.22.0, because engine-strict rejects Node 25. The local shell exports NODE_ENV=production, which makes pnpm skip devDependencies, so I ran install with NODE_ENV=development and tests with NODE_ENV=test. CI is not affected.

🤖 Generated with Claude Code

Add an SG.<22>.<43> pattern to redactProviderTokens so keys whose
segments contain _ or - are replaced whole with [REDACTED_SENDGRID_KEY].
Tests build keys at runtime to avoid secret scanning. SPECS.md lists
SendGrid among covered providers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmlweb

jmlweb commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

🤖 hustle review: approve — SendGrid pattern is correct, with a lookahead for keys ending in - or _. Fixture lengths check out at 22 and 43, and tests build keys at runtime. SPECS.md and the backlog are updated, so all acceptance criteria are met.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmlweb

jmlweb commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

🤖 hustle review: approve — SendGrid pattern is correct (22/43 segments, lookahead handles trailing -/_), tests cover all required cases with runtime-built keys, docs and backlog updated; all acceptance criteria met.

@jmlweb
jmlweb merged commit e316a70 into main Nov 16, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 16, 2026
## [4.1.5](v4.1.4...v4.1.5) (2026-11-16)

### Bug Fixes

* **sanitizer:** redact bare SendGrid API keys (TSK-007) ([#104](#104)) ([e316a70](e316a70))

### Chores

* **backlog:** file and triage permission deny-rule overlap report ([#103](#103)) ([606df32](606df32))
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.1.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant