Overview
Consensus implements multiple security layers to protect election integrity and user data. This guide covers the built-in security features and best practices for production deployments.Authentication & Authorization
Password Security
Consensus uses bcrypt for password hashing with industry-standard parameters:src/utils/password.ts
Bcrypt with 10 salt rounds provides strong protection against brute-force attacks while maintaining reasonable performance. Each password hash takes approximately 100ms to compute.
Session Management
Consensus uses secure session-based authentication with the following features:Session Data
Session data includes:
voterID: Authenticated voter identifiervoterName: Voter display nameisAdmin: Administrator flagadminUsername: Admin username if authenticated
Role Separation
Consensus enforces strict separation between administrators and voters:| Role | Capabilities | Authentication |
|---|---|---|
| Admin | Manage elections, voters, candidates, settings | Username + password via /admin/login |
| Voter | Register, view elections, cast votes | Voter ID + password via /login |
Administrators and voters use separate authentication endpoints and cannot access each other’s interfaces. Admin routes are protected by the
/admin prefix.Default Admin Account
On first startup, Consensus creates a default administrator account:src/web/server.ts:153-167
Session Secret Security
Importance
TheSESSION_SECRET is used to cryptographically sign session cookies. If compromised, attackers can forge valid sessions and impersonate users.
Requirements
Generating Secure Secrets
Container Security
Non-Root User
The Docker container runs as a non-root user for defense in depth:Dockerfile:34-35,52
Running as UID 1001 (nodejs) prevents privilege escalation attacks and limits damage if the container is compromised.
File Permissions
Files are owned by the nodejs user during the build process:Dockerfile:38-42
Read-Only Root Filesystem
For additional security, run the container with a read-only root filesystem:Only
/app/data needs write access. All other directories can be read-only.Security Scanning
Regularly scan the Docker image for vulnerabilities:Database Security
SQLite Security Features
Consensus uses SQLite with security best practices:Preventing SQL Injection
Consensus uses parameterized queries via better-sqlite3 prepared statements:Example
All database queries in Consensus use prepared statements, preventing SQL injection attacks.
Network Security
HTTPS/TLS
Consensus should always be deployed behind HTTPS in production:Firewall Configuration
Restrict network access to the Consensus container:Maintenance Mode
Consensus includes a maintenance mode feature to block voter access during updates:src/web/server.ts:108-120
Administrators can still access the system during maintenance mode to perform updates or fixes.
Security Checklist
Pre-Deployment
Secrets
- Generate strong
SESSION_SECRET(32+ characters) - Set secure
CONSENSUS_ADMIN_DEFAULT_PASSWORD - Store secrets in environment variables, not code
- Add
.env*to.gitignore
Configuration
- Set
NODE_ENV=production - Enable
cookie.secure = truefor HTTPS - Configure HTTPS reverse proxy
- Set up automatic HTTPS redirects
Container
- Run container as non-root user (default)
- Use read-only root filesystem
- Limit container capabilities
- Scan image for vulnerabilities
Post-Deployment
Initial Access
- Login as admin immediately
- Change default admin password
- Create additional admin accounts if needed
- Disable or delete default admin account
Monitoring
- Monitor application logs for errors
- Set up alerts for failed login attempts
- Review audit logs regularly
- Monitor database size and performance
Audit Logging
Consensus includes built-in audit logging for election events:src/services/observers/ElectionAuditLogger.ts
Audit logs are stored in the database and track all election lifecycle events. Review these logs regularly to detect unauthorized changes.
Security Monitoring
Failed Login Attempts
Monitor logs for repeated failed authentication:Database Access
Monitor database file access:Container Security Events
Incident Response
Suspected Breach
If you suspect a security breach:Enable Maintenance Mode
Access the admin settings and enable maintenance mode to block voter access.
Compliance Considerations
Data Protection
Consensus stores personal information (voter names, emails, passwords):- Encryption at Rest: Encrypt the database file or volume
- Encryption in Transit: Always use HTTPS
- Data Retention: Implement policies for deleting old election data
- Access Controls: Limit admin access to authorized personnel only
Election Integrity
- Vote Secrecy: Votes are anonymized after casting
- Audit Trail: All election events are logged
- Tamper Detection: Database integrity can be verified through backups
- Access Logging: Monitor who accesses election results
Next Steps
Docker Deployment
Deploy Consensus using Docker
Configuration
Configure environment variables