Overview
Tresa Contafy implements multiple layers of security to protect user data and prevent common web vulnerabilities. This guide covers all security features and configuration.Security Features
Helmet.js
HTTP security headers
Rate Limiting
DDoS and brute-force protection
CORS
Cross-origin request control
JWT
Secure token-based authentication
HTTP Security Headers (Helmet)
Configuration
Helmet is enabled by default insrc/server.ts:38:
Headers Applied
Helmet automatically sets secure HTTP headers:Content-Security-Policy
Content-Security-Policy
Prevents XSS attacks by controlling resource loading:
X-Content-Type-Options
X-Content-Type-Options
Prevents MIME type sniffing:
X-Frame-Options
X-Frame-Options
Prevents clickjacking attacks:
Strict-Transport-Security
Strict-Transport-Security
Enforces HTTPS connections:
X-DNS-Prefetch-Control
X-DNS-Prefetch-Control
Controls DNS prefetching:
Custom Helmet Configuration
For custom CSP or other headers:Rate Limiting
General API Rate Limit
Protects against DDoS attacks (src/server.ts:67):
Time window in milliseconds (15 minutes)
Maximum requests per IP per window
Return rate limit info in
RateLimit-* headersAuthentication Rate Limit
Stricter limits for auth endpoints (src/server.ts:80):
Production: 5 attempts per 15 minutesDevelopment: 100 attempts per 15 minutes (for testing)
Rate Limit Headers
Clients receive rate limit information:Customizing Rate Limits
Adjust via environment variable:CORS Configuration
Default CORS Settings
CORS is configured based on environment (src/server.ts:41):
Environment-Based CORS
- Development
- Production
http://localhost:3000Multiple Origins
To allow multiple origins:JWT Authentication
Token Configuration
JWT tokens are used for authentication with short-lived access tokens:Expires: 15 minutesSecret:
JWT_SECRETUsage: API authenticationExpires: 7 daysSecret:
JWT_REFRESH_SECRETUsage: Obtaining new access tokensToken Security
Store Tokens Securely
Client-side best practices:
- Store in
httpOnlycookies (recommended) - Or use secure
localStoragewith XSS protection - Never expose tokens in URLs
Password Security
Bcrypt Hashing
Passwords are hashed with bcrypt (10 salt rounds):Password Requirements
Implement strong password requirements in your frontend:- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character
Password Reset Security
- Tokens expire: Password reset tokens expire after a set time
- One-time use: Tokens are invalidated after successful reset
- Rate limited: Reset requests are rate limited to prevent abuse
Email Verification
Required Verification
Users must verify their email before accessing protected resources:Verification Token Security
- Tokens are cryptographically random
- Tokens expire after 24 hours
- One-time use only
- Stored hashed in database
Input Validation
Express Validator
All inputs are validated usingexpress-validator:
SQL Injection Protection
Sequelize ORM provides automatic protection against SQL injection:Row-Level Security
User Data Isolation
All user data is isolated byuser_id:
Authorization Middleware
Verify resource ownership before operations:File Upload Security
File Size Limits
Uploads are limited to 10MB (src/server.ts:105):
File Type Validation
Validate file types for XML uploads:Error Handling
Production Error Messages
Error details are hidden in production (src/server.ts:144):
Never expose stack traces or internal error details in production
Security Best Practices
Use HTTPS Only
Always use HTTPS in production:
- Configure SSL certificates
- Enable HSTS headers (via Helmet)
- Redirect HTTP to HTTPS
Monitor Security Logs
Watch for suspicious activity:
- Failed authentication attempts
- Rate limit violations
- Unusual traffic patterns
Regular Security Audits
Perform periodic security reviews:
- Run
pnpm audit - Review access logs
- Test authentication flows
- Penetration testing
Security Checklist
✓ Helmet.js enabled for security headers
✓ Rate limiting configured (general + auth endpoints)
✓ CORS restricted to known origins
✓ Strong JWT secrets (32+ bytes random)
✓ Passwords hashed with bcrypt
✓ Email verification required
✓ Input validation on all endpoints
✓ SQL injection protection (Sequelize ORM)
✓ Row-level security (user_id isolation)
✓ File upload limits (10MB max)
✓ Error messages sanitized in production
✓ HTTPS enforced (HSTS header)
✓ Database SSL enabled
✓ Dependencies regularly updated
Incident Response
If a security incident occurs:Identify & Contain
- Identify affected systems
- Isolate compromised resources
- Block malicious IPs if needed
Next Steps
Monitoring
Set up monitoring and logging
Production Deployment
Deploy to production environment