memory-journal-mcp 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.dockerignore +131 -122
  2. package/.gitattributes +29 -0
  3. package/.github/workflows/docker-publish.yml +1 -1
  4. package/.github/workflows/lint-and-test.yml +1 -2
  5. package/.github/workflows/secrets-scanning.yml +0 -1
  6. package/.github/workflows/security-update.yml +6 -6
  7. package/.vscode/settings.json +17 -15
  8. package/CHANGELOG.md +1065 -11
  9. package/DOCKER_README.md +51 -33
  10. package/Dockerfile +14 -12
  11. package/README.md +68 -33
  12. package/SECURITY.md +225 -220
  13. package/dist/cli.js +7 -0
  14. package/dist/cli.js.map +1 -1
  15. package/dist/constants/ServerInstructions.d.ts +1 -1
  16. package/dist/constants/ServerInstructions.d.ts.map +1 -1
  17. package/dist/constants/ServerInstructions.js +70 -26
  18. package/dist/constants/ServerInstructions.js.map +1 -1
  19. package/dist/constants/icons.d.ts +2 -0
  20. package/dist/constants/icons.d.ts.map +1 -1
  21. package/dist/constants/icons.js +6 -0
  22. package/dist/constants/icons.js.map +1 -1
  23. package/dist/database/SqliteAdapter.d.ts +51 -10
  24. package/dist/database/SqliteAdapter.d.ts.map +1 -1
  25. package/dist/database/SqliteAdapter.js +143 -43
  26. package/dist/database/SqliteAdapter.js.map +1 -1
  27. package/dist/filtering/ToolFilter.d.ts +1 -1
  28. package/dist/filtering/ToolFilter.d.ts.map +1 -1
  29. package/dist/filtering/ToolFilter.js +7 -1
  30. package/dist/filtering/ToolFilter.js.map +1 -1
  31. package/dist/github/GitHubIntegration.d.ts +74 -2
  32. package/dist/github/GitHubIntegration.d.ts.map +1 -1
  33. package/dist/github/GitHubIntegration.js +508 -7
  34. package/dist/github/GitHubIntegration.js.map +1 -1
  35. package/dist/handlers/prompts/index.js +1 -0
  36. package/dist/handlers/prompts/index.js.map +1 -1
  37. package/dist/handlers/resources/index.d.ts.map +1 -1
  38. package/dist/handlers/resources/index.js +257 -13
  39. package/dist/handlers/resources/index.js.map +1 -1
  40. package/dist/handlers/tools/index.d.ts.map +1 -1
  41. package/dist/handlers/tools/index.js +595 -8
  42. package/dist/handlers/tools/index.js.map +1 -1
  43. package/dist/server/McpServer.d.ts +2 -0
  44. package/dist/server/McpServer.d.ts.map +1 -1
  45. package/dist/server/McpServer.js +69 -26
  46. package/dist/server/McpServer.js.map +1 -1
  47. package/dist/types/index.d.ts +97 -0
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/index.js.map +1 -1
  50. package/dist/utils/logger.d.ts +1 -0
  51. package/dist/utils/logger.d.ts.map +1 -1
  52. package/dist/utils/logger.js +8 -1
  53. package/dist/utils/logger.js.map +1 -1
  54. package/dist/utils/progress-utils.d.ts +18 -3
  55. package/dist/utils/progress-utils.d.ts.map +1 -1
  56. package/dist/utils/progress-utils.js.map +1 -1
  57. package/dist/utils/security-utils.d.ts +91 -0
  58. package/dist/utils/security-utils.d.ts.map +1 -0
  59. package/dist/utils/security-utils.js +184 -0
  60. package/dist/utils/security-utils.js.map +1 -0
  61. package/dist/vector/VectorSearchManager.d.ts +2 -1
  62. package/dist/vector/VectorSearchManager.d.ts.map +1 -1
  63. package/dist/vector/VectorSearchManager.js +100 -34
  64. package/dist/vector/VectorSearchManager.js.map +1 -1
  65. package/docker-compose.yml +46 -37
  66. package/mcp-config-example.json +0 -2
  67. package/package.json +21 -14
  68. package/releases/v4.3.1.md +69 -0
  69. package/releases/v4.4.0.md +120 -0
  70. package/server.json +3 -3
  71. package/src/cli.ts +11 -0
  72. package/src/constants/ServerInstructions.ts +70 -26
  73. package/src/constants/icons.ts +7 -0
  74. package/src/database/SqliteAdapter.ts +165 -44
  75. package/src/filtering/ToolFilter.ts +7 -1
  76. package/src/github/GitHubIntegration.ts +588 -8
  77. package/src/handlers/prompts/index.ts +1 -0
  78. package/src/handlers/resources/index.ts +318 -12
  79. package/src/handlers/tools/index.ts +686 -13
  80. package/src/server/McpServer.ts +79 -37
  81. package/src/types/index.ts +98 -0
  82. package/src/utils/logger.ts +10 -1
  83. package/src/utils/progress-utils.ts +17 -6
  84. package/src/utils/security-utils.ts +205 -0
  85. package/src/vector/VectorSearchManager.ts +110 -39
  86. package/tests/constants/icons.test.ts +102 -0
  87. package/tests/constants/server-instructions.test.ts +549 -0
  88. package/tests/database/sqlite-adapter.bench.ts +63 -0
  89. package/tests/database/sqlite-adapter.test.ts +555 -0
  90. package/tests/filtering/tool-filter.test.ts +266 -0
  91. package/tests/github/github-integration.test.ts +1024 -0
  92. package/tests/handlers/github-resource-handlers.test.ts +473 -0
  93. package/tests/handlers/github-tool-handlers.test.ts +556 -0
  94. package/tests/handlers/prompt-handlers.test.ts +91 -0
  95. package/tests/handlers/resource-handlers.test.ts +339 -0
  96. package/tests/handlers/tool-handlers.test.ts +497 -0
  97. package/tests/handlers/vector-tool-handlers.test.ts +238 -0
  98. package/tests/security/sql-injection.test.ts +347 -0
  99. package/tests/server/mcp-server.bench.ts +55 -0
  100. package/tests/server/mcp-server.test.ts +675 -0
  101. package/tests/utils/logger.test.ts +180 -0
  102. package/tests/utils/mcp-logger.test.ts +212 -0
  103. package/tests/utils/progress-utils.test.ts +156 -0
  104. package/tests/utils/security-utils.test.ts +82 -0
  105. package/tests/vector/vector-search-manager.test.ts +335 -0
  106. package/tests/vector/vector-search.bench.ts +53 -0
  107. package/vitest.config.ts +15 -0
  108. package/.github/workflows/DOCKER_DEPLOYMENT_SETUP.md +0 -387
  109. package/.github/workflows/dependabot-auto-merge.yml +0 -42
