This document describes the security measures implemented in Cortex and how to maintain them.
All tool inputs are validated before processing:
| Tool | Validated Fields | Max Lengths |
|---|---|---|
cortex__query |
query, sources, limit | query: 10,000 chars |
cortex__recall |
context, type | context: 5,000 chars |
cortex__reflect |
topic, depth | topic: 1,000 chars |
cortex__infer |
concepts, includeMemories | concept: 1,000 chars each |
cortex__learn |
insight, context, type, tags | insight: 50,000 chars |
cortex__consolidate |
scope, type, dryRun | - |
Protection Against:
- Command injection
- Path traversal
- Buffer overflow
- Invalid type coercion
Prevents runaway API costs with tiered limits:
| Tool Type | Per Minute | Per Hour | Per Day |
|---|---|---|---|
| Haiku (query, recall) | 30 | 300 | 1,000 |
| Sonnet (reflect, infer, learn) | 10-15 | 60-100 | 200-300 |
| Sonnet (consolidate) | 5 | 20 | 50 |
Features:
- Sliding window algorithm
- 1.5x burst allowance
- 60-second cooldown on limit breach
- Environment variable override:
CORTEX_RATE_LIMIT=false
All operations are logged to JSONL files:
Log Location: ~/.claude/memory/logs/cortex-YYYY-MM-DD.jsonl
Logged Events:
tool_call_start/tool_call_end/tool_call_errorrate_limit_hitvalidation_failureresource_accessprompt_accesssession_start/session_end
Features:
- Automatic log rotation (10MB max)
- Keeps last 5 rotated files
- Sensitive field redaction
- Correlation IDs for request tracing
Environment Variables:
CORTEX_AUDIT=false- Disable loggingCORTEX_LOG_LEVEL=DEBUG|INFO|WARN|ERROR- Set log levelCORTEX_AUDIT_CONSOLE=true- Echo to stderr
Optional encryption for sensitive memory data:
Algorithm: AES-256-GCM (authenticated encryption) Key Derivation: PBKDF2 with SHA-512, 100,000 iterations
Setup:
# Generate a secret
node -e "console.log(require('./core/encryption.cjs').generateSecret())"
# Set the secret
export CORTEX_ENCRYPTION_SECRET="your-base64-secret"Usage:
const { encrypt, decrypt } = require('./core/encryption.cjs');
const encrypted = encrypt('sensitive data');
const decrypted = decrypt(encrypted);-
npm audit - Check for known vulnerabilities
cd ~/.claude/memory npm audit
-
snyk - Deep dependency scanning
npm install -g snyk snyk test -
eslint-plugin-security - Static code analysis
npm install --save-dev eslint-plugin-security # Add to .eslintrc: plugins: ['security'] -
retire.js - Detect outdated libraries
npm install -g retire retire --path .
Run periodically (recommended: weekly):
- Dependencies: Run
npm auditand update vulnerable packages - API Key: Verify
ANTHROPIC_API_KEYis not hardcoded - Log Files: Check logs don't contain sensitive data
- Permissions: Verify file permissions on
~/.claude/memory/ - Rate Limits: Review rate limit stats for anomalies
- Encryption: Verify encryption secret is not committed
Trusted:
- Claude Code client
- Local file system
- Environment variables
Untrusted:
- Tool input arguments (always validated)
- Resource URIs (resolved and checked)
- Prompt arguments (sanitized)
| Code | Category | Description |
|---|---|---|
| CORTEX_E200 | tool | Invalid tool arguments |
| CORTEX_E310 | rate-limit | Rate limit exceeded |
| CORTEX_E311 | rate-limit | Hourly limit exceeded |
| CORTEX_E312 | rate-limit | Daily limit exceeded |
| CORTEX_E313 | rate-limit | Tool in cooldown |
| CORTEX_E500 | encryption | Encryption operation failed |
| CORTEX_E501 | encryption | Decryption failed |
| CORTEX_E502 | encryption | Encryption not configured |
If you suspect a security issue:
- Disable the server: Remove from
~/.claude.json - Review logs: Check
~/.claude/memory/logs/ - Rotate API key: Generate new key in Anthropic console
- Rotate encryption secret: Generate new secret, re-encrypt data
- Report: File issue at repository (do not include sensitive data)
| Environment Variable | Purpose | Default |
|---|---|---|
ANTHROPIC_API_KEY |
API authentication | Required |
CORTEX_RATE_LIMIT |
Enable rate limiting | true |
CORTEX_AUDIT |
Enable audit logging | true |
CORTEX_LOG_LEVEL |
Minimum log level | INFO |
CORTEX_AUDIT_CONSOLE |
Echo logs to stderr | false |
CORTEX_ENCRYPTION_SECRET |
Encryption key (base64) | Not set |
- v1.0.0: Initial security implementation
- Input validation for all 6 tools
- Rate limiting with sliding window
- JSONL audit logging with rotation
- Optional AES-256-GCM encryption