Timing Attack Defense Framework
Secure Aura is a production-ready framework designed to mitigate timing attacks, username enumeration, and brute-force attempts in authentication systems. It employs quantum timing slots, constant-time operations, and statistical analysis to ensure robust security.
- Argon2id Hashing: Utilizes the PHC winner for secure password hashing.
- Constant-Time Authentication: Uses
crypto.timingSafeEqualto prevent timing leaks during verification. - Quantum Timing Defense: Responses are normalized to discrete time slots (100/150/200/250ms) to mask processing time differences.
- Distributed Attack Protection: Implements username-based rate limiting to defend against distributed attacks.
- Real-Time Detection: Statistical analysis of traffic to detect and mitigate anomalies.
- Dockerized Architecture: Fully containerized services for easy deployment and scaling.
- Docker >= 20.10.0
- Docker Compose >= 2.0.0
-
Clone the repository:
git clone https://github.com/yourusername/secure-aura.git cd secure-aura -
Start the services:
docker-compose up -d
-
Verify the services are running:
docker-compose logs -f
The system is composed of the following services:
βββββββββββββββββββββββββββββββββββββββββββββββ
β Nginx Gateway (8080) β
β Rate Limiting + Routing β
ββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββ
β β
ββββββββΌβββββββ ββββββββΌβββββββββββ
β Auth Serviceβ β Monitor Service β
β (Node.js) β β (Node.js) β
β :8000 β β :8001 β
ββββββββ¬βββββββ ββββββββ¬βββββββββββ
β β
ββββββββΌβββββββββββββββββββΌβββββββ
β PostgreSQL Database β
β Users | Auth Logs | Events β
ββββββββββββββββββ¬βββββββββββββββββ
β
ββββββββββΌβββββββββ
β Redis Cache β
β Rate Limits β
βββββββββββββββββββ
- Auth Service: Handles user registration, login, and token generation with timing protections.
- Monitor Service: Analyzes traffic patterns and manages security events.
- Dashboard: Provides a real-time UI for monitoring system health and threats.
- PostgreSQL: Stores user data and logs.
- Redis: Manages rate limits and distributed state.
Responses are padded or delayed to match specific "quantum" time slots. This prevents attackers from inferring information based on response times.
// Quantum timing - fixed time slots instead of random delays
const quantumSlots = [100, 150, 200, 250]; // milliseconds
const targetTime = quantumSlots[cryptoRandomIndex];The system performs dummy hash operations when a user is not found, ensuring that the response time for invalid users matches that of valid users.
if (!user) {
// Execute dummy Argon2 hash - same timing as real verification
await UsernameEnumerationDefense.generateDummyHash();
}- Rate Limiting: Limits login attempts per IP and per username.
- Distributed Detection: Correlates attacks across multiple IPs targeting the same account.
POST /api/auth/register: Register a new user.POST /api/auth/login: Authenticate a user.POST /api/auth/verify-token: Verify a JWT.GET /api/users/me: Get current user details.
GET /api/monitor/stats: Get system statistics.GET /api/monitor/events: List security events.GET /api/monitor/timing-analysis: Retrieve timing analysis data.
Configuration is managed via environment variables in the .env file.
# Database
DATABASE_URL=postgresql://secureaura:secureaura_pass_2024@postgres:5432/timing_defense
# Redis
REDIS_URL=redis://:redis_secure_2024@redis:6379/0
# JWT
JWT_SECRET=your-super-secret-key-change-in-production
JWT_EXPIRATION=3600
# Timing Defense
MIN_NOISE_MS=50 # Not used - quantum slots instead
MAX_NOISE_MS=200 # Not used - quantum slots instead
QUANTUM_SLOTS=100,150,200,250 # Fixed timing intervals (ms)
# Detection
DETECTION_THRESHOLD=0.75
ANALYSIS_WINDOW=300
# Rate Limiting
USERNAME_RATE_LIMIT=20 # Max attempts per username in 5 min
IP_RATE_LIMIT=30 # Max login attempts per IP in 1 minConfigured in services/auth-service/src/middleware.js:
// IP-based rate limits
requestsPerMinute: 200 // Global limit
loginAttemptsPerMinute: 30 // Login endpoint
registrationPerMinute: 10 // Registration endpoint
// Username-based rate limits (NEW - prevents distributed attacks)
usernameAttemptsPerWindow: 20 // Per username in 5 minutes (from ANY IP)Configured in services/auth-service/src/constantTimeAuth.js:
// Fixed time slots (not random)
quantumSlots: [100, 150, 200, 250] // milliseconds
// Threat-adaptive slots
lowThreatSlots: [100, 150] // Threat level 0.0-0.3
mediumThreatSlots: [150, 200] // Threat level 0.3-0.7
highThreatSlots: [200, 250, 300] // Threat level 0.7-1.0secure-aura/
βββ services/
β βββ auth-service/ # Node.js authentication API
β β βββ src/
β β β βββ server.js # Express app
β β β βββ constantTimeAuth.js # Timing-safe crypto
β β β βββ database.js # PostgreSQL models
β β β βββ middleware.js # Rate limiting
β β βββ Dockerfile
β β βββ package.json
β βββ monitor-service/ # Node.js monitoring API
β β βββ src/
β β β βββ server.js # Express app
β β β βββ detector.js # Statistical analysis
β β β βββ database.js # Data access layer
β β βββ Dockerfile
β β βββ package.json
β βββ dashboard/ # React frontend
β βββ src/
β β βββ App.js # Main component
β β βββ index.js
β β βββ styles/
β βββ public/
β βββ Dockerfile
β βββ package.json
βββ database/
β βββ init.sql # PostgreSQL schema
βββ nginx/
β βββ nginx.conf # Reverse proxy config
β βββ ssl/ # SSL certificates
βββ tests/
β βββ quick-test.sh # Full API test
β βββ attack-*.sh # Attack simulations
β βββ demo-attack-detection.sh
β βββ verify-protection.sh
β βββ CURL_EXAMPLES.md
βββ postman/
β βββ Secure-Aura-API.postman_collection.json
β βββ Secure-Aura-Local.postman_environment.json
βββ docs/
β βββ API.md # API documentation
β βββ architecture/
β β βββ SYSTEM_ARCHITECTURE.md
β βββ guides/
β βββ DEPLOYMENT.md
βββ scripts/
β βββ simulate_attack.sh
β βββ test_api.sh
βββ docker-compose.yml # Service orchestration
βββ start.sh # Quick start script
βββ README.md
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f auth-service
docker-compose logs -f monitor-service
# Last 100 lines
docker-compose logs --tail=100 auth-service# Connect to PostgreSQL
docker-compose exec postgres psql -U secureaura -d timing_defense
# View recent auth attempts
SELECT username_attempted, success, processing_time_ms, created_at
FROM auth_logs
ORDER BY created_at DESC LIMIT 10;
# View security events
SELECT event_type, severity, ip_address, confidence_score
FROM security_events
WHERE resolved = false
ORDER BY created_at DESC;# Connect to Redis
docker-compose exec redis redis-cli -a redis_secure_2024
# Check rate limits
KEYS ratelimit:*
# Check threat levels
KEYS threat:ip:*- Change all default passwords
- Generate strong JWT secret:
openssl rand -hex 32 - Enable SSL/TLS in Nginx
- Set
ENVIRONMENT=production - Increase
MAX_NOISE_MSto 300+ - Configure firewall rules
- Set up log aggregation
- Enable database backups
# Build and start
docker-compose up -d --build
# Scale services
docker-compose up -d --scale auth-service=3
docker-compose up -d --scale monitor-service=2
# Update single service
docker-compose up -d --no-deps --build auth-service