feat(crypto): validate CREDENTIAL_MASTER_KEY format at startup#1071
feat(crypto): validate CREDENTIAL_MASTER_KEY format at startup#1071
Conversation
Add npm overrides to force lodash-es>=4.18.1, resolving GHSA-r5fr-rjxr-66jc (Code Injection via _.template) and GHSA-f23m-r3pf-42rh (Prototype Pollution) which affected transitive deps chevrotain/js-toml/llmist. Also updates brace-expansion to 2.0.3 to resolve moderate GHSA-f886-m6hf-6m8v. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CI Failures ResolvedFixes Applied
The audit failures were pre-existing on the Verification
🕵️ claude-code · claude-sonnet-4-6 · run details |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
nhopeatall
left a comment
There was a problem hiding this comment.
Summary
LGTM — clean, well-scoped fail-fast validation that catches malformed CREDENTIAL_MASTER_KEY at boot instead of mid-request.
The implementation is correct:
validateCredentialMasterKey()uses a result-type pattern (no throwing), consistent with its role as a startup check- Adds hex-content validation (
/^[0-9a-fA-F]+$/) that the existinggetMasterKey()lacks —Buffer.from(hex, 'hex')silently drops non-hex chars, so this catches a real silent-corruption bug - Both entry points (Router + Dashboard) validate early before any async initialization
- No behavior change when the key is unset (encryption remains opt-in)
- The
lodash-esoverride and lock file churn are unrelated dependency maintenance — harmless
Tests are thorough: unit tests cover all validation branches (unset, valid, too short, too long, non-hex, uppercase), and the startup-validation test file verifies the process.exit integration pattern. All CI checks pass.
No architectural concerns — the validation function lives in the right module (db/crypto.ts) next to the functions that consume the key, and the startup call sites are minimal and obvious.
🕵️ claude-code · claude-opus-4-6 · run details
Summary
validateCredentialMasterKey()function tosrc/db/crypto.tsthat validates theCREDENTIAL_MASTER_KEYenv var format (64-char hex) at call time, returning a result object instead of throwingstartRouter()(src/router/index.ts) andstartDashboard()(src/dashboard.ts) so a malformed key is detected at boot rather than mid-requestprocess.exit(1)and a descriptive error message when the key is set but malformedgetMasterKey()lacks —Buffer.from(hex, 'hex')silently ignores non-hex chars, which could produce a wrong keyTest plan
validateCredentialMasterKey()unit tests — all valid/invalid scenarios (unset, correct, too short, too long, non-hex, uppercase)process.exit(1)is called when key is malformed, not called when key is valid or unsetCard
https://trello.com/c/69ce1bd2060817e9d257b7b9
🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details