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(apps): pre-seed PortOS icon path; skip CSP-broken SVGs in detector

Adam Eivy03e281896bb6
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 0d42141308..c7df99e939 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -26,3 +26,4 @@ A page-level run dock now slides up from the bottom of the Writers Room while im
- Stale-chunk auto-reload now covers Safari ("Importing a module script failed") and Firefox ("error loading dynamically imported module") in addition to Chrome — previously iOS Safari users hit a "Something went wrong" error after a rebuild and had to tap Refresh manually. Detection is shared between `lazyWithReload` (the primary path) and `ErrorBoundary` (safety net), with a one-reload-per-session guard against infinite loops.
- `ErrorBoundary` now uses theme-aware `text-port-text` / `text-port-text-muted` / `text-port-on-accent` instead of hardcoded `text-white` / `text-gray-400`, so the fallback UI is readable on light themes (Lumen Glass, etc).
+- App icon detection: ship `data.sample/apps.json` with PortOS's icon path pre-set to `client/public/portos-logo.png`, and harden `detectAppIcon()` to skip SVGs that embed external `<image href="…">` (the icon endpoint serves SVG with `default-src 'none'` CSP, so those embeds are blocked and the icon renders blank). Detector now also checks `apple-touch-icon.png` and `icon-{192,512}.png` so PWAs without a usable favicon still resolve to a high-res raster. Hit "Detect Icon" once on existing installs to repick.
diff --git a/data.sample/apps.json b/data.sample/apps.json
index ab66cb8ba1..e5d13d6d10 100644
--- a/data.sample/apps.json
+++ b/data.sample/apps.json
@@ -21,6 +21,7 @@
],
"envFile": ".env",
"icon": "portos",
+ "appIconPath": "__PORTOS_ROOT__/client/public/portos-logo.png",
"editorCommand": "code .",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z",
diff --git a/server/services/appIconDetect.js b/server/services/appIconDetect.js
index 5faa0cef50..fa2e73090e 100644
--- a/server/services/appIconDetect.js
+++ b/server/services/appIconDetect.js
@@ -10,22 +10,29 @@ import { safeJSONParse } from '../lib/fileUtils.js';
const ICON_SEARCH_PATHS = [
// Web app favicons/logos
'public/favicon.svg',
+ 'public/apple-touch-icon.png',
'public/favicon.png',
'public/favicon.ico',
'public/logo.svg',
'public/logo.png',
'public/icon.svg',
'public/icon.png',
- 'public/logo192.png',
+ 'public/icon-512.png',
+ 'public/icon-192.png',
'public/logo512.png',
+ 'public/logo192.png',
'client/public/favicon.svg',
+ 'client/public/apple-touch-icon.png',
'client/public/favicon.png',
'client/public/favicon.ico',
'client/public/logo.svg',
'client/public/logo.png',
- 'client/public/logo192.png',
+ 'client/public/icon-512.png',
+ 'client/public/icon-192.png',
'client/public/logo512.png',
+ 'client/public/logo192.png',
'static/favicon.svg',
+ 'static/apple-touch-icon.png',
'static/favicon.png',
'static/favicon.ico',
// Electron / desktop
@@ -49,6 +56,17 @@ const CONTENT_TYPES = {
'.webp': 'image/webp',
};
+// SVGs that embed an external <image href="..."> won't render under the icon
+// endpoint's strict `default-src 'none'` CSP, so they are unusable as app icons
+// even though the file exists. Skip them and let detection fall through to a
+// sibling PNG/raster file. Inline data: URIs are fine.
+async function isUsableSvg(filePath) {
+ const content = await readFile(filePath, 'utf-8').catch(() => null);
+ if (content === null) return false;
+ const externalImage = /<image\b[^>]*\b(?:xlink:)?href\s*=\s*['"](?!data:)/i;
+ return !externalImage.test(content);
+}
+
/**
* Find the best Xcode AppIcon image from an asset catalog.
* Looks for the largest available PNG in the appiconset.
@@ -164,7 +182,9 @@ export async function detectAppIcon(repoPath, appType) {
// Check well-known paths
for (const relPath of ICON_SEARCH_PATHS) {
const fullPath = join(repoPath, relPath);
- if (existsSync(fullPath)) return fullPath;
+ if (!existsSync(fullPath)) continue;
+ if (extname(fullPath).toLowerCase() === '.svg' && !await isUsableSvg(fullPath)) continue;
+ return fullPath;
}
// For any project type, also try Xcode icon detection as a fallback
diff --git a/server/services/appIconDetect.test.js b/server/services/appIconDetect.test.js
new file mode 100644
index 0000000000..345ad297b8
--- /dev/null
+++ b/server/services/appIconDetect.test.js
@@ -0,0 +1,59 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+import { detectAppIcon } from './appIconDetect.js';
+
+const PNG_BYTES = Buffer.from('89504e470d0a1a0a', 'hex');
+
+describe('detectAppIcon', () => {
+ let repoPath;
+
+ beforeEach(() => {
+ repoPath = mkdtempSync(join(tmpdir(), 'icon-detect-'));
+ });
+
+ afterEach(() => {
+ rmSync(repoPath, { recursive: true, force: true });
+ });
+
+ it('returns null for missing repoPath', async () => {
+ expect(await detectAppIcon('', 'express')).toBe(null);
+ expect(await detectAppIcon('/no/such/path', 'express')).toBe(null);
+ });
+
+ 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>');
+ const result = await detectAppIcon(repoPath, 'express');
+ expect(result).toBe(join(repoPath, 'client', 'public', 'favicon.svg'));
+ });
+
+ // Regression: PortOS shipped a favicon.svg containing
+ // `<image href="/portos-logo.png">`. The icon endpoint serves SVG with a
+ // strict `default-src 'none'` CSP, so the embedded raster is blocked and
+ // the icon renders blank. Detector must skip SVGs that pull external
+ // resources and fall through to a self-contained sibling.
+ it('skips SVGs that embed external <image href> and falls through to PNG', async () => {
+ mkdirSync(join(repoPath, 'client', 'public'), { recursive: true });
+ writeFileSync(
+ join(repoPath, 'client', 'public', 'favicon.svg'),
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">' +
+ '<image href="/portos-logo.png" width="512" height="512"/>' +
+ '</svg>'
+ );
+ writeFileSync(join(repoPath, 'client', 'public', 'apple-touch-icon.png'), PNG_BYTES);
+ const result = await detectAppIcon(repoPath, 'express');
+ expect(result).toBe(join(repoPath, 'client', 'public', 'apple-touch-icon.png'));
+ });
+
+ it('keeps an SVG that uses inline data: image hrefs', async () => {
+ mkdirSync(join(repoPath, 'public'), { recursive: true });
+ writeFileSync(
+ join(repoPath, 'public', 'favicon.svg'),
+ '<svg><image href="data:image/png;base64,AAAA"/></svg>'
+ );
+ const result = await detectAppIcon(repoPath, 'express');
+ expect(result).toBe(join(repoPath, 'public', 'favicon.svg'));
+ });
+});