Overview
Memos implements multiple security layers to protect your data. This guide covers authentication mechanisms, security hardening, and best practices for production deployments.Authentication System
Memos uses a three-tier authentication system:1. JWT Access Tokens (Short-lived)
Purpose: Active user sessionsLifetime: 15 minutes
Storage: Client-side memory
Validation: Stateless (signature only)
Secret: Auto-generated UUID on first run Generation (server/auth/token.go:133-160):
2. JWT Refresh Tokens (Long-lived)
Purpose: Session persistenceLifetime: 30 days
Storage: HTTP-only cookie
Validation: Stateful (database lookup for revocation)
user_refresh_token tableValidation (server/auth/authenticator.go:60-99):
3. Personal Access Tokens (PAT)
Purpose: API integrations, automationLifetime: User-defined (or never expires)
Format:
memos_pat_<random32chars>Storage: SHA-256 hash in database Generation (server/auth/token.go:189-203):
- Only hash stored in database (token visible once at creation)
- Per-token expiration dates
- Last used timestamp tracking
- Can be revoked individually
Authentication Flow
See: server/auth/authenticator.go:133-165Secret Key Management
Secret Generation
Memos auto-generates a secret key on first run:system_setting table, key BASIC, field secret_key
Demo Mode Exception
"usememos" - never use in production!
Rotating Secret Keys
Current limitation: Memos does not support key rotation. Changing the secret will invalidate all existing JWT tokens. Future enhancement (server/auth/token.go:32-33):Security Headers
Configure reverse proxy (nginx/Caddy) to add security headers:Nginx Configuration
Caddy Configuration
HTTPS/TLS Encryption
Recommendation: Always use HTTPS in production. Memos does not have built-in TLS support. Use a reverse proxy:Option 1: Caddy (Automatic HTTPS)
Option 2: Nginx + Certbot
Option 3: Cloudflare Tunnel
Cloudflare Tunnel provides HTTPS without exposing ports:CORS Configuration
Default behavior: Memos allows all origins. For production, restrict CORS to your domain: Note: Currently not configurable via environment variables. Modify source:Public Endpoint Access Control
Some endpoints are public (no authentication required): Public endpoints (server/router/api/v1/acl_config.go:11-34):- Public methods: Allow without authentication
- Protected methods: Require valid token (JWT or PAT)
- Admin-only methods: Check user role
Database Security
SQLite
All queries use parameterized statements:
MySQL/PostgreSQL
Password Security
Hashing algorithm: Not directly visible in provided code, but follows industry standards. Best practices:- Enforce strong passwords (8+ chars, mixed case, numbers, symbols)
- Rate limit login attempts (not built-in, use reverse proxy)
- Enable 2FA (future enhancement)
Rate Limiting
Memos does not have built-in rate limiting. Implement at reverse proxy level:Nginx Rate Limiting
Caddy Rate Limiting
Firewall Configuration
UFW (Ubuntu)
firewalld (RHEL/CentOS)
Content Security Policy (CSP)
Restrict resource loading to prevent XSS:'unsafe-inline' and 'unsafe-eval' are required for React. Consider nonce-based CSP for stricter security.
Security Checklist
- Use HTTPS in production (reverse proxy)
- Set strong secret key (auto-generated, do not use demo mode)
- Restrict database access (dedicated user, minimal privileges)
- Enable database encryption at rest
- Configure firewall (block direct access to Memos port)
- Add security headers (X-Frame-Options, CSP, etc.)
- Implement rate limiting (reverse proxy)
- Regular security updates (Memos + OS + dependencies)
- Enable audit logging (reverse proxy access logs)
- Backup encryption (encrypt backup files)
- Use Personal Access Tokens for API access (not user passwords)
- Rotate PATs regularly
- Monitor failed login attempts
- Disable demo mode in production
- Review public endpoint access control
Vulnerability Reporting
If you discover a security vulnerability in Memos:- Do NOT open a public GitHub issue
- Email security concerns to: [email protected]
- Include:
- Description of vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if available)
Security Updates
Stay informed about security updates:- Watch the Memos GitHub repository
- Subscribe to release notifications
- Check CHANGELOG for security fixes
Next Steps
Architecture
Understand Memos system architecture
Backup & Restore
Backup strategies for disaster recovery
Performance Tuning
Optimize for production workloads
Deployment
Deployment guides for various platforms