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([issue-2895]): reject traversal-capable manifest paths in the sprite importer
[._.]/ Adam Eivy1d6d07ed4c5f
diff --git a/server/services/sprites/importer.js b/server/services/sprites/importer.jsindex 94830b797c..aa9ee925d9 100644--- a/server/services/sprites/importer.js+++ b/server/services/sprites/importer.js@@ -99,13 +99,17 @@ async function verifyHashes(destDir, expectations, errors) {// Manifest paths reference files repo-relative (art-source/sprites/<id>/…) or// occasionally bare. Normalize to a path relative to the character's source-// dir so it can be re-anchored under data/sprites/<id>/.+// dir so it can be re-anchored under data/sprites/<id>/. Manifest content is+// request-influenced data feeding join() as a WRITE destination, so a `..`+// segment (or empty segment) rejects the whole path — a corrupt/crafted+// manifest must not be able to copy outside data/sprites/.function relToCharacterDir(manifestPath, characterId) {if (typeof manifestPath !== 'string' || !manifestPath) return null;const marker = `sprites/${characterId}/`;const idx = manifestPath.indexOf(marker);- if (idx >= 0) return manifestPath.slice(idx + marker.length);- return manifestPath.replace(/^\/+/, '');+ const rel = idx >= 0 ? manifestPath.slice(idx + marker.length) : manifestPath.replace(/^\/+/, '');+ if (!rel || rel.split('/').some((seg) => seg === '..' || seg === '')) return null;+ return rel;}async function importCharacter({ sourceRoot, characterId, spec, specPath }) {@@ -147,9 +151,12 @@ async function importCharacter({ sourceRoot, characterId, spec, specPath }) {for (const rel of copied) {if (!rel.endsWith('.json')) continue;const walkSet = await readJson(join(destDir, 'walk', rel));- for (const [, dir] of Object.entries(walkSet?.directions || {})) {+ for (const [direction, dir] of Object.entries(walkSet?.directions || {})) {const runRel = relToCharacterDir(dir?.runPath, characterId);- if (!runRel) continue;+ if (!runRel) {+ if (dir?.runPath) result.errors.push(`walk set ${direction}: unsafe run path rejected: ${dir.runPath}`);+ continue;+ }const srcRunDir = join(srcCharDir, runRel);if (!(await pathExists(srcRunDir))) {result.errors.push(`walk set references missing run: ${runRel}`);diff --git a/server/services/sprites/importer.test.js b/server/services/sprites/importer.test.jsindex 273837ca08..f793ca412d 100644--- a/server/services/sprites/importer.test.js+++ b/server/services/sprites/importer.test.js@@ -63,6 +63,14 @@ beforeAll(() => {runManifest: 'art-source/sprites/hero/grok/run-1/south-manifest.json',runManifestSha256: sha256(runManifest),},+ // Traversal attempt: a crafted runPath must be rejected, never joined+ // into a write destination outside data/sprites/.+ north: {+ status: 'approved',+ runPath: 'art-source/sprites/hero/../../../../tmp/sprite-escape',+ runManifest: 'art-source/sprites/hero/../../../../tmp/sprite-escape/x.json',+ runManifestSha256: sha256('x'),+ },},},'art-source/sprites/hero/grok/run-1/south-manifest.json': runManifest,@@ -90,7 +98,11 @@ describe('importFromSource', () => {expect(hero.kind).toBe('character');// one good anchor + the run manifest verify; the tampered east anchor errorsexpect(hero.verified).toBe(2);- expect(hero.errors).toEqual(['sha256 mismatch: reference/hero-anchor-east.png']);+ expect(hero.errors).toEqual([+ 'walk set north: unsafe run path rejected: art-source/sprites/hero/../../../../tmp/sprite-escape',+ 'sha256 mismatch: reference/hero-anchor-east.png',+ ]);+ expect(existsSync('/tmp/sprite-escape')).toBe(false);const heroDir = join(SPRITES_ROOT, 'hero');expect(existsSync(join(heroDir, 'character-spec.json'))).toBe(true);@@ -111,7 +123,7 @@ describe('importFromSource', () => {expect(results.some((r) => r.id === 'hero' && r.kind === 'props')).toBe(false);expect(totals.subjects).toBe(2);- expect(totals.errors).toBe(1);+ expect(totals.errors).toBe(2);const record = await getRecord('hero');expect(record).toMatchObject({ kind: 'character', name: 'Hero', status: 'imported', chromaKey: '#FF00FF' });