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: sanitize senderInstanceId in subscriptionFilename
[._.]/ Adam Eivy9ff5e45470ca
diff --git a/server/services/sharing/manifest.js b/server/services/sharing/manifest.jsindex 1f5225387d..d7ededb271 100644--- a/server/services/sharing/manifest.js+++ b/server/services/sharing/manifest.js@@ -198,9 +198,13 @@ export const SUBSCRIPTION_FILE_PREFIX = 'sub-';* and the reader (subscriptions service, watcher) so the formula stays in* one place. The `senderInstanceId` segment keeps two peers' shares of the* same record from colliding; absent senderInstanceId falls back to- * `'unknown'` so the filename is always valid. */+ * `'unknown'` so the filename is always valid. The sender segment is+ * sanitized with the same allowlist/length cap used by+ * `annotationManifestFilename` so a malformed persisted instance id+ * containing path separators can't escape the `manifests` directory. */export function subscriptionFilename({ recordKind, recordId, senderInstanceId }) {- const sender = (isStr(senderInstanceId) ? senderInstanceId.trim() : '') || 'unknown';+ const raw = (isStr(senderInstanceId) ? senderInstanceId.trim() : '') || 'unknown';+ const sender = raw.replace(/[^A-Za-z0-9_-]/g, '_').slice(0, 80) || 'unknown';return `${SUBSCRIPTION_FILE_PREFIX}${recordKind}-${recordId}-${sender}.json`;}diff --git a/server/services/sharing/manifest.test.js b/server/services/sharing/manifest.test.jsindex b91f4078f4..2bc3b44d85 100644--- a/server/services/sharing/manifest.test.js+++ b/server/services/sharing/manifest.test.js@@ -274,4 +274,33 @@ describe('sharing/manifest', () => {expect(manifest.legacySubscriptionFilename({ recordKind: 'series', recordId: 'ser-1' })).toBe('sub-series-ser-1.json');});++ it('subscriptionFilename sanitizes path separators and other unsafe chars from senderInstanceId', () => {+ // A malformed persisted instance id with path separators must not be+ // able to escape the manifests directory or create nested paths.+ const f1 = manifest.subscriptionFilename({+ recordKind: 'universe', recordId: 'uni-1', senderInstanceId: '../../../etc/passwd',+ });+ expect(f1).not.toMatch(/[/\\]/);+ expect(f1).toBe('sub-universe-uni-1-_________etc_passwd.json');++ const f2 = manifest.subscriptionFilename({+ recordKind: 'series', recordId: 'ser-1', senderInstanceId: 'inst/with\\slashes',+ });+ expect(f2).not.toMatch(/[/\\]/);+ expect(f2).toBe('sub-series-ser-1-inst_with_slashes.json');++ // Length cap: a wildly oversized id is truncated to 80 chars.+ const long = 'A'.repeat(200);+ const f3 = manifest.subscriptionFilename({+ recordKind: 'universe', recordId: 'uni-1', senderInstanceId: long,+ });+ expect(f3).toBe(`sub-universe-uni-1-${'A'.repeat(80)}.json`);++ // An id of all separator chars is fully escaped, never empty.+ const f4 = manifest.subscriptionFilename({+ recordKind: 'universe', recordId: 'uni-1', senderInstanceId: '///',+ });+ expect(f4).toBe('sub-universe-uni-1-___.json');+ });});