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: address code review findings — XSS, toast styling, diff logic, input sanitization

Adam Eivyd1449329d110
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index ecfffd84f9..8b9919b845 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -54,3 +54,9 @@
## Fixed
- JIRA report provider discovery now tries all available API providers instead of failing on first unreachable one
- `agentCliSpawning.js` imported `completeExecution`/`errorExecution` from `executionLanes.js` (wrong module); corrected to import from `toolStateMachine.js`, fixing server crash on startup
+- XSS: `MarkdownOutput.jsx` links now validate `href` protocol (allow `http://`, `https://`, `/` only); unsafe URIs render as plain text
+- Toast notifications missing background color — added `bg-port-card` with border
+- `InlineDiff` word diff used `Set` which collapsed duplicate common words; replaced with sequential LCS pointer matching
+- `httpClient.js` now auto-sets `Content-Type: application/json` when sending JSON body
+- `zipStream.js` sanitizes ZIP entry paths (normalizes separators, strips `..` and `.` components)
+- `multipart.js` sanitizes file extension to alphanumeric characters only
diff --git a/client/src/components/cos/MarkdownOutput.jsx b/client/src/components/cos/MarkdownOutput.jsx
index 834df803f8..8a4ad6854a 100644
--- a/client/src/components/cos/MarkdownOutput.jsx
+++ b/client/src/components/cos/MarkdownOutput.jsx
@@ -18,7 +18,13 @@ function parseInline(text) {
parts.push(<em key={m.index} className="text-gray-300 italic">{s.slice(1, -1)}</em>);
} else {
const lm = s.match(/\[([^\]]+)\]\(([^)]+)\)/);
- if (lm) parts.push(<a key={m.index} href={lm[2]} className="text-port-accent hover:underline" target="_blank" rel="noopener noreferrer">{lm[1]}</a>);
+ if (lm) {
+ const href = lm[2];
+ const safeHref = /^(https?:\/\/|\/[^/])/.test(href) ? href : null;
+ parts.push(safeHref
+ ? <a key={m.index} href={safeHref} className="text-port-accent hover:underline" target="_blank" rel="noopener noreferrer">{lm[1]}</a>
+ : <span key={m.index} className="text-port-accent">{lm[1]}</span>);
+ }
}
last = m.index + s.length;
}
diff --git a/client/src/components/insights/CrossDomainTab.jsx b/client/src/components/insights/CrossDomainTab.jsx
index 40ed958485..ee67eaee69 100644
--- a/client/src/components/insights/CrossDomainTab.jsx
+++ b/client/src/components/insights/CrossDomainTab.jsx
@@ -23,13 +23,15 @@ function lcs(a, b) {
const InlineDiff = memo(function InlineDiff({ oldText, newText }) {
const oldWords = (oldText || '').split(/(\s+)/);
const newWords = (newText || '').split(/(\s+)/);
- const common = new Set(lcs(oldWords, newWords));
+ const commonSeq = lcs(oldWords, newWords);
const render = (words, added) => {
const spans = [];
let run = [];
+ let ci = 0;
words.forEach((w, i) => {
- if (common.has(w)) {
+ if (ci < commonSeq.length && w === commonSeq[ci]) {
+ ci++;
if (run.length) { spans.push(<span key={i + 'r'} className={added ? 'bg-green-900/50 text-green-300' : 'bg-red-900/50 text-red-300'}>{run.join('')}</span>); run = []; }
spans.push(w);
} else { run.push(w); }
diff --git a/client/src/components/ui/Toast.jsx b/client/src/components/ui/Toast.jsx
index 64e9dfad34..16cc5e5605 100644
--- a/client/src/components/ui/Toast.jsx
+++ b/client/src/components/ui/Toast.jsx
@@ -75,7 +75,7 @@ export function Toaster({ position = 'bottom-right', toastOptions = {} }) {
const iconStr = t.icon ?? (t.type !== 'default' ? TYPE_ICON[t.type] : null);
const iconClass = t.type !== 'default' ? TYPE_CLASS[t.type] : '';
return (
- <div key={t.id} style={style} className="pointer-events-auto flex items-start gap-2 shadow-lg text-sm max-w-[520px]">
+ <div key={t.id} style={style} className="pointer-events-auto flex items-start gap-2 shadow-lg text-sm max-w-[520px] bg-port-card border border-port-border">
{iconStr && <span className={`shrink-0 ${iconClass}`}>{iconStr}</span>}
<div className="flex-1 min-w-0">
{typeof t.content === 'function' ? t.content({ id: t.id }) : <span>{t.content}</span>}
diff --git a/server/lib/httpClient.js b/server/lib/httpClient.js
index 96ba4b6d4b..1209866c8c 100644
--- a/server/lib/httpClient.js
+++ b/server/lib/httpClient.js
@@ -63,7 +63,12 @@ export function createHttpClient({ baseURL = '', headers: defaultHeaders = {}, t
signal: AbortSignal.timeout(timeout)
};
- if (data !== undefined) options.body = JSON.stringify(data);
+ if (data !== undefined) {
+ options.body = JSON.stringify(data);
+ if (!options.headers['Content-Type'] && !options.headers['content-type']) {
+ options.headers['Content-Type'] = 'application/json';
+ }
+ }
const res = await fetchFn(url, options);
const ct = res.headers.get('content-type') || '';
diff --git a/server/lib/multipart.js b/server/lib/multipart.js
index 61642bc5e6..c254131c41 100644
--- a/server/lib/multipart.js
+++ b/server/lib/multipart.js
@@ -99,7 +99,8 @@ function parseStream(stream, boundary, fieldName, maxSize, fileFilter, next) {
const originalname = dispMatch[2];
const mimeMatch = headerStr.match(/Content-Type:\s*([^\r\n]+)/i);
const mimetype = mimeMatch ? mimeMatch[1].trim() : 'application/octet-stream';
- const ext = originalname.match(/\.[^.]+$/)?.[0] || '';
+ const rawExt = originalname.match(/\.[^.]+$/)?.[0] || '';
+ const ext = rawExt.replace(/[^a-zA-Z0-9.]/g, '');
fileMeta = { originalname, mimetype };
if (fileFilter) {
diff --git a/server/lib/zipStream.js b/server/lib/zipStream.js
index 90c5eec391..68b3dde894 100644
--- a/server/lib/zipStream.js
+++ b/server/lib/zipStream.js
@@ -79,7 +79,9 @@ export function parseZip() {
if (buf.length < headerSize) return;
- const name = buf.slice(30, 30 + nameLen).toString('utf-8');
+ const rawName = buf.slice(30, 30 + nameLen).toString('utf-8');
+ // Sanitize: normalize path separators and reject directory traversal
+ const name = rawName.replace(/\\/g, '/').split('/').filter(s => s !== '..' && s !== '.').join('/');
const dataDescriptor = (flags & 0x0008) !== 0; // bit 3: sizes in data descriptor
buf = buf.slice(headerSize);