Skip to content

Security: neverinfamous/memory-journal-mcp

SECURITY.md

πŸ”’ Security Guide

The Memory Journal MCP server implements comprehensive security measures to protect your personal journal data.

πŸ›‘οΈ Database Security

Native SQLite Architecture

The server uses the native better-sqlite3 driver with sqlite-vec for vector operations, running directly against the filesystem.

  • βœ… PRAGMA foreign_keys = ON β€” enforces referential integrity and ON DELETE CASCADE
  • βœ… Parameterized queries β€” all user input bound via ? placeholders
  • βœ… WAL journal mode β€” high concurrency with non-blocking reads (PRAGMA journal_mode = WAL)
  • βœ… Synchronous Normal β€” optimized durability and performance (PRAGMA synchronous = NORMAL)

File Permissions (Docker)

  • βœ… Data directory: 700 (full access for owner only) in Docker
  • βœ… Non-root user (appuser:appgroup) owns data directory

πŸ” Input Validation

Content Limits

  • Journal entries: 50,000 characters maximum
  • Tags: 100 characters maximum
  • Entry types: 50 characters maximum
  • Significance types: 50 characters maximum
  • HTTP request body: 1MB maximum (prevents memory exhaustion)

Character Handling

Tags are stored as-is via parameterized queries. Special characters in tags are safely handled by the database layer and do not pose injection risks.

SQL Injection Prevention

  • βœ… Parameterized queries used throughout
  • βœ… Input validation via Zod schemas before database operations
  • βœ… Warning system for potentially dangerous content patterns
  • βœ… FTS5 / LIKE pattern sanitization (escapes %, _, \ wildcards and handles FTS5 syntax errors gracefully)
  • βœ… Date format whitelisting (prevents strftime injection)

Path Traversal Protection

  • βœ… Backup filenames validated - rejects /, \, .. in paths
  • βœ… Typed security errors with consistent error codes

🌐 HTTP Transport Security

When running in HTTP mode (--transport http), the following security measures apply:

CORS Configuration

  • βœ… Configurable multiple origins via comma-separated --cors-origin flag or MCP_CORS_ORIGIN environment variable
  • βœ… Exact-match verification (no wildcard matching for custom domains)
  • ⚠️ Default: * (allow all origins) for backward compatibility
  • πŸ”’ Recommended: Set specific origins for production deployments
# Restrict CORS to specific origins
memory-journal-mcp --transport http --cors-origin "http://localhost:3000,https://my-app.com"

# Or via environment variable
export MCP_CORS_ORIGIN="http://localhost:3000,https://my-app.com"

Security Headers & Protections

  • βœ… DNS Rebinding Protection β€” hostHeaderValidation middleware prevents CVE-2025-66414
  • βœ… Strict-Transport-Security (HSTS) β€” max-age=31536000; includeSubDomains (opt-in via --enable-hsts)
  • βœ… X-Content-Type-Options: nosniff β€” prevents MIME sniffing
  • βœ… X-Frame-Options: DENY β€” prevents clickjacking
  • βœ… Content-Security-Policy: default-src 'none'; frame-ancestors 'none' β€” prevents XSS and framing
  • βœ… Cache-Control: no-store, no-cache, must-revalidate β€” prevents caching of sensitive journal data
  • βœ… Referrer-Policy: no-referrer β€” prevents referrer leakage
  • ⚠️ CORS wildcard warning β€” server logs a warning when CORS origin is *

Rate Limiting & Timeouts

  • βœ… Built-in Rate Limiting β€” 100 requests/minute per IP (sliding window with Retry-After header)
  • βœ… HTTP Timeouts β€” Request timeout (120s), keep-alive timeout (65s), headers timeout (66s)

Session Management (Stateful Mode)

  • βœ… UUID-based session IDs (cryptographically random)
  • βœ… 30-minute session timeout - idle sessions automatically expired
  • βœ… 5-minute sweep interval - periodic cleanup of abandoned sessions
  • βœ… Explicit session termination via DELETE /mcp

Request Size Limits

  • βœ… 1MB body limit on JSON requests (prevents memory exhaustion DoS)

πŸ™ GitHub Token Security

Token Handling

  • βœ… Environment variables only - tokens never stored in config files
  • βœ… Error message scrubbing - Authorization headers stripped from error logs
  • βœ… Optional integration - server works fully offline without GitHub token
  • βœ… Minimal scopes - only requires repo, project, read:org

Environment Variables

# Required for GitHub features
GITHUB_TOKEN=ghp_...            # GitHub personal access token