package/SECURITY.md CHANGED
@@ -1,220 +1,225 @@
1
- # 🔒 Security Guide
2
-
3
- The Memory Journal MCP server implements comprehensive security measures to protect your personal journal data.
4
-
5
- ## 🛡️ **Database Security**
6
-
7
- ### **WAL Mode Enabled**
8
-
9
- - ✅ **Write-Ahead Logging (WAL)** enabled for better concurrency and crash recovery
10
- - ✅ **Atomic transactions** ensure data consistency
11
- - ✅ **Better performance** with concurrent read/write operations
12
-
13
- ### **Optimized PRAGMA Settings**
14
-
15
- ```sql
16
- PRAGMA foreign_keys = ON -- Enforce referential integrity
17
- PRAGMA journal_mode = WAL -- Enable WAL mode
18
- PRAGMA synchronous = NORMAL -- Balance safety and performance
19
- PRAGMA cache_size = -64000 -- 64MB cache for better performance
20
- PRAGMA mmap_size = 268435456 -- 256MB memory-mapped I/O
21
- PRAGMA temp_store = MEMORY -- Store temp tables in memory
22
- PRAGMA busy_timeout = 30000 -- 30-second timeout for busy database
23
- ```
24
-
25
- ### **File Permissions**
26
-
27
- - ✅ **Database files**: `600` (read/write for owner only)
28
- - ✅ **Data directory**: `700` (full access for owner only)
29
- - ✅ **Automatic permission setting** on database creation
30
-
31
- ## 🔐 **Input Validation**
32
-
33
- ### **Content Limits**
34
-
35
- - **Journal entries**: 50,000 characters maximum
36
- - **Tags**: 100 characters maximum
37
- - **Entry types**: 50 characters maximum
38
- - **Significance types**: 50 characters maximum
39
-
40
- ### **Character Filtering**
41
-
42
- Dangerous characters are blocked in tags:
43
-
44
- - `<` `>` `"` `'` `&` `\x00`
45
-
46
- ### **SQL Injection Prevention**
47
-
48
- - ✅ **Parameterized queries** used throughout
49
- - ✅ **Input validation** before database operations
50
- - ✅ **Warning system** for potentially dangerous content patterns
51
-
52
- ## 🐳 **Docker Security**
53
-
54
- ### **Non-Root User**
55
-
56
- - ✅ **Dedicated user**: `appuser` with minimal privileges
57
- - ✅ **No shell access**: `/bin/false` shell for security
58
- - ✅ **Restricted home directory**: `/app/user`
59
-
60
- ### **File System Security**
61
-
62
- - **Minimal base image**: `python:3.11-slim`
63
- - ✅ **Restricted data directory**: `700` permissions
64
- - **Volume mounting**: Data persists outside container
65
-
66
- ### **Container Isolation**
67
-
68
- - **Process isolation** from host system
69
- - ✅ **Network isolation** (no external network access needed)
70
- - ✅ **Resource limits** can be applied via Docker
71
-
72
- ## 🔍 **Data Privacy**
73
-
74
- ### **Local-First Architecture**
75
-
76
- - ✅ **No external services**: All processing happens locally
77
- - ✅ **No telemetry**: No data sent to external servers
78
- - **Full data ownership**: SQLite database stays on your machine
79
-
80
- ### **Context Bundle Security**
81
-
82
- - ✅ **Git context**: Only reads local repository information
83
- - **No sensitive data**: Doesn't access private keys or credentials
84
- - ✅ **Optional GitHub integration**: Only if explicitly configured
85
-
86
- ## 🚨 **Security Best Practices**
87
-
88
- ### **For Users**
89
-
90
- 1. **Keep Docker updated**: Regularly update Docker and base images
91
- 2. **Secure host system**: Ensure your host machine is secure
92
- 3. **Regular backups**: Back up your `data/` directory
93
- 4. **Monitor logs**: Check container logs for any unusual activity
94
- 5. **Limit access**: Don't expose the container to external networks
95
-
96
- ### **For Developers**
97
-
98
- 1. **Regular updates**: Keep Python and dependencies updated
99
- 2. **Security scanning**: Regularly scan Docker images for vulnerabilities
100
- 3. **Code review**: All database operations use parameterized queries
101
- 4. **Input validation**: All user inputs are validated before processing
102
-
103
- ## 🔧 **Security Configuration**
104
-
105
- ### **Environment Variables**
106
-
107
- ```bash
108
- # Database location (should be on secure volume)
109
- DB_PATH=/app/data/memory_journal.db
110
-
111
- # Python path for module resolution
112
- PYTHONPATH=/app
113
- ```
114
-
115
- ### **Volume Mounting Security**
116
-
117
- ```bash
118
- # Secure volume mounting
119
- docker run -v ./data:/app/data:rw,noexec,nosuid,nodev memory-journal-mcp
120
- ```
121
-
122
- ### **Resource Limits**
123
-
124
- ```bash
125
- # Apply resource limits
126
- docker run --memory=1g --cpus=1 memory-journal-mcp
127
- ```
128
-
129
- ## 📋 **Security Checklist**
130
-
131
- - [x] WAL mode enabled for database consistency
132
- - [x] Proper file permissions (600/700)
133
- - [x] Input validation and length limits
134
- - [x] Parameterized SQL queries
135
- - [x] Non-root Docker user
136
- - [x] Minimal container attack surface
137
- - [x] Local-first data architecture
138
- - [x] No external network dependencies
139
- - [x] Comprehensive error handling
140
- - [x] Security documentation
141
-
142
- ## 🚨 **Reporting Security Issues**
143
-
144
- If you discover a security vulnerability, please:
145
-
146
- 1. **Do not** open a public GitHub issue
147
- 2. **Contact** the maintainers privately
148
- 3. **Provide** detailed information about the vulnerability
149
- 4. **Allow** time for the issue to be addressed before public disclosure
150
-
151
- ## 🔄 **Security Updates**
152
-
153
- - **Database maintenance**: Run `ANALYZE` and `PRAGMA optimize` regularly
154
- - **Container updates**: Rebuild Docker images when base images are updated
155
- - **Dependency updates**: Keep Python packages updated
156
- - **Security patches**: Apply host system security updates
157
-
158
- ### **Recent Security Fixes**
159
-
160
- #### **CodeQL #110, #111: URL Substring Sanitization Vulnerability** (Fixed: October 26, 2025)
161
-
162
- - **Issue**: Incomplete URL substring sanitization in GitHub remote URL parsing
163
- - **Severity**: MEDIUM
164
- - **Affected Code**: `_extract_repo_owner_from_remote()` function in server.py
165
- - **Vulnerability Details**:
166
- - Used unsafe substring checks: `'github.com' in remote_url` and `'github.com/' in remote_url`
167
- - Could allow malicious URLs to bypass hostname validation
168
- - Example bypasses: `http://evil.com/github.com/fake/repo` or `http://github.com.evil.com/fake/repo`
169
- - **Mitigation**:
170
- - **Proper URL Parsing**: Implemented `urllib.parse.urlparse()` for HTTPS/HTTP URLs
171
- - ✅ **Exact Hostname Matching**: Validates `parsed.hostname == 'github.com'` (not substring or endswith)
172
- - **SSH URL Validation**: Explicit `startswith('git@github.com:')` check for SSH format
173
- - ✅ **Defense in Depth**: Returns `None` for any non-GitHub URLs instead of attempting to parse
174
- - **Technical Details**:
175
- - Vulnerability: CWE-20 (Improper Input Validation)
176
- - CodeQL Rule: `py/incomplete-url-substring-sanitization`
177
- - Context: Limited impact as this only parses Git remote URLs from local repositories
178
- - However, could be exploited if an attacker could manipulate Git config files
179
- - **Verification**: Review `_extract_repo_owner_from_remote()` function for proper urlparse usage
180
- - **Impact**: Prevents URL spoofing attacks in repository owner detection
181
- - **Reference**: [OWASP: SSRF](https://owasp.org/www-community/attacks/Server_Side_Request_Forgery) | [CWE-20](https://cwe.mitre.org/data/definitions/20.html)
182
-
183
- #### **CVE-2025-58050: PCRE2 Heap Buffer Overflow** (Fixed: October 26, 2025)
184
-
185
- - **Issue**: PCRE2 heap-buffer-overflow read in match_ref due to missing boundary restoration
186
- - **Severity**: CRITICAL
187
- - **Affected Package**: pcre2 <10.46-r0
188
- - **Mitigation**:
189
- - ✅ **Alpine Package**: Explicitly upgraded to pcre2=10.46-r0 in Dockerfile
190
- - **Early Installation**: Upgraded in first layer to ensure all subsequent packages use patched version
191
- - **Docker Base Image**: Using Python 3.14-alpine with latest security patches
192
- - **Technical Details**:
193
- - Vulnerability could allow heap buffer overflow attacks during regex pattern matching
194
- - Fixed version restores boundaries correctly in match_ref function
195
- - PCRE2 is a system dependency used by various tools including git and grep
196
- - **Verification**: Run `apk info pcre2` in Alpine container to confirm version ≥10.46-r0
197
- - **Impact**: Prevents potential remote code execution via malformed regex patterns
198
- - **Reference**: [CVE-2025-58050](https://avd.aquasec.com/nvd/cve-2025-58050)
199
-
200
- #### **CVE-2025-8869: pip Symbolic Link Vulnerability** (Fixed: October 20, 2025)
201
-
202
- - **Issue**: pip missing checks on symbolic link extraction in fallback tar implementation (when Python doesn't implement PEP 706)
203
- - **Severity**: MEDIUM
204
- - **Affected Package**: pip <25.0 (with Python versions without PEP 706 support)
205
- - **Comprehensive Mitigations**:
206
- - **Python Version**: Minimum requirement bumped to 3.10.12+ (all versions ≥3.10.12 implement PEP 706)
207
- - **pip Upgrade**: Explicitly upgrading to pip>=25.0 in all build processes (CI, Docker, local)
208
- - ✅ **Docker Base Image**: Using Python 3.14-alpine which fully implements PEP 706
209
- - **CI/CD Pipelines**: Updated to test against minimum Python 3.10.12
210
- - ✅ **pyproject.toml**: Enforced minimum Python version requirement
211
- - **Technical Details**:
212
- - PEP 706 provides secure tar extraction with symlink validation
213
- - When Python implements PEP 706, pip uses the secure implementation
214
- - Otherwise, pip falls back to its own implementation which had the vulnerability
215
- - Our fix addresses both the pip version and underlying Python version
216
- - **Verification**: Run `pip --version` to confirm pip>=25.0
217
- - **Impact**: Prevents potential exploitation during package installation via tar extraction
218
- - **Reference**: [CVE-2025-8869](https://nvd.nist.gov/vuln/detail/CVE-2025-8869) | [PEP 706](https://peps.python.org/pep-0706/)
219
-
220
- The Memory Journal MCP server is designed with **security-first principles** to protect your personal journal data while maintaining excellent performance and usability.
1
+ # 🔒 Security Guide
2
+
3
+ The Memory Journal MCP server implements comprehensive security measures to protect your personal journal data.
4
+
5
+ ## 🛡️ **Database Security**
6
+
7
+ ### **WAL Mode Enabled**
8
+
9
+ - ✅ **Write-Ahead Logging (WAL)** enabled for better concurrency and crash recovery
10
+ - ✅ **Atomic transactions** ensure data consistency
11
+ - ✅ **Better performance** with concurrent read/write operations
12
+
13
+ ### **Optimized PRAGMA Settings**
14
+
15
+ ```sql
16
+ PRAGMA foreign_keys = ON -- Enforce referential integrity
17
+ PRAGMA journal_mode = WAL -- Enable WAL mode
18
+ PRAGMA synchronous = NORMAL -- Balance safety and performance
19
+ PRAGMA cache_size = -64000 -- 64MB cache for better performance
20
+ PRAGMA mmap_size = 268435456 -- 256MB memory-mapped I/O
21
+ PRAGMA temp_store = MEMORY -- Store temp tables in memory
22
+ PRAGMA busy_timeout = 30000 -- 30-second timeout for busy database
23
+ ```
24
+
25
+ ### **File Permissions**
26
+
27
+ - ✅ **Database files**: `600` (read/write for owner only)
28
+ - ✅ **Data directory**: `700` (full access for owner only)
29
+ - ✅ **Automatic permission setting** on database creation
30
+
31
+ ## 🔐 **Input Validation**
32
+
33
+ ### **Content Limits**
34
+
35
+ - **Journal entries**: 50,000 characters maximum
36
+ - **Tags**: 100 characters maximum
37
+ - **Entry types**: 50 characters maximum
38
+ - **Significance types**: 50 characters maximum
39
+ - **HTTP request body**: 1MB maximum (prevents memory exhaustion)
40
+
41
+ ### **Character Filtering**
42
+
43
+ Dangerous characters are blocked in tags:
44
+
45
+ - `<` `>` `"` `'` `&` `\x00`
46
+
47
+ ### **SQL Injection Prevention**
48
+
49
+ - ✅ **Parameterized queries** used throughout
50
+ - ✅ **Input validation** via Zod schemas before database operations
51
+ - ✅ **Warning system** for potentially dangerous content patterns
52
+ - **LIKE pattern sanitization** (escapes `%`, `_`, `\` wildcards)
53
+ - ✅ **Date format whitelisting** (prevents strftime injection)
54
+
55
+ ### **Path Traversal Protection**
56
+
57
+ - ✅ **Backup filenames validated** - rejects `/`, `\`, `..` in paths
58
+ - ✅ **Typed security errors** with consistent error codes
59
+
60
+ ## 🌐 **HTTP Transport Security**
61
+
62
+ When running in HTTP mode (`--transport http`), the following security measures apply:
63
+
64
+ ### **CORS Configuration**
65
+
66
+ - **Configurable origin** via `--cors-origin` flag or `MCP_CORS_ORIGIN` environment variable
67
+ - ⚠️ **Default: `*`** (allow all origins) for backward compatibility
68
+ - 🔒 **Recommended**: Set a specific origin for production deployments
69
+
70
+ ```bash
71
+ # Restrict CORS to specific origin
72
+ memory-journal-mcp --transport http --cors-origin "http://localhost:3000"
73
+
74
+ # Or via environment variable
75
+ export MCP_CORS_ORIGIN="http://localhost:3000"
76
+ ```
77
+
78
+ ### **Security Headers**
79
+
80
+ - **X-Content-Type-Options: nosniff** - prevents MIME sniffing
81
+ - ✅ **X-Frame-Options: DENY** - prevents clickjacking
82
+
83
+ ### **Session Management (Stateful Mode)**
84
+
85
+ - ✅ **UUID-based session IDs** (cryptographically random)
86
+ - **30-minute session timeout** - idle sessions automatically expired
87
+ - ✅ **5-minute sweep interval** - periodic cleanup of abandoned sessions
88
+ - **Explicit session termination** via `DELETE /mcp`
89
+
90
+ ### **Request Size Limits**
91
+
92
+ - **1MB body limit** on JSON requests (prevents memory exhaustion DoS)
93
+
94
+ ## 🐙 **GitHub Token Security**
95
+
96
+ ### **Token Handling**
97
+
98
+ - **Environment variables only** - tokens never stored in config files
99
+ - **Error message scrubbing** - Authorization headers stripped from error logs
100
+ - **Optional integration** - server works fully offline without GitHub token
101
+ - **Minimal scopes** - only requires `repo`, `project`, `read:org`
102
+
103
+ ### **Environment Variables**
104
+
105
+ ```bash
106
+ # Required for GitHub features
107
+ GITHUB_TOKEN=ghp_... # GitHub personal access token
108
+
109
+ # Optional
110
+ GITHUB_ORG_TOKEN=ghp_... # For organization projects
111
+ GITHUB_REPO_PATH=/path/to/repo # For auto-detecting owner/repo
112
+ DEFAULT_PROJECT_NUMBER=1 # Default project for issue assignment
113
+ MCP_CORS_ORIGIN=* # CORS origin (default: *)
114
+ MCP_HOST=localhost # Server bind host
115
+ AUTO_REBUILD_INDEX=true # Rebuild vector index on startup
116
+ ```
117
+
118
+ ## 🐳 **Docker Security**
119
+
120
+ ### **Non-Root User**
121
+
122
+ - **Dedicated user**: `appuser` (UID 1001) with minimal privileges
123
+ - ✅ **Restricted group**: `appgroup` (GID 1001)
124
+ - ✅ **Restricted data directory**: `700` permissions
125
+
126
+ ### **Container Hardening**
127
+
128
+ - ✅ **Minimal base image**: `node:24-alpine`
129
+ - **Multi-stage build**: Build dependencies not in production image
130
+ - ✅ **Process isolation** from host system
131
+ - **No shell access needed** for production
132
+
133
+ ### **Volume Mounting Security**
134
+
135
+ ```bash
136
+ # Secure volume mounting
137
+ docker run -v ./data:/app/data:rw,noexec,nosuid,nodev memory-journal-mcp
138
+ ```
139
+
140
+ ### **Resource Limits**
141
+
142
+ ```bash
143
+ # Apply resource limits
144
+ docker run --memory=1g --cpus=1 memory-journal-mcp
145
+ ```
146
+
147
+ ## 🔍 **Data Privacy**
148
+
149
+ ### **Local-First Architecture**
150
+
151
+ - **No external services**: All processing happens locally
152
+ - ✅ **No telemetry**: No data sent to external servers
153
+ - **Full data ownership**: SQLite database stays on your machine
154
+ - **Semantic search**: ML model runs locally via `@xenova/transformers`
155
+
156
+ ### **Context Security**
157
+
158
+ - **Git context**: Only reads local repository information
159
+ - ✅ **No sensitive data**: Doesn't access private keys or credentials
160
+ - **Optional GitHub integration**: Only if explicitly configured with token
161
+
162
+ ## 🔄 **CI/CD Security**
163
+
164
+ - **CodeQL analysis** - automated static analysis on push/PR
165
+ - **Trivy container scanning** - Docker image vulnerability detection
166
+ - **TruffleHog + Gitleaks** - secret scanning on push/PR
167
+ - **npm audit** - dependency vulnerability checking
168
+ - **Dependabot** - automated dependency update PRs
169
+
170
+ ## 🚨 **Security Best Practices**
171
+
172
+ ### **For Users**
173
+
174
+ 1. **Set a CORS origin** when exposing the HTTP transport on a network
175
+ 2. **Keep Node.js updated**: Use Node.js 24+ (LTS)
176
+ 3. **Secure host system**: Ensure your host machine is secure
177
+ 4. **Regular backups**: Use the `backup_journal` tool or back up your `.db` file
178
+ 5. **Limit network access**: Don't expose the HTTP transport to untrusted networks
179
+ 6. **Use resource limits**: Apply Docker `--memory` and `--cpus` limits
180
+
181
+ ### **For Developers**
182
+
183
+ 1. **Regular updates**: Keep Node.js and npm dependencies updated
184
+ 2. **Security scanning**: Regularly scan Docker images for vulnerabilities
185
+ 3. **Code review**: All database operations use parameterized queries
186
+ 4. **Input validation**: All tool inputs validated via Zod schemas
187
+
188
+ ## 📋 **Security Checklist**
189
+
190
+ - [x] WAL mode enabled for database consistency
191
+ - [x] Proper file permissions (600/700)
192
+ - [x] Input validation and length limits (Zod schemas)
193
+ - [x] Parameterized SQL queries
194
+ - [x] SQL injection detection heuristics
195
+ - [x] Path traversal protection
196
+ - [x] LIKE pattern sanitization
197
+ - [x] Date format whitelisting
198
+ - [x] HTTP body size limit (1MB)
199
+ - [x] Configurable CORS origin
200
+ - [x] Security headers (X-Content-Type-Options, X-Frame-Options)
201
+ - [x] Session timeout (30 minutes)
202
+ - [x] Non-root Docker user
203
+ - [x] Multi-stage Docker build
204
+ - [x] Local-first data architecture
205
+ - [x] GitHub token error scrubbing
206
+ - [x] CI/CD security pipeline (CodeQL, Trivy, secret scanning)
207
+ - [x] Comprehensive security documentation
208
+
209
+ ## 🚨 **Reporting Security Issues**
210
+
211
+ If you discover a security vulnerability, please:
212
+
213
+ 1. **Do not** open a public GitHub issue
214
+ 2. **Contact** the maintainers privately
215
+ 3. **Provide** detailed information about the vulnerability
216
+ 4. **Allow** time for the issue to be addressed before public disclosure
217
+
218
+ ## 🔄 **Security Updates**
219
+
220
+ - **Container updates**: Rebuild Docker images when base images are updated
221
+ - **Dependency updates**: Keep npm packages updated via `npm audit` and Dependabot
222
+ - **Database maintenance**: Run `ANALYZE` and `PRAGMA optimize` regularly
223
+ - **Security patches**: Apply host system security updates
224
+
225
+ The Memory Journal MCP server is designed with **security-first principles** to protect your personal journal data while maintaining excellent performance and usability.
package/dist/cli.js CHANGED
@@ -12,25 +12,31 @@ program
12
12
  .version(pkg.version)
13
13
  .option('--transport <type>', 'Transport type: stdio or http', 'stdio')
14
14
  .option('--port <number>', 'HTTP port (for http transport)', '3000')
15
+ .option('--server-host <host>', 'Server bind host for HTTP transport (default: localhost)')
15
16
  .option('--stateless', 'Use stateless HTTP mode (no session management)')
16
17
  .option('--db <path>', 'Database path', './memory_journal.db')
17
18
  .option('--tool-filter <filter>', 'Tool filter string (e.g., "starter", "core,search")')
18
19
  .option('--default-project <number>', 'Default GitHub Project number')
19
20
  .option('--auto-rebuild-index', 'Rebuild vector index on server startup')
21
+ .option('--cors-origin <origin>', 'CORS allowed origin for HTTP transport (default: *)')
20
22
  .option('--log-level <level>', 'Log level: debug, info, warning, error', 'info')
21
23
  .action(async (options) => {
22
24
  // Set log level
23
25
  logger.setLevel(options.logLevel);
26
+ // Resolve host: CLI flag > env var > default (localhost)
27
+ const host = options.serverHost ?? process.env['MCP_HOST'] ?? process.env['HOST'] ?? undefined;
24
28
  logger.info('Starting Memory Journal MCP Server', {
25
29
  module: 'CLI',
26
30
  transport: options.transport,
27
31
  stateless: options.stateless ?? false,
28
32
  db: options.db,
33
+ ...(host ? { host } : {}),
29
34
  });
30
35
  try {
31
36
  await createServer({
32
37
  transport: options.transport,
33
38
  port: parseInt(options.port, 10),
39
+ host,
34
40
  statelessHttp: options.stateless === true,
35
41
  dbPath: options.db,
36
42
  toolFilter: options.toolFilter,
@@ -40,6 +46,7 @@ program
40
46
  ? parseInt(process.env['DEFAULT_PROJECT_NUMBER'], 10)
41
47
  : undefined,
42
48
  autoRebuildIndex: options.autoRebuildIndex ?? process.env['AUTO_REBUILD_INDEX'] === 'true',
49
+ corsOrigin: options.corsOrigin,
43
50
  });
44
51
  }
45
52
  catch (error) {
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAEvD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAE7B,OAAO;KACF,IAAI,CAAC,oBAAoB,CAAC;KAC1B,WAAW,CAAC,wDAAwD,CAAC;KACrE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;KACpB,MAAM,CAAC,oBAAoB,EAAE,+BAA+B,EAAE,OAAO,CAAC;KACtE,MAAM,CAAC,iBAAiB,EAAE,gCAAgC,EAAE,MAAM,CAAC;KACnE,MAAM,CAAC,aAAa,EAAE,iDAAiD,CAAC;KACxE,MAAM,CAAC,aAAa,EAAE,eAAe,EAAE,qBAAqB,CAAC;KAC7D,MAAM,CAAC,wBAAwB,EAAE,qDAAqD,CAAC;KACvF,MAAM,CAAC,4BAA4B,EAAE,+BAA+B,CAAC;KACrE,MAAM,CAAC,sBAAsB,EAAE,wCAAwC,CAAC;KACxE,MAAM,CAAC,qBAAqB,EAAE,wCAAwC,EAAE,MAAM,CAAC;KAC/E,MAAM,CACH,KAAK,EAAE,OASN,EAAE,EAAE;IACD,gBAAgB;IAChB,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAkD,CAAC,CAAA;IAE3E,MAAM,CAAC,IAAI,CAAC,oCAAoC,EAAE;QAC9C,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,OAAO,CAA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;IACnB,CAAC;AACL,CAAC,CACJ,CAAA;AAEL,OAAO,CAAC,KAAK,EAAE,CAAA"}
@@ -4,7 +4,7 @@
4
4
  * These instructions are automatically sent to MCP clients during initialization,
5
5
  * providing guidance for AI agents on tool usage.
6
6
  *
7
- * v3.1.6: Optimized for token efficiency with tiered instruction levels.
7
+ * Unreleased: Optimized for token efficiency with tiered instruction levels.
8
8
  */
9
9
  /**
10
10
  * Resource definition for instruction generation
@@ -1 +1 @@
1
- {"version":3,"file":"ServerInstructions.d.ts","sourceRoot":"","sources":["../../src/constants/ServerInstructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAA;AAuLhE;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAChC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,UAAU,EAAE,kBAAkB,EAAE,EAChC,OAAO,EAAE,gBAAgB,EAAE,EAC3B,WAAW,CAAC,EAAE,mBAAmB,EACjC,KAAK,GAAE,gBAA6B,GACrC,MAAM,CAuCR;AAkBD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAA+C,CAAA"}
1
+ {"version":3,"file":"ServerInstructions.d.ts","sourceRoot":"","sources":["../../src/constants/ServerInstructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAA;AAmOhE;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAChC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,UAAU,EAAE,kBAAkB,EAAE,EAChC,OAAO,EAAE,gBAAgB,EAAE,EAC3B,WAAW,CAAC,EAAE,mBAAmB,EACjC,KAAK,GAAE,gBAA6B,GACrC,MAAM,CAuCR;AAkBD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAA+C,CAAA"}