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
address review: legacy prompt migration heuristic, hasOwnProperty guard, sanitize tests
Adam Eivy616a8d1c1386
diff --git a/server/lib/validation.js b/server/lib/validation.jsindex c5035f79d7..b7011133b0 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -551,13 +551,13 @@ const DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);*/export function sanitizeTaskMetadata(raw) {if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;- const clean = {};+ const clean = Object.create(null);let hasKeys = false;for (const key of ALLOWED_TASK_METADATA_KEYS) {- if (key in raw && !DANGEROUS_KEYS.has(key) && typeof raw[key] === 'boolean') {+ if (Object.prototype.hasOwnProperty.call(raw, key) && typeof raw[key] === 'boolean') {clean[key] = raw[key];hasKeys = true;}}- return hasKeys ? clean : null;+ return hasKeys ? { ...clean } : null;}diff --git a/server/lib/validation.test.js b/server/lib/validation.test.jsindex 2f0d11d7ae..9643d8da9e 100644--- a/server/lib/validation.test.js+++ b/server/lib/validation.test.js@@ -7,7 +7,8 @@ import {runSchema,featureAgentSchema,featureAgentUpdateSchema,- validate+ validate,+ sanitizeTaskMetadata} from './validation.js';describe('validation.js', () => {@@ -427,4 +428,52 @@ describe('validation.js', () => {expect(result.data.type).toBe('express'); // default value});});++ describe('sanitizeTaskMetadata', () => {+ it('should return null for null/undefined/non-object input', () => {+ expect(sanitizeTaskMetadata(null)).toBeNull();+ expect(sanitizeTaskMetadata(undefined)).toBeNull();+ expect(sanitizeTaskMetadata('string')).toBeNull();+ expect(sanitizeTaskMetadata(42)).toBeNull();+ expect(sanitizeTaskMetadata(true)).toBeNull();+ });++ it('should return null for arrays', () => {+ expect(sanitizeTaskMetadata([1, 2, 3])).toBeNull();+ expect(sanitizeTaskMetadata([])).toBeNull();+ });++ it('should return null for empty objects', () => {+ expect(sanitizeTaskMetadata({})).toBeNull();+ });++ it('should accept allowed keys with boolean values', () => {+ expect(sanitizeTaskMetadata({ useWorktree: true })).toEqual({ useWorktree: true });+ expect(sanitizeTaskMetadata({ simplify: false })).toEqual({ simplify: false });+ expect(sanitizeTaskMetadata({ useWorktree: true, simplify: false })).toEqual({ useWorktree: true, simplify: false });+ });++ it('should drop non-boolean values for allowed keys', () => {+ expect(sanitizeTaskMetadata({ useWorktree: 'yes' })).toBeNull();+ expect(sanitizeTaskMetadata({ simplify: 1 })).toBeNull();+ expect(sanitizeTaskMetadata({ useWorktree: null })).toBeNull();+ });++ it('should drop unknown keys', () => {+ expect(sanitizeTaskMetadata({ unknownKey: true })).toBeNull();+ expect(sanitizeTaskMetadata({ useWorktree: true, foo: 'bar' })).toEqual({ useWorktree: true });+ });++ it('should reject prototype pollution keys', () => {+ expect(sanitizeTaskMetadata({ __proto__: { malicious: true } })).toBeNull();+ expect(sanitizeTaskMetadata({ constructor: true })).toBeNull();+ expect(sanitizeTaskMetadata({ prototype: true })).toBeNull();+ });++ it('should not accept inherited properties', () => {+ const proto = { useWorktree: true };+ const obj = Object.create(proto);+ expect(sanitizeTaskMetadata(obj)).toBeNull();+ });+ });});diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 3c4028f7ee..7fb8ca790d 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -728,17 +728,37 @@ export async function loadSchedule() {let needsSave = false;for (const [taskType, config] of Object.entries(schedule.tasks)) {if (!config.prompt && DEFAULT_TASK_PROMPTS[taskType]) {+ // No prompt set — initialize with current default and versionconfig.prompt = DEFAULT_TASK_PROMPTS[taskType];config.promptVersion = PROMPT_VERSIONS[taskType] || 1;needsSave = true;- } else if (PROMPT_VERSIONS[taskType] && !config.promptCustomized) {- // Auto-upgrade non-customized prompts when code version is newer- const storedVersion = config.promptVersion || 1;- if (storedVersion < PROMPT_VERSIONS[taskType]) {- emitLog('info', `Upgrading ${taskType} prompt v${storedVersion} → v${PROMPT_VERSIONS[taskType]}`, { taskType }, '📅 TaskSchedule');- config.prompt = DEFAULT_TASK_PROMPTS[taskType];- config.promptVersion = PROMPT_VERSIONS[taskType];- needsSave = true;+ } else {+ // Legacy migration: infer customization when promptVersion is missing+ if (+ config.prompt &&+ config.promptVersion === undefined &&+ DEFAULT_TASK_PROMPTS[taskType]+ ) {+ if (config.prompt !== DEFAULT_TASK_PROMPTS[taskType]) {+ // Prompt differs from default — treat as customized to avoid overwriting+ config.promptCustomized = true;+ needsSave = true;+ } else {+ // Prompt matches default — safe to assign version for future upgrades+ config.promptVersion = PROMPT_VERSIONS[taskType] || 1;+ needsSave = true;+ }+ }++ if (PROMPT_VERSIONS[taskType] && !config.promptCustomized) {+ // Auto-upgrade non-customized prompts when code version is newer+ const storedVersion = config.promptVersion || 1;+ if (storedVersion < PROMPT_VERSIONS[taskType]) {+ emitLog('info', `Upgrading ${taskType} prompt v${storedVersion} → v${PROMPT_VERSIONS[taskType]}`, { taskType }, '📅 TaskSchedule');+ config.prompt = DEFAULT_TASK_PROMPTS[taskType];+ config.promptVersion = PROMPT_VERSIONS[taskType];+ needsSave = true;+ }}}}