e35ac6a41c
Security Enhancements: - Fix SQL injection vulnerabilities by replacing whereRaw queries with parameterized queries - Add LIKE pattern escaping to prevent SQL injection in search functionality - Implement account lockout protection (5 failed attempts = 30 min lockout) - Add comprehensive login attempt tracking and audit trail - Enhance JWT tokens with issuer validation, IP tracking, and password change detection - Add logout endpoint and session management - Prevent user enumeration with generic error messages Database Changes: - Add login_attempts table for authentication tracking - Add security columns to admin_users (password_changed_at, last_login_ip, two_factor_enabled) New Security Features: - Brute force protection with configurable lockout duration - Automatic cleanup of old login attempts - Enhanced authentication middleware with stricter validation - Monitoring scripts for security health checks All fixes are backward compatible and production-ready with rollback plans included. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
106 lines
3.5 KiB
JavaScript
106 lines
3.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Verify enhanced authentication is active and working
|
|
*/
|
|
|
|
const { db } = require('../src/database/db');
|
|
|
|
console.log('=== Verifying Enhanced Authentication Activation ===\n');
|
|
|
|
async function verifyAuth() {
|
|
const results = {
|
|
databaseTables: false,
|
|
serverConfig: false,
|
|
lockoutActive: false,
|
|
cleanupActive: false
|
|
};
|
|
|
|
try {
|
|
// 1. Check database tables
|
|
console.log('1. Checking database tables...');
|
|
const hasLoginAttempts = await db.schema.hasTable('login_attempts');
|
|
const hasSecurityColumns = await db.schema.hasColumn('admin_users', 'password_changed_at');
|
|
|
|
if (hasLoginAttempts && hasSecurityColumns) {
|
|
results.databaseTables = true;
|
|
console.log('✓ Auth tables and columns exist');
|
|
|
|
// Count attempts
|
|
const attempts = await db('login_attempts').count().first();
|
|
console.log(` Total login attempts tracked: ${attempts['count(*)'] || 0}`);
|
|
} else {
|
|
console.log('✗ Auth tables missing');
|
|
}
|
|
|
|
// 2. Check server configuration
|
|
console.log('\n2. Checking server configuration...');
|
|
const fs = require('fs');
|
|
const serverContent = fs.readFileSync('./server.js', 'utf8');
|
|
|
|
if (serverContent.includes("require('./src/routes/auth-enhanced')")) {
|
|
results.serverConfig = true;
|
|
console.log('✓ Server using enhanced auth routes');
|
|
} else {
|
|
console.log('✗ Server using original auth routes');
|
|
}
|
|
|
|
if (serverContent.includes('initializeCleanupJob')) {
|
|
results.cleanupActive = true;
|
|
console.log('✓ Cleanup job initialized');
|
|
} else {
|
|
console.log('✗ Cleanup job not initialized');
|
|
}
|
|
|
|
// 3. Test lockout functionality
|
|
console.log('\n3. Testing lockout functionality...');
|
|
const { checkAccountLockout } = require('../src/utils/authSecurity');
|
|
|
|
// Check a test account
|
|
const lockoutTest = await checkAccountLockout('lockout-test-user');
|
|
console.log(`✓ Lockout check functional: ${lockoutTest.isLocked ? 'locked' : 'not locked'}`);
|
|
results.lockoutActive = true;
|
|
|
|
// 4. Check recent activity
|
|
console.log('\n4. Recent authentication activity...');
|
|
const recentAttempts = await db('login_attempts')
|
|
.orderBy('attempt_time', 'desc')
|
|
.limit(5);
|
|
|
|
if (recentAttempts.length > 0) {
|
|
console.log('Recent login attempts:');
|
|
recentAttempts.forEach(attempt => {
|
|
const time = new Date(attempt.attempt_time).toLocaleString();
|
|
console.log(` ${time} - ${attempt.identifier} - ${attempt.success ? 'SUCCESS' : 'FAILED'}`);
|
|
});
|
|
} else {
|
|
console.log('No login attempts recorded yet');
|
|
}
|
|
|
|
// Summary
|
|
console.log('\n=== Summary ===');
|
|
const allGood = Object.values(results).every(v => v === true);
|
|
|
|
if (allGood) {
|
|
console.log('✅ Enhanced authentication is FULLY ACTIVE!');
|
|
console.log('\nFeatures enabled:');
|
|
console.log('- Account lockout protection (5 attempts)');
|
|
console.log('- Login attempt tracking');
|
|
console.log('- Enhanced token validation');
|
|
console.log('- Session management');
|
|
console.log('- Automatic cleanup of old records');
|
|
} else {
|
|
console.log('⚠️ Some features not active:');
|
|
Object.entries(results).forEach(([key, value]) => {
|
|
console.log(` ${key}: ${value ? '✓' : '✗'}`);
|
|
});
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Verification error:', error);
|
|
} finally {
|
|
await db.destroy();
|
|
}
|
|
}
|
|
|
|
verifyAuth(); |