memorio 5.0.0 → 5.1.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 (60) hide show
  1. package/README.md +80 -449
  2. package/SECURITY.md +152 -42
  3. package/SUMMARY.md +1 -1
  4. package/adr/001-state-proxy-model.md +95 -96
  5. package/adr/002-observer-semantics.md +179 -180
  6. package/adr/003-deep-mutation-semantics.md +7 -8
  7. package/adr/004-array-mutation-semantics.md +127 -128
  8. package/adr/005-scheduler-contract.md +148 -149
  9. package/adr/006-context-isolation.md +91 -92
  10. package/adr/007-mutation-records.md +5 -6
  11. package/adr/008-transactions.md +6 -7
  12. package/adr/009-history-model.md +6 -7
  13. package/adr/README.md +46 -46
  14. package/adr/template.md +48 -49
  15. package/bin/cli.js +68 -0
  16. package/global.cjs +1462 -323
  17. package/global.js +1459 -324
  18. package/index.cjs +1462 -323
  19. package/index.d.ts +1 -0
  20. package/index.js +1459 -324
  21. package/llms.txt +42 -5
  22. package/markdown/AUDIT-REPORT.md +7 -8
  23. package/markdown/CACHE.md +190 -99
  24. package/markdown/DEVTOOLS.md +0 -1
  25. package/markdown/DISPATCH.md +0 -1
  26. package/markdown/HISTORY.md +0 -1
  27. package/markdown/IDB.md +0 -1
  28. package/markdown/IMPORT.md +0 -1
  29. package/markdown/INSPECT.md +0 -1
  30. package/markdown/LOGGER.md +0 -1
  31. package/markdown/MEMORY-ATTACHMENT.md +0 -1
  32. package/markdown/MEMORY.md +0 -1
  33. package/markdown/OBSERVER.md +0 -1
  34. package/markdown/PLATFORM.md +277 -271
  35. package/markdown/REDUX.md +54 -0
  36. package/markdown/SCHEMA.md +0 -1
  37. package/markdown/SESSION.md +0 -1
  38. package/markdown/SQLITE.md +0 -1
  39. package/markdown/STATE.md +0 -1
  40. package/markdown/STORE.md +0 -1
  41. package/markdown/SYNC.md +0 -1
  42. package/markdown/TYPED.md +0 -1
  43. package/markdown/USEOBSERVER.md +0 -1
  44. package/modules/redux.cjs +381 -10
  45. package/modules/redux.cjs.map +1 -1
  46. package/modules/redux.js +381 -10
  47. package/modules/redux.js.map +1 -1
  48. package/package.json +14 -2
  49. package/types/broadcast.d.ts +61 -0
  50. package/types/computed.d.ts +96 -0
  51. package/types/encryption.d.ts +129 -0
  52. package/types/exports.d.ts +9 -0
  53. package/types/memorio.d.ts +19 -12
  54. package/types/security.d.ts +67 -0
  55. package/types/session.d.ts +23 -5
  56. package/types/store.d.ts +19 -3
  57. package/vsix/memorio.vsix +0 -0
  58. package/markdown/CHANGELOG.md +0 -243
  59. package/markdown/PROJECT.md +0 -311
  60. package/markdown/SECURITY.md +0 -330
@@ -1,330 +0,0 @@
1
- > **Status:** Published
2
- > **Date:** 2026-09-12
3
- > **Deciders:** Memorio 5.x Core Team
4
- > **Scope**: Security Documentation
5
- > **Standard**: NIST SP 800-53, OWASP ASVS, NSA Cybersecurity Guidelines
6
- >
7
- ---
8
- # Memorio Security Documentation
9
-
10
- > Last Updated: v3.0.2
11
-
12
- This document describes the security measures implemented in Memorio to protect against common vulnerabilities and ensure safe operation across different platforms.
13
-
14
- ---
15
-
16
- ## Security Overview
17
-
18
- Memorio implements multiple layers of security to protect user data and prevent common attack vectors:
19
-
20
- | Security Feature | Status | Description |
21
- |------------------|--------|-------------|
22
- | Cryptographically Secure IDs | ✅ Enabled | Session/Context IDs use crypto.randomUUID |
23
- | Input Validation | ✅ Enabled | Key length limits + character filtering |
24
- | Session Isolation | ✅ Enabled | Unique namespaces per session |
25
- | Context Isolation | ✅ Enabled | Separate storage per tenant |
26
- | No Code Injection | ✅ Enabled | No eval() or dynamic code execution |
27
- | XSS Prevention | ✅ Enabled | No innerHTML or document.write |
28
-
29
- ---
30
-
31
- ## 1. Cryptographically Secure Random Generation
32
-
33
- ### Implementation
34
-
35
- Session and context IDs are generated using cryptographically secure random values:
36
-
37
- ```typescript
38
- // config/platform.ts
39
- function generateSessionId(): string {
40
- // Priority 1: crypto.randomUUID (most secure)
41
- if (typeof crypto !== 'undefined' && crypto.randomUUID) {
42
- return crypto.randomUUID()
43
- }
44
-
45
- // Priority 2: crypto.getRandomValues (secure fallback)
46
- if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
47
- const array = new Uint8Array(16)
48
- crypto.getRandomValues(array)
49
- return Array.from(array, b => b.toString(16).padStart(2, '0')).join('')
50
- }
51
-
52
- // Priority 3: Math.random (last resort - less secure)
53
- return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`
54
- }
55
- ```
56
-
57
- ### Random Source Priority
58
-
59
- | Priority | Method | Security Level |
60
- |----------|--------|----------------|
61
- | 1 | `crypto.randomUUID()` | 🔒 FIPS 140-2 compliant |
62
- | 2 | `crypto.getRandomValues()` | 🔒 Cryptographically secure |
63
- | 3 | `Math.random()` | ⚠️ Not for security purposes |
64
-
65
- ---
66
-
67
- ## 2. Input Validation & Key Sanitization
68
-
69
- All storage keys are validated before use to prevent injection attacks:
70
-
71
- ### Validation Rules
72
-
73
- | Rule | Limit | Action on Violation |
74
- |------|-------|---------------------|
75
- | Key Length | Max 512 chars | Reject with debug message |
76
- | Character Set | `[a-zA-Z0-9_.-]` | Reject with debug message |
77
- | Type Check | Must be string | Return empty/null |
78
-
79
- ### Implementation
80
-
81
- ```typescript
82
- function _prefixKey(name: string): string {
83
- // Validate key
84
- if (!name || typeof name !== 'string') return ''
85
- if (name.length > 512) {
86
- console.debug('Key too long (max 512 characters)')
87
- return ''
88
- }
89
- // Sanitize: only allow alphanumeric, underscore, dash, dot
90
- if (!/^[a-zA-Z0-9_.-]+$/.test(name)) {
91
- console.debug('Key contains invalid characters')
92
- return ''
93
- }
94
- return _sessionPrefix + name
95
- }
96
- ```
97
-
98
- ### Allowed Characters Table
99
-
100
- | Character Type | Allowed | Example |
101
- |----------------|---------|---------|
102
- | Lowercase | ✅ | `username`, `user_data` |
103
- | Uppercase | ✅ | `USER`, `UserName` |
104
- | Numbers | ✅ | `user123`, `data_2024` |
105
- | Underscore | ✅ | `user_name`, `_private` |
106
- | Dash | ✅ | `user-id`, `data-set` |
107
- | Dot | ✅ | `user.profile`, `data.json` |
108
- | Special Chars | ❌ | `<script>`, `../../../etc` |
109
-
110
- ---
111
-
112
- ## 3. Session Isolation
113
-
114
- Each session gets a unique namespace to prevent data leakage:
115
-
116
- ### Isolation Mechanism
117
-
118
- | Component | Without Context | With Context |
119
- |-----------|-----------------|--------------|
120
- | Session ID | `crypto.randomUUID()` | Context name |
121
- | Store Keys | `memorio_store_[uuid]-keyname` | `[contextName]-keyname` |
122
- | Session Keys | `memorio_session_[uuid]-keyname` | `[contextName]-keyname` |
123
- | State | In-memory (per-instance) | In-memory (per-instance) |
124
-
125
- ### Key Prefix Format
126
-
127
- ```
128
- // Without context:
129
- memorio_store-[session-uuid]-username
130
- memorio_session-[session-uuid]-auth-token
131
-
132
- // With context (createContext('user-123')):
133
- user-123-username
134
- user-123-auth-token
135
- ```
136
-
137
- ### Cross-Session Protection
138
-
139
- | Scenario | Protection |
140
- |----------|------------|
141
- | Browser Tabs | Each tab has unique session ID |
142
- | Server Requests | Each request can use separate context |
143
- | Multi-Tenant | `memorio.createContext()` isolates tenants |
144
-
145
- ---
146
-
147
- ## 4. Context Isolation (Multi-Tenant)
148
-
149
- For server-side applications, contexts provide complete data isolation:
150
-
151
- ```typescript
152
- // Create isolated context per tenant
153
- const tenantA = memorio.isolate('tenant-A')
154
- const tenantB = memorio.isolate('tenant-B')
155
-
156
- // Each context has completely separate storage
157
- tenantA.state.secret = 'Tenant A data' // Isolated
158
- tenantB.state.secret = 'Tenant B data' // Isolated
159
- ```
160
-
161
- ### Context Security
162
-
163
- | Feature | Description |
164
- |---------|-------------|
165
- | Unique ID | Each context gets unique identifier |
166
- | Separate Storage | State, Store, Session, Cache all isolated |
167
- | No Cross-Context Access | Impossible to read other contexts |
168
- | Cleanup | `deleteContext()` removes all data |
169
-
170
- ---
171
-
172
- ## 5. Data Serialization Security
173
-
174
- ### Safe Operations
175
-
176
- | Operation | Security Measure |
177
- |-----------|-----------------|
178
- | `store.set()` | JSON.stringify only allowed types |
179
- | `store.get()` | JSON.parse with try-catch |
180
- | Functions | Blocked with debug message |
181
- | Objects | Deep-cloned on read |
182
-
183
- ### Blocked Types
184
-
185
- ```typescript
186
- // These are blocked and logged:
187
- store.set('myFunc', () => {}) // "It's not secure to store functions."
188
- store.set('mySymbol', Symbol('test')) // Would fail serialization
189
- ```
190
-
191
- ---
192
-
193
- ## 6. Platform-Specific Security
194
-
195
- ### Browser Environment
196
-
197
- | Feature | Security |
198
- |---------|----------|
199
- | localStorage | Same-origin policy applies |
200
- | sessionStorage | Tab isolation |
201
- | IndexedDB | Same-origin policy |
202
- | HTTPS Required | Recommended for production |
203
-
204
- ### Server Environment (Node.js/Deno)
205
-
206
- | Feature | Security |
207
- |---------|----------|
208
- | In-Memory Storage | Process-scoped only |
209
- | Context Isolation | Per-request isolation recommended |
210
- | No Persistence | Data lost on restart (by design) |
211
-
212
- ---
213
-
214
- ## 7. Security Best Practices
215
-
216
- ### For Developers
217
-
218
- 1. **Use Contexts in Server Apps**
219
- ```typescript
220
- // Express middleware
221
- app.use((req, res, next) => {
222
- req.memorio = memorio.createContext(`req-${req.id}`)
223
- next()
224
- })
225
- ```
226
-
227
- 2. **Validate Keys**
228
- ```typescript
229
- // Don't use user input directly as keys
230
- const safeKey = sanitize(userInput) // Input validation
231
- store.set(safeKey, value)
232
- ```
233
-
234
- 3. **Check Persistence**
235
- ```typescript
236
- if (!store.isPersistent) {
237
- console.warn('Data not persisted!')
238
- }
239
- ```
240
-
241
- 4. **Clear Sensitive Data**
242
- ```typescript
243
- // On logout
244
- session.removeAll()
245
- state.removeAll()
246
- ```
247
-
248
- ### For Security Audits
249
-
250
- | Check | Location |
251
- |-------|----------|
252
- | Random Generation | `config/platform.ts:44` |
253
- | Key Validation | `functions/store/index.ts:31` |
254
- | Session Isolation | `functions/session/index.ts:27` |
255
- | Context System | `config/platform.ts:301` |
256
-
257
- ---
258
-
259
- ## 8. Vulnerability Prevention
260
-
261
- ### Prevention Matrix
262
-
263
- | Vulnerability | Prevention | Status |
264
- |---------------|------------|--------|
265
- | XSS | No innerHTML/document.write | ✅ |
266
- | Code Injection | No eval/Function | ✅ |
267
- | Key Injection | Character whitelist | ✅ |
268
- | DoS | 512 char key limit | ✅ |
269
- | Session Hijacking | Unique session IDs | ✅ |
270
- | Data Leakage | Namespace isolation | ✅ |
271
- | CSRF | Browser Same-Origin | ✅ |
272
-
273
- ---
274
-
275
- ## 9. Compliance
276
-
277
- ### Standards Alignment
278
-
279
- | Standard | Compliance |
280
- |----------|------------|
281
- | NIST SP 800-53 | ✅ Cryptographic standards |
282
- | OWASP Top 10 | ✅ Key injection prevention |
283
- | CWE | ✅ Common weaknesses addressed |
284
- | FIPS 140-2 | ✅ crypto.randomUUID |
285
-
286
- ---
287
-
288
- ## 10. Reporting Security Issues
289
-
290
- If you discover a security vulnerability in Memorio:
291
-
292
- 1. **Do NOT** open a public GitHub issue
293
- 2. **Email**: security@example.com (replace with actual contact)
294
- 3. **Include**: Vulnerability details, steps to reproduce, potential impact
295
-
296
- ### Response Timeline
297
-
298
- | Phase | Timeline |
299
- |-------|----------|
300
- | Acknowledgment | 48 hours |
301
- | Initial Assessment | 7 days |
302
- | Fix Released | Based on severity |
303
-
304
- ---
305
-
306
- ## Security Changelog
307
-
308
- ### v3.0.2 (Current)
309
-
310
- - ✅ Removed esbuild-sass-plugin / esbuild-scss-modules-plugin (SCSS attack vector eliminated)
311
- - ✅ `store.set()` now blocks function values instead of silently continuing
312
- - ✅ All `PRIVATE License` headers in `functions/idb/` replaced with `MIT`
313
- - ✅ `buildPathTracker` dead code removed from state
314
- - ✅ `Object.freeze(observer)` call removed (undeclared variable, caused `ReferenceError`)
315
- - ✅ `confirm()` removed from `idb.db.delete()` (no blocking UI calls in libraries)
316
- - ✅ Fully generated changelog for v3.0.2 across all github docs
317
-
318
- ---
319
-
320
- ### v2.7.0 - Previous
321
-
322
- - ✅ Added `crypto.getRandomValues()` fallback
323
- - ✅ Added key length validation (512 chars)
324
- - ✅ Added character whitelist validation
325
- - ✅ Improved session isolation
326
- - ✅ Context isolation for multi-tenancy
327
-
328
- ---
329
-
330
- *This document was last updated for Memorio v3.0.2*