Jason Woltje
e3dd490d4d
fix(#84): address critical security issues in federation identity
Implemented comprehensive security fixes for federation instance identity:
CRITICAL SECURITY FIXES:
1. Private Key Encryption at Rest (AES-256-GCM)
- Implemented CryptoService with AES-256-GCM encryption
- Private keys encrypted before database storage
- Decrypted only when needed in-memory
- Master key stored in ENCRYPTION_KEY environment variable
- Updated schema comment to reflect actual encryption method
2. Admin Authorization on Key Regeneration
- Created AdminGuard for system-level admin operations
- Requires workspace ownership for admin privileges
- Key regeneration restricted to admin users only
- Proper authorization checks before sensitive operations
3. Private Key Never Exposed in API Responses
- Changed regenerateKeypair return type to PublicInstanceIdentity
- Service method strips private key before returning
- Added tests to verify private key exclusion
- Controller returns only public identity
ADDITIONAL SECURITY IMPROVEMENTS:
4. Audit Logging for Key Regeneration
- Created FederationAuditService
- Logs all keypair regeneration events
- Includes userId, instanceId, and timestamp
- Marked as security events for compliance
5. Input Validation for INSTANCE_URL
- Validates URL format (must be HTTP/HTTPS)
- Throws error on invalid URLs
- Prevents malformed configuration
6. Added .env.example
- Documents all required environment variables
- Includes INSTANCE_NAME, INSTANCE_URL
- Includes ENCRYPTION_KEY with generation instructions
- Clear security warnings for production use
TESTING:
- Added 11 comprehensive crypto service tests
- Updated 8 federation service tests for encryption
- Updated 5 controller tests for security verification
- Total: 24 tests passing (100% success rate)
- Verified private key never exposed in responses
- Verified encryption/decryption round-trip
- Verified admin authorization requirements
FILES CREATED:
- apps/api/src/federation/crypto.service.ts (encryption)
- apps/api/src/federation/crypto.service.spec.ts (tests)
- apps/api/src/federation/audit.service.ts (audit logging)
- apps/api/src/auth/guards/admin.guard.ts (authorization)
- apps/api/.env.example (configuration template)
FILES MODIFIED:
- apps/api/prisma/schema.prisma (updated comment)
- apps/api/src/federation/federation.service.ts (encryption integration)
- apps/api/src/federation/federation.controller.ts (admin guard, audit)
- apps/api/src/federation/federation.module.ts (new providers)
- All test files updated for new security requirements
CODE QUALITY:
- All tests passing (24/24)
- TypeScript compilation: PASS
- ESLint: PASS
- Test coverage maintained at 100%
Fixes #84
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 11:13:12 -06:00
..
2026-02-02 12:51:17 -06:00
2026-01-30 18:26:41 -06:00
2026-02-03 11:13:12 -06:00
2026-01-31 16:50:32 -06:00
2026-02-02 12:24:29 -06:00
2026-02-01 21:01:25 -06:00
2026-02-02 13:31:47 -06:00
2026-01-31 13:44:23 -06:00
2026-01-31 13:51:46 -06:00
2026-02-02 13:31:47 -06:00
2026-01-31 10:37:14 -06:00
2026-01-30 18:26:41 -06:00
2026-02-02 12:51:17 -06:00
2026-02-02 12:51:17 -06:00
2026-02-03 11:13:12 -06:00
2026-01-28 15:07:04 -06:00
2026-02-02 12:30:19 -06:00
2026-02-02 12:51:17 -06:00
2026-02-02 12:30:19 -06:00
2026-02-02 11:41:11 -06:00
2026-02-02 15:27:00 -06:00
2026-02-02 12:51:17 -06:00
2026-01-30 18:26:41 -06:00
2026-01-31 15:01:18 -06:00
2026-01-31 13:07:58 -06:00
2026-01-30 18:26:41 -06:00
2026-01-31 12:44:50 -06:00
2026-01-30 20:39:03 -06:00
2026-02-02 12:51:17 -06:00
2026-01-31 13:33:04 -06:00
2026-01-31 14:47:59 -06:00
2026-01-31 14:01:42 -06:00
2026-02-02 12:51:17 -06:00
2026-02-02 13:07:16 -06:00
2026-02-02 12:51:17 -06:00
2026-01-31 12:55:11 -06:00
2026-01-31 15:01:18 -06:00
2026-01-30 18:26:41 -06:00
2026-01-30 20:39:03 -06:00
2026-02-02 13:07:16 -06:00
2026-01-30 20:39:03 -06:00
2026-02-01 01:48:09 -06:00
2026-01-28 16:24:25 -06:00
2026-01-30 18:26:41 -06:00
2026-02-03 10:58:50 -06:00
2026-01-28 13:31:33 -06:00
2026-02-02 12:13:17 -06:00
2026-02-02 12:13:17 -06:00