BeMore Backend implements defense-in-depth security measures to protect user data and system integrity.
- JWT token validation (
optionalJwtAuthmiddleware) - Request ID tracking for audit trails
- Secure token storage requirements in client
CORS (Cross-Origin Resource Sharing)
// Whitelist specific origins
allowedOrigins: [
'http://localhost:5173',
'https://be-more-frontend.vercel.app',
// Environment variable support for custom origins
]Helmet Security Headers
// Content Security Policy
// X-Frame-Options: DENY
// X-Content-Type-Options: nosniff
// X-XSS-Protection enabledHTTPS/TLS
- β Enforced on production (Render, Vercel)
- β Secure cookie flags (when implemented)
Global Rate Limiter (10 min window)
- GET/other: 600 requests per IP
- POST/PUT/DELETE: 300 requests per IP
// Configuration in app.js
const limiter = rateLimit({
windowMs: 10 * 60 * 1000,
max: 600,
standardHeaders: true,
legacyHeaders: false,
});Request Size Limits
- JSON payload: 1MB limit
- Prevents denial-of-service via large payloads
Request Validation
- Zod schema validation on all API inputs
- Type checking with TypeScript
Logging & Monitoring
- Request logging via Morgan middleware
- Request ID correlation for tracing
- Error tracking via Sentry (frontend)
Environment Variables
- β
API keys in
.env(not committed) - β Database credentials not exposed
- β Port configuration via ENV
Database Security
- β Sequelize ORM prevents SQL injection
- β Parameterized queries enforced
- β Connection pooling for stability
Error Handling
- β Generic error messages to clients
- β Detailed errors logged internally only
- β Stack traces not exposed in production
Docker
# Non-root user (when implemented)
# Minimal base image
# Read-only filesystem (production)ErrorHandler System
class ErrorHandler {
handle(error, context) {
// Log with full context
// Send safe response to client
// Track error statistics
}
}Run periodic security audits:
# Check for vulnerabilities
npm audit
# Update if needed (carefully)
npm audit fix
# Force update (breaking changes possible)
npm audit fix --force| Package | Purpose | Security Status |
|---|---|---|
| express | Web framework | β Maintained |
| jsonwebtoken | JWT handling | β Maintained |
| helmet | Security headers | β Maintained |
| sequelize | ORM | β Maintained |
| @google/generative-ai | AI API client | β Maintained |
| openai | STT/TTS | β Maintained |
- Security Updates: Apply immediately
- Minor Updates: Apply weekly/monthly
- Major Updates: Test thoroughly before applying
- Beta/Dev Dependencies: Only for development
Public Endpoints (no auth)
GET /health- Status checkGET /- Root statusGET /api/errors/stats- Error statistics (monitoring only)
Protected Endpoints (JWT optional)
/api/session/*- Session management/api/stt/*- Speech-to-text/api/dashboard/*- Dashboard/api/user/*- User information
Zod Schemas
// Example validation
const SessionStartSchema = z.object({
userId: z.string().min(1),
counselorId: z.string().min(1),
});| Tier | Requests | Window | Purpose |
|---|---|---|---|
| Global | 600 | 10 min | General traffic |
| Write (POST/PUT/DELETE) | 300 | 10 min | Protect mutations |
| WebSocket | Per-connection | Session | Real-time data |
Personal Information
- User profile data (name, email)
- Session records (timestamps, content)
- Counseling notes (transcripts, analysis)
Encryption (Recommended)
- At-rest encryption for database
- In-transit encryption (TLS/HTTPS)
- Session data: [Define retention period]
- Temporary files: Cleaned up on session end (see
tempFileCleanup) - Logs: 30 days retention (configurable)
- User consent management
- Data export functionality
- Account deletion procedures
- Privacy policy linked
Before each production deployment:
- Run
npm audit- no critical/high severity issues - Review environment variables - all secrets set
- Check CORS origins - production URLs only
- Verify rate limiting - active
- Test error handling - no sensitive data exposed
- Check logs - no credentials logged
- SSL/TLS certificate valid
- Database credentials rotated
- Backup strategy verified
- Rollback plan prepared
# Check server health
curl https://api.bemore.dev/health
# Expected response
{
"status": "ok",
"uptime": 12345,
"version": "1.0.0"
}# View error statistics
curl https://api.bemore.dev/api/errors/statsMonitor for:
- β Repeated 401 errors (auth issues)
- β Repeated 429 errors (rate limit breaches)
- β Repeated 500 errors (server errors)
- β Unusual request patterns
- OWASP Top 10 assessment
- SQL injection tests (ORM prevents)
- XSS prevention (API doesn't render HTML)
- CSRF protection (token validation)
- Rate limit verification
- Authentication bypass attempts
- Authorization boundary testing
- Sensitive data exposure checks
| Version | Date | Changes |
|---|---|---|
| 1.0 | 2025-10-24 | Initial security policy |
Last Updated: 2025-11-03 Next Review: 2025-12-03 (Monthly)
π Internal Security Issues? See
SECURITY_INTERNAL.md(not in public repo)