Skip to content

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

address review: annotation-sync tombstones + path-traversal guard + log fix

[._.]/ Adam Eivy30bf027b8d17
diff --git a/scripts/migrations/014-attribute-existing-annotations.js b/scripts/migrations/014-attribute-existing-annotations.js
index b9077c6c4b..2a7816cd84 100644
--- a/scripts/migrations/014-attribute-existing-annotations.js
+++ b/scripts/migrations/014-attribute-existing-annotations.js
@@ -69,7 +69,7 @@ export default {
return { changed: false, alreadyCurrent };
}
await writeFile(annotationsPath, JSON.stringify({ annotations: next }, null, 2));
- console.log(`📝 migration 012: attributed ${migrated} annotation(s) to instanceId=${instanceId} (already-multi-author=${alreadyCurrent})`);
+ console.log(`📝 migration 014: attributed ${migrated} annotation(s) to instanceId=${instanceId} (already-multi-author=${alreadyCurrent})`);
return { changed: true, migrated, alreadyCurrent };
},
};
diff --git a/server/services/mediaAnnotations.js b/server/services/mediaAnnotations.js
index 4c8a964037..50fe7ab01f 100644
--- a/server/services/mediaAnnotations.js
+++ b/server/services/mediaAnnotations.js
@@ -48,8 +48,8 @@ function sanitizeAuthorEntry(raw) {
return { authorName, starred, note, updatedAt };
}
-// Safety net for a stale install: migration 012 rewrites the file once, but a
-// hand-edited or pre-012 file still parses correctly here.
+// Safety net for a stale install: migration 014 rewrites the file once, but a
+// hand-edited or pre-014 file still parses correctly here.
async function liftLegacyEntry(rawEntry) {
const isLegacy = rawEntry
&& typeof rawEntry === 'object'
diff --git a/server/services/sharing/annotationsSync.js b/server/services/sharing/annotationsSync.js
index 069444ddcd..e72ea5c73b 100644
--- a/server/services/sharing/annotationsSync.js
+++ b/server/services/sharing/annotationsSync.js
@@ -9,7 +9,7 @@
import { join } from 'path';
import { readdir } from 'fs/promises';
import { existsSync } from 'fs';
-import { ensureDir, atomicWrite } from '../../lib/fileUtils.js';
+import { ensureDir, atomicWrite, readJSONFile } from '../../lib/fileUtils.js';
import { listBuckets } from './buckets.js';
import { buildManifest, writeManifest, annotationManifestFilename } from './manifest.js';
import { getProducedByVersion } from './version.js';
@@ -47,15 +47,38 @@ async function exportAnnotationsToBucket(bucket, localAnnotations, senderInstanc
await ensureDir(recordDir);
const recordId = senderInstanceId;
const recordPath = join(recordDir, `${recordId}.json`);
+
+ // Tombstone synthesis: peers only learn about deletions by seeing them. The
+ // import-side merge (`mergePeerAnnotations`) iterates incoming keys and
+ // treats `sanitizeAuthorEntry` returning null as "delete the peer's entry."
+ // So we diff the previously-written record (for this bucket+instance) for
+ // keys we used to publish but no longer do, and emit an explicit empty
+ // tombstone for each. Without this, a local delete shows up as "the key is
+ // simply absent from the next snapshot" — and peers retain the stale note
+ // forever. Scoped per-bucket because each bucket's prior record is its own
+ // file, so a key dropped from bucket A doesn't tombstone the same key on
+ // bucket B (it may still be valid there).
+ const tombstoneTs = new Date().toISOString();
+ const prior = await readJSONFile(recordPath, null, { logError: false });
+ const priorKeys = prior && prior.annotations && typeof prior.annotations === 'object'
+ ? Object.keys(prior.annotations)
+ : [];
+ for (const key of priorKeys) {
+ if (filtered[key]) continue;
+ // Only tombstone keys whose assets are still in this bucket — pruning a
+ // key whose asset has been removed from the bucket would tell peers to
+ // delete the note even though they may still hold the asset.
+ if (!assetKeys.has(key)) continue;
+ filtered[key] = { starred: false, note: '', updatedAt: tombstoneTs };
+ }
+
const record = {
id: recordId,
instanceId: senderInstanceId,
authorName: sourceName,
- updatedAt: new Date().toISOString(),
+ updatedAt: tombstoneTs,
annotations: filtered,
};
- // Always write the record even when filtered is empty — an empty payload is
- // how we signal "I deleted all my notes on assets in this bucket" to peers.
await atomicWrite(recordPath, record);
const manifest = buildManifestForAnnotations({
senderInstanceId,
diff --git a/server/services/sharing/exporter.js b/server/services/sharing/exporter.js
index e286e2c7c7..b3a5d83d8f 100644
--- a/server/services/sharing/exporter.js
+++ b/server/services/sharing/exporter.js
@@ -90,8 +90,17 @@ async function copyAssetIfPresent(filename, kind, bucketPath) {
* Build a synthetic job record from a `.metadata.json` sidecar when the
* in-memory queue/archive no longer holds the job (>24h TTL). The sidecar
* lives alongside the image file so its lifetime is tied to the asset.
+ *
+ * Guards against path traversal: rejects any jobId that contains a path
+ * separator, parent-directory token, or otherwise normalizes to something
+ * other than its bare basename. A corrupted or hostile imageJobId
+ * (`../../etc/passwd`, `..\foo`, absolute paths) could otherwise read
+ * arbitrary JSON outside `PATHS.images`. Same posture as `copyAssetIfPresent`.
*/
async function jobFromSidecar(jobId) {
+ if (typeof jobId !== 'string' || !jobId) return null;
+ if (basename(jobId) !== jobId) return null;
+ if (jobId.includes('/') || jobId.includes('\\') || jobId.includes('..')) return null;
const sc = await readJSONFile(join(PATHS.images, `${jobId}.metadata.json`));
if (!sc) return null;
return {