-
Notifications
You must be signed in to change notification settings - Fork 952
Feat: User-level secrets store #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: nightly
Are you sure you want to change the base?
Conversation
- Added UserSecretsStore durable object for secure secret storage and management - Implemented XChaCha20-Poly1305 encryption service for secure secret storage - Heirarchial key derivation
- Increased PBKDF2 iterations to 600k/100k for stronger key derivation - Added memory zeroing for plaintext bytes in encryption/decryption operations - Implemented promise-based locking for key rotation to prevent concurrent modifications - Added detailed security documentation for deterministic salt design and SQL injection prevention - Updated UserSecretsStore to wait for any in-progress key rotation before executing operations - Added comprehensive
…r-secrets-management
|
Claude finished @AshishKumar4's task —— View job Code & Security Review (Critical Path)Recommendation: APPROVE WITH MINOR SUGGESTIONS I've completed a comprehensive security-focused review of this user secrets management implementation. This is high-quality, production-ready code with strong cryptographic foundations and excellent test coverage. Security AnalysisStrengthsEncryption Architecture
Key Derivation
Durable Object Design
API Security
Operational Security
Minor Concerns & Suggestions1. Deterministic Salt for UMK Derivation Location: Issue: The userId is used as a deterministic salt for deriving the User Master Key. While this is documented as required for the DO architecture, it means:
Assessment: This is an acceptable architectural trade-off given the DO constraints, but it's worth noting:
Recommendation: Add a section to documentation about MEK management best practices:
2. Memory Zeroing Limitation Location: Issue: The code correctly notes that JavaScript strings are immutable and cannot be zeroed from memory. The plaintext secret values remain in heap until garbage collected. Assessment: This is a fundamental JavaScript limitation, not a code flaw. The comment correctly documents this. Mitigation:
Recommendation: No code changes needed. The inline comment is excellent. Consider adding to documentation that this is a known limitation. 3. SQL Injection Safety (Dynamic Query) Location: Assessment: The dynamic SQL query construction for updates is SAFE: UPDATE secrets SET ${updateFields.join(', ')} WHERE id = ?
The inline comment (lines 343-348) correctly documents this safety. Well done. 4. Error Message Information Disclosure Location: Assessment: Good job returning null instead of throwing exceptions on validation failures. This prevents leaking implementation details. However, some exceptions are still thrown:
Recommendation: Consider returning null for these cases too, or ensure they're caught and logged without exposing details to the client. 5. Key Rotation Race Condition Protection Location: Assessment: Excellent implementation:
Well-designed concurrency control. Code QualityExcellent:
Minor Issues:
TestingCoverage: Excellent
Recommendation: All tests should pass before merge. Run Architecture AlignmentDurable Object Patterns: Perfect implementation following vibesdk conventions:
API Patterns: Follows existing controller/route patterns:
Documentation: CLAUDE.md properly updated with architecture overview. SummaryThis is a well-designed, secure implementation of user secrets management. The cryptographic choices are sound, the DO architecture is proper, and the code quality is high. The 90+ tests demonstrate thorough validation. Key Strengths:
Minor Suggestions:
Approval: This code is ready to merge after ensuring SECRETS_ENCRYPTION_KEY is properly configured in production environment. |
Summary
This PR introduces a production-ready user-level secrets management system built on Cloudflare Durable Objects, enabling secure storage of API keys and sensitive credentials with encryption, key rotation support, and comprehensive audit trails.
Changes
Core Infrastructure
worker/services/secrets/UserSecretsStore.ts) - One DO per user architecture with SQLite backendworker/services/secrets/KeyDerivation.ts) - MEK → UMK → DEK chain using PBKDF2worker/services/secrets/EncryptionService.ts) - AEAD encryption with authenticated data integritySecurity Features
API Endpoints
GET /api/user-secrets- List all secrets (metadata only)POST /api/user-secrets- Store new secretGET /api/user-secrets/:id/value- Retrieve decrypted secret valuePATCH /api/user-secrets/:id- Update secretDELETE /api/user-secrets/:id- Soft delete secretConfiguration
UserSecretsStoreDO binding towrangler.jsoncv3for DO SQLite schemaSECRETS_ENCRYPTION_KEYenvironment variable requirementwrangler.test.jsoncfor isolated testingTesting
Documentation
CLAUDE.mdwith User Secrets Store architecture overviewMotivation
VibeSDK needs secure storage for user API keys (OpenAI, Anthropic, Google AI) without exposing them in plaintext or storing them in the main database. This implementation provides:
Testing
Manual Testing
SECRETS_ENCRYPTION_KEYenvironment variable set to 64-char hex stringSECRETS_ENCRYPTION_KEYand verifying secrets remain accessibleAutomated Testing
Run: bun run test
All 90+ tests pass, covering:
Breaking Changes
None. This is a new feature with no impact on existing functionality.
This PR description was automatically generated by Claude Code