Skip to content

Security: RexSixT9/gckconfessions

Security

SECURITY.md

Security Best Practices - GCK Confessions

Authentication & Authorization

✅ Implemented

  1. JWT-based Authentication

    • HttpOnly cookies prevent XSS attacks
    • Secure flag enabled in production (HTTPS only)
    • SameSite=strict prevents CSRF attacks
    • 8-hour token expiration
  2. Password Security

    • Passwords hashed with bcryptjs (cost factor: 10)
    • Constant-time comparison prevents timing attacks
    • Password cleared from memory after use
    • Failed login attempts logged
    • No user enumeration (same error for invalid email/password)
  3. Rate Limiting

    • Login attempts: 3 per 3 minutes (production)
    • Submission: 3 per 5 minutes (production)
    • Automatic IP blocking after threshold
    • Configurable per environment
  4. Session Management

    • Server-side token verification
    • Automatic logout after 8 hours
    • Cookie cleared on logout
    • No session storage in localStorage

Network Security

✅ Security Headers

X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Content-Security-Policy: (comprehensive policy)
Permissions-Policy: camera=(), microphone=(), geolocation=()
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Origin-Agent-Cluster: ?1
Strict-Transport-Security: max-age=31536000; includeSubDomains (production)

✅ CORS & Origin Validation

  • Same-origin checks on sensitive endpoints
  • Optional strict allowlist via ALLOWED_ORIGINS
  • Content-Type validation
  • Cloudflare/Vercel IP detection

✅ Optional Network Hardening

  • Optional admin surface restriction via ADMIN_IP_ALLOWLIST
  • Optional strict REFERRER_POLICY and PERMISSIONS_POLICY overrides

Data Protection

✅ Input Validation & Sanitization

  1. Server-side Validation

    • Email format validation
    • Password length limits (max 128 chars)
    • Message length limits (max 1000 chars)
    • Music field limits (max 120 chars)
    • HTML/script tag stripping
  2. Profanity Filtering

    • Configurable word list
    • Automatic censoring
  3. Bot Detection

    • User-agent analysis (isbot library)
    • Arcjet DDoS protection
    • Rate limiting per IP

✅ Database Security

  1. MongoDB Best Practices

    • Connection string in environment variables
    • Mongoose schema validation
    • Lean queries to prevent prototype pollution
    • No direct query string injection
  2. Audit Logging

    • All admin actions logged
    • IP addresses recorded
    • Timestamps for all events
    • Failed login attempts tracked

Privacy Protection

✅ Anonymous Submissions

  1. No User Tracking

    • No cookies for public users
    • No authentication required for submissions
    • IP addresses hashed before storage (optional)
  2. Data Minimization

    • Only collect necessary fields
    • No personal information required
    • Music field optional
  3. Admin Privacy

    • Admin emails not exposed in UI
    • Login attempts rate-limited
    • Session cookies httpOnly

API Security

✅ Endpoint Protection

  1. Authentication Required

    • /admin/* - Server-side token verification
    • /api/admin/* - Cookie-based auth
    • /api/confessions/* (GET/PATCH) - Admin only
    • POST /api/confessions - Public (rate-limited)
  2. Request Validation

    • Content-Type checks
    • Method validation
    • Parameter sanitization
    • Max body size limits
  3. Error Handling

    • Generic error messages (no stack traces)
    • Status codes properly set
    • Sensitive info never exposed
    • Errors logged server-side only

Environment Security

✅ Configuration Management

  1. Environment Variables

    • All secrets in .env file
    • .env excluded from git
    • .env.example provided
    • No hardcoded credentials
  2. Secret Management

    • JWT_SECRET: min 32 characters
    • ADMIN_SETUP_KEY: rotated after use
    • ARCJET_KEY: stored securely
    • MONGODB_URI: connection string protected

Deployment Security

✅ Production Checklist

  • Set NODE_ENV=production
  • Generate strong JWT_SECRET (32+ chars)
  • Enable secure cookie flag
  • Configure MongoDB IP whitelist
  • Set up Arcjet DDoS protection
  • Enable rate limiting
  • Review blocked IPs list
  • Rotate ADMIN_SETUP_KEY after initial setup
  • Enable HTTPS (required)
  • Configure CSP headers
  • Set up monitoring/alerts
  • Regular dependency updates
  • Backup strategy in place

Monitoring & Incident Response

✅ Audit Logging

Query audit logs:

// Recent admin logins
db.auditlogs.find({ action: "admin_login" }).sort({ createdAt: -1 }).limit(10);

// Failed login attempts
db.auditlogs.find({ action: "admin_login_failed" }).sort({ createdAt: -1 }).limit(10);

// Suspicious patterns
db.auditlogs.aggregate([
  { $match: { action: "admin_login_failed" } },
  { $group: { _id: "$ip", count: { $sum: 1 } } },
  { $sort: { count: -1 } }
]);

🔴 Incident Response

If suspicious activity detected:

  1. Check audit logs for patterns
  2. Add IP to BLOCKED_IPS if needed
  3. Rotate JWT_SECRET
  4. Force logout all sessions
  5. Review recent confession submissions
  6. Check MongoDB access logs
  7. Update Arcjet rules

Regular Maintenance

Weekly

  • Review audit logs
  • Check failed login attempts
  • Monitor rate limiting triggers
  • Review new confessions

Monthly

  • Update dependencies (npm audit)
  • Review security headers
  • Check Arcjet dashboard
  • Rotate admin passwords
  • Database backup verification

Quarterly

  • Rotate JWT_SECRET
  • Security audit
  • Penetration testing (if applicable)
  • Update emergency response procedures

Known Limitations

Not Implemented (Future Enhancements)

  • Two-factor authentication (2FA)
  • Email notifications on login
  • IP geolocation tracking
  • Advanced bot detection (hCaptcha)
  • Session management UI
  • Automated threat response
  • Data encryption at rest
  • Regular automated security scans

Contact

For security issues, please report to the project maintainers immediately. Do not create public GitHub issues for security vulnerabilities.


OWASP Top 10 Audit Results

Audit Date: $(date)

OWASP Category Status Notes
A01 Broken Access Control ✅ Pass JWT auth, httpOnly cookies, server-side verification
A02 Cryptographic Failures ✅ Pass bcrypt(10), secure JWT, timing-safe comparisons
A03 Injection ✅ Pass Mongoose parameterized queries, ObjectId validation
A04 Insecure Design ✅ Pass Origin validation, bot detection, honeypot fields
A05 Security Misconfiguration ✅ Pass CSP headers, X-Frame-Options, no default creds
A06 Vulnerable Components ✅ Pass npm audit clean, dependency overrides applied
A07 Auth Failures ✅ Pass Rate limiting, password policy, timing-safe login
A08 Software Integrity ✅ Pass npm integrity checks, no CDN dependencies
A09 Logging/Monitoring ✅ Pass AuditLog tracks all admin actions
A10 SSRF ✅ Pass No user-controlled URL fetching

Fixes Applied During Audit

  1. Timing-safe setup key comparison - Added safeCompare() using crypto.timingSafeEqual() to prevent timing attacks on setup key verification
  2. Removed unsafe-eval from CSP - Tightened Content-Security-Policy by removing 'unsafe-eval'
  3. Added upgrade-insecure-requests - CSP directive to force HTTPS

Last Updated: February 2026 Security Audit Status: ✅ Passed (OWASP Top 10 Compliant)

There aren't any published security advisories