This document describes the security model and best practices for RAG-Vault.
When the RAG_API_KEY environment variable is set, all API endpoints require authentication.
Supported methods:
Authorization: Bearer <key>Authorization: ApiKey <key>X-API-Key: <key>header
Local-only mode: If RAG_API_KEY is not set, authentication is disabled for local development.
API key validation uses Node.js crypto.timingSafeEqual with padding to prevent timing attacks and length leaks.
CORS is configured via the CORS_ORIGINS environment variable.
Default origins (localhost only):
http://localhost:5173http://localhost:3000http://127.0.0.1:5173http://127.0.0.1:3000
Custom configuration:
- Comma-separated list:
CORS_ORIGINS=https://app.example.com,https://admin.example.com - Allow all (not recommended):
CORS_ORIGINS=*
In-memory rate limiting protects against abuse:
| Setting | Default | Environment Variable |
|---|---|---|
| Window | 1 minute | RATE_LIMIT_WINDOW_MS |
| Max requests | 100 | RATE_LIMIT_MAX_REQUESTS |
Rate limit headers are included in responses:
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Window reset timestamp
The HTTP server uses Helmet to set security headers:
- Content-Security-Policy: Restricts resource loading
- X-Content-Type-Options: Prevents MIME sniffing
- X-Frame-Options: Prevents clickjacking
- X-XSS-Protection: Legacy XSS protection
- Strict-Transport-Security: HTTPS enforcement (when behind HTTPS)
- Extension check: Only allowed extensions (
.pdf,.docx,.txt,.md,.html,.json) - MIME type check: Validates Content-Type header
- Magic byte validation: Uses file-type to verify actual file content
- Size limit: 100MB maximum
Database scanning is restricted to paths within ALLOWED_SCAN_ROOTS:
- Default: User's home directory
- Custom:
ALLOWED_SCAN_ROOTS=/path/one,/path/two
Symlinks are resolved before path validation to prevent traversal attacks.
The following dependency overrides are configured in package.json:
| Package | Minimum Version | Reason |
|---|---|---|
tar |
>=7.5.4 |
CVE fixes for path traversal |
hono |
>=4.11.4 |
Security patches |
diff |
>=4.0.4 |
Security patches |
# Check for vulnerabilities
pnpm audit
# Auto-fix where possible
pnpm audit:fixAPI requests timeout after 30 seconds to prevent resource exhaustion:
- Returns
503 Service UnavailablewithREQUEST_TIMEOUTerror code - Protects against slow loris and similar attacks
- Always set
RAG_API_KEYin production - Configure specific CORS origins instead of
* - Use HTTPS with a reverse proxy (nginx, Caddy)
- Set
NODE_ENV=productionto disable stack traces in errors - Monitor rate limit headers for abuse patterns
- Use
.env.exampleas a template for local configuration - Never commit
.envfiles with secrets - Run
pnpm auditbefore deploying
Please report security vulnerabilities to the repository maintainer via GitHub Security Advisories or email.
Do not create public issues for security vulnerabilities.