v3/implementation/adrs/ADR-013-core-security-module.md
Implemented ✅
2026-01-05
The v2 codebase had critical security vulnerabilities identified in the security audit:
| Issue | Severity | Description |
|---|---|---|
| CVE-2 | Critical | SHA-256 password hashing with hardcoded salt |
| CVE-3 | Critical | Hardcoded default admin/service credentials |
| HIGH-1 | High | Command injection via shell:true in spawn() |
| HIGH-2 | High | Path traversal via unvalidated file paths |
These vulnerabilities required a complete security module rewrite for v3.
Create @claude-flow/security package with defense-in-depth approach:
Implementation: password-hasher.ts
// Before (vulnerable)
createHash('sha256').update(password + 'salt').digest('hex');
// After (secure)
await bcrypt.hash(password, 12); // Adaptive, per-user salt
Implementation: credential-generator.ts
// Before (vulnerable)
passwordHash: createHash('sha256').update('admin123' + 'salt');
// After (secure)
crypto.randomBytes(32).toString('base64url');
Implementation: safe-executor.ts
// Before (vulnerable)
spawn('npx', args, { shell: true });
// After (secure)
execFile(command, args); // No shell interpretation
Implementation: path-validator.ts
// Before (vulnerable)
fs.readFile(userPath); // No validation
// After (secure)
const safe = await pathValidator.validate(userPath);
if (!safe.valid) throw new Error('Path traversal detected');
fs.readFile(safe.resolvedPath);
Implementation: input-validator.ts
Implementation: token-generator.ts
Test Date: 2026-01-05
| Component | Tests | Status |
|---|---|---|
| password-hasher | 52 | ✅ Pass |
| credential-generator | 55 | ✅ Pass |
| safe-executor | 77 | ✅ Pass |
| path-validator | 70 | ✅ Pass |
| input-validator | 58 | ✅ Pass |
| token-generator | 78 | ✅ Pass |
| integration | 20 | ✅ Pass |
| acceptance | 34 | ✅ Pass |
Total: 444/444 tests passing
95% test coverage
import { createSecurityModule } from '@claude-flow/security';
const security = createSecurityModule({
projectRoot: process.cwd(),
hmacSecret: process.env.HMAC_SECRET!,
bcryptRounds: 12,
allowedCommands: ['git', 'npm', 'npx', 'node'],
});
// Password hashing
const hash = await security.passwordHasher.hash('password');
const valid = await security.passwordHasher.verify('password', hash);
// Safe command execution
const result = await security.safeExecutor.execute('git', ['status']);
// Path validation
const pathResult = await security.pathValidator.validate(userPath);
if (!pathResult.valid) throw new Error(pathResult.error);
// Token generation
const token = security.tokenGenerator.generateAccessToken('user-123', 3600);
v3/implementation/security/SECURITY_AUDIT_REPORT.mdv3/@claude-flow/security/src/CVE-REMEDIATION.ts