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

fix: keep detected icon paths under the registered repository

Adam Eivy408074f4f465
diff --git a/server/services/appIconDetect.js b/server/services/appIconDetect.js
index 14e063dada..78e3740ba9 100644
--- a/server/services/appIconDetect.js
+++ b/server/services/appIconDetect.js
@@ -1,6 +1,6 @@
import { existsSync } from 'fs';
import { readdir, realpath, stat } from 'fs/promises';
-import { join, extname } from 'path';
+import { isAbsolute, join, extname, relative } from 'path';
import { isPathInsideDir, isTopLevelEntryName, safeJSONParse, tryReadFile } from '../lib/fileUtils.js';
/**
@@ -58,11 +58,28 @@ const CONTENT_TYPES = {
const ICON_EXTENSIONS = new Set(Object.keys(CONTENT_TYPES));
+/**
+ * Spell `realFile` under the caller's `repoPath` after containment has been
+ * decided on real paths. Native realpath expands Windows 8.3 names
+ * (`RUNNER~1` → `runneradmin`) and a symlinked repository root; storing that
+ * expanded spelling would no longer sit on the path the app was registered with.
+ * @param {string} repoPath
+ * @param {string} realRoot
+ * @param {string} realFile
+ * @returns {string|null}
+ */
+function pathSpelledUnderRepo(repoPath, realRoot, realFile) {
+ const rel = relative(realRoot, realFile);
+ if (!rel || isAbsolute(rel) || rel.split(/[\\/]/).includes('..')) return null;
+ return join(repoPath, rel);
+}
+
/**
* Real path of a regular file that stays inside `repoPath` after symlinks are
* resolved. A stored icon, an Xcode manifest, or a repo symlink can otherwise
* name a host file and the icon route will return its bytes. `extensions`
* limits the resolved target, so `favicon.svg -> .env` is not an icon.
+ * The returned path keeps the caller's repository spelling.
* @param {string} repoPath
* @param {string} candidatePath
* @param {Set<string>} extensions lowercase extensions including the dot
@@ -80,7 +97,7 @@ async function resolveContainedFile(repoPath, candidatePath, extensions) {
if (!info.isFile()) return null;
if (!extensions.has(extname(resolved).toLowerCase())) return null;
if (!isPathInsideDir(root, resolved)) return null;
- return resolved;
+ return pathSpelledUnderRepo(repoPath, root, resolved);
} catch {
return null;
}
diff --git a/server/services/appIconDetect.test.js b/server/services/appIconDetect.test.js
index 16c8820433..fd186f335b 100644
--- a/server/services/appIconDetect.test.js
+++ b/server/services/appIconDetect.test.js
@@ -25,6 +25,15 @@ describe('detectAppIcon', () => {
expect(await detectAppIcon('/no/such/path', 'express')).toBe(null);
});
+ it('keeps the caller repository spelling when the root is a symlink', async () => {
+ mkdirSync(join(repoPath, 'public'), { recursive: true });
+ writeFileSync(join(repoPath, 'public', 'favicon.svg'), '<svg><circle/></svg>');
+ const linked = join(scratch, 'linked-repo');
+ symlinkSync(repoPath, linked, process.platform === 'win32' ? 'junction' : 'dir');
+
+ expect(await detectAppIcon(linked, 'express')).toBe(join(linked, 'public', 'favicon.svg'));
+ });
+
it('finds favicon.svg in client/public', async () => {
mkdirSync(join(repoPath, 'client', 'public'), { recursive: true });
writeFileSync(join(repoPath, 'client', 'public', 'favicon.svg'), '<svg><circle/></svg>');