# Optional
GITHUB_ORG_TOKEN=ghp_...        # For organization projects
PROJECT_REGISTRY='{"my-repo":{"path":"/path/to/repo","project_number":1}}'  # Multi-project routing
DEFAULT_PROJECT_NUMBER=1         # Default project for issue assignment
MCP_CORS_ORIGIN=*               # CORS origin (default: *)
MCP_HOST=localhost               # Server bind host
AUTO_REBUILD_INDEX=true          # Rebuild vector index on startup

🐳 Docker Security

Non-Root User

  • βœ… Dedicated user: appuser (UID 1001) with minimal privileges
  • βœ… Restricted group: appgroup (GID 1001)
  • βœ… Restricted data directory: 700 permissions

Container Hardening

  • βœ… Minimal base image: node:24-alpine
  • βœ… Multi-stage build: Build dependencies not in production image
  • βœ… Process isolation from host system
  • βœ… No shell access needed for production

Volume Mounting Security

# Secure volume mounting
docker run -v ./data:/app/data:rw,noexec,nosuid,nodev memory-journal-mcp

Resource Limits

# Apply resource limits
docker run --memory=1g --cpus=1 memory-journal-mcp

πŸ” Data Privacy

Local-First Architecture

  • βœ… No external services: All processing happens locally
  • βœ… No telemetry: No data sent to external servers
  • βœ… Full data ownership: SQLite database stays on your machine
  • βœ… Semantic search: ML model runs locally via @huggingface/transformers

Context Security

  • βœ… Git context: Only reads local repository information
  • βœ… No sensitive data: Doesn't access private keys or credentials
  • βœ… Optional GitHub integration: Only if explicitly configured with token

πŸ”„ CI/CD Security

  • βœ… CodeQL analysis - automated static analysis on push/PR
  • βœ… Trivy container scanning - Docker image vulnerability detection
  • βœ… TruffleHog + Gitleaks - secret scanning on push/PR
  • βœ… npm audit - dependency vulnerability checking
  • βœ… Dependabot - automated dependency update PRs

🚨 Security Best Practices

For Users

  1. Set a CORS origin when exposing the HTTP transport on a network
  2. Keep Node.js updated: Use Node.js 24+ (LTS)
  3. Secure host system: Ensure your host machine is secure
  4. Regular backups: Use the backup_journal tool or back up your .db file
  5. Limit network access: Don't expose the HTTP transport to untrusted networks
  6. Use resource limits: Apply Docker --memory and --cpus limits

For Developers

  1. Regular updates: Keep Node.js and npm dependencies updated
  2. Security scanning: Regularly scan Docker images for vulnerabilities
  3. Code review: All database operations use parameterized queries
  4. Input validation: All tool inputs validated via Zod schemas

πŸ“‹ Security Checklist

  • Foreign key enforcement (PRAGMA foreign_keys = ON)
  • Input validation and length limits (Zod schemas)
  • Parameterized SQL queries
  • SQL injection detection heuristics (defense-in-depth)
  • Path traversal protection (assertNoPathTraversal)
  • FTS5 / LIKE pattern sanitization (sanitizeSearchQuery)
  • Date format whitelisting (validateDateFormatPattern)
  • HTTP body size limit (1MB)
  • Configurable CORS multi-origin with exact-match enforcement
  • HTTP timeouts and built-in rate limiter (100 req/min)
  • DNS rebinding protection and strict HSTS
  • Security headers (CSP, X-Content-Type-Options, X-Frame-Options, Cache-Control, Referrer-Policy, Permissions-Policy)
  • Session timeout (30 minutes)
  • Non-root Docker user
  • Multi-stage Docker build
  • Local-first data architecture
  • GitHub token error scrubbing
  • CI/CD security pipeline (CodeQL, Trivy, secret scanning)
  • Comprehensive security documentation

🚨 Reporting Security Issues

If you discover a security vulnerability, please:

  1. Do not open a public GitHub issue
  2. Contact the maintainers privately
  3. Provide detailed information about the vulnerability
  4. Allow time for the issue to be addressed before public disclosure

πŸ”„ Security Updates

  • Container updates: Rebuild Docker images when base images are updated
  • Dependency updates: Keep npm packages updated via npm audit and Dependabot
  • Database maintenance: Run ANALYZE and PRAGMA optimize regularly
  • Security patches: Apply host system security updates

The Memory Journal MCP server is designed with security-first principles to protect your personal journal data while maintaining excellent performance and usability.

There aren’t any published security advisories