Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(security): reject prototype names as POST memory mastery keys
Adam Eivyac5a7a5351ce
diff --git a/server/lib/postValidation.js b/server/lib/postValidation.jsindex 3d1f46480e..7467287c86 100644--- a/server/lib/postValidation.js+++ b/server/lib/postValidation.js@@ -6,6 +6,12 @@ import { HHMM_STRICT_RE } from './timezone.js';import { POST_LLM_MAX_SEMANTIC_CANDIDATES, postLlmEvaluationSchema } from './postLlmContracts.js';import { EFFORT_LEVELS } from './providerModels.js';import { RHETORIC_DRILL_TYPES, RHETORIC_MODE_IDS, rhetoricEvaluationSchema } from './postRhetoric.js';+import { POLLUTING_KEYS } from './objects.js';++// Chunk ids and element names index the plain-object mastery maps in+// meatspacePostMemory.js; `__proto__` would resolve to Object.prototype and+// the mastery update would write onto every object in the process.+const masteryKeySchema = z.string().refine((key) => !POLLUTING_KEYS.has(key), 'reserved mastery key');// =============================================================================// POST (Power On Self Test) VALIDATION SCHEMAS@@ -76,8 +82,8 @@ const questionResultSchema = z.object({// merge per-chunk/per-element mastery (mergeMasteryFromSession in// meatspacePostMemory.js) the same way MemoryBuilder's submitPractice does.// Absent for math/LLM/cognitive drills.- chunkId: z.string().nullable().optional(),- element: z.string().nullable().optional()+ chunkId: masteryKeySchema.nullable().optional(),+ element: masteryKeySchema.nullable().optional()});// LLM drill response (text-based)@@ -561,10 +567,10 @@ export const memoryItemUpdateSchema = z.object({const practiceResultSchema = z.object({correct: z.boolean(),word: z.string().optional(),- element: z.string().nullable().optional(),+ element: masteryKeySchema.nullable().optional(),expected: z.string().optional(),answered: z.string().optional(),- chunkId: z.string().optional(),+ chunkId: masteryKeySchema.optional(),});export const memoryPracticeSchema = z.object({@@ -572,7 +578,7 @@ export const memoryPracticeSchema = z.object({// logged like `learn` and intentionally does not advance mastery. It is NOT a// POST-session drill type (no server generator, see generateMemoryDrill).mode: z.enum(['fill-blank', 'sequence', 'element-flash', 'element-study', 'learn', 'speed-run']),- chunkId: z.string().nullable().optional(),+ chunkId: masteryKeySchema.nullable().optional(),// Learn mode is an exposure event and legitimately has no scored results.// Every retrieval mode still needs at least one result.results: z.array(practiceResultSchema),diff --git a/server/lib/postValidation.test.js b/server/lib/postValidation.test.jsindex e8fbe1d867..8e5730bcc5 100644--- a/server/lib/postValidation.test.js+++ b/server/lib/postValidation.test.js@@ -404,6 +404,20 @@ describe('questionResultSchema chunkId/element (issue #2016)', () => {expect(parsed.tasks[0].questions[0].element).toBeUndefined();});+ // Both keys index plain-object mastery maps; `__proto__` would write the+ // mastery update onto Object.prototype.+ it.each(['__proto__', 'constructor', 'prototype'])('rejects %s as a mastery chunk or element key', (key) => {+ const session = (question) => ({+ modules: ['memory'],+ tasks: [{ module: 'memory', type: 'memory-sequence', memoryItemId: 'song-1', questions: [{ prompt: 'a', expected: 'b', answered: 'b', correct: true, responseMs: 1, ...question }], totalMs: 1 }],+ });+ expect(postSessionSubmitSchema.safeParse(session({ chunkId: key })).success).toBe(false);+ expect(postSessionSubmitSchema.safeParse(session({ element: key })).success).toBe(false);+ expect(memoryPracticeSchema.safeParse({ mode: 'sequence', chunkId: key, results: [{ correct: true }] }).success).toBe(false);+ expect(memoryPracticeSchema.safeParse({ mode: 'element-flash', results: [{ correct: true, element: key }] }).success).toBe(false);+ expect(memoryPracticeSchema.safeParse({ mode: 'sequence', chunkId: 'verse-1', results: [{ correct: true, chunkId: 'verse-1' }] }).success).toBe(true);+ });+it('accepts a null chunkId (question with no matching chunk)', () => {const parsed = postSessionSubmitSchema.parse({modules: ['memory'],