Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(xss): escape third-party feed values before they reach innerHTML

nirholas220594f2f659
diff --git a/api/creations.js b/api/creations.js
index 1b48b1931..ed21264e0 100644
--- a/api/creations.js
+++ b/api/creations.js
@@ -66,6 +66,9 @@ const LICENSES = {
'all-rights': { label: 'All rights reserved', remixable: false, commercial: false, note: 'Display only, no remixing.' },
};
const DEFAULT_LICENSE = 'remix-cc';
+// Own keys only: a plain lookup let `constructor`, `__proto__` or `toString`
+// through as a "license", which then rendered as a function instead of terms.
+const isLicense = (id) => typeof id === 'string' && Object.hasOwn(LICENSES, id);
// Style + type vocabularies power the discovery filters. Free-text tags still
// flow through search; these are the curated facets.
@@ -326,8 +329,8 @@ async function enrich(creation, { withChildren = false, overlay = null } = {}) {
type: meta?.type || inferred.type,
style: meta?.style || inferred.style,
tags: meta?.tags || inferred.tags,
- license: meta?.license || DEFAULT_LICENSE,
- licenseInfo: LICENSES[meta?.license || DEFAULT_LICENSE],
+ license: isLicense(meta?.license) ? meta.license : DEFAULT_LICENSE,
+ licenseInfo: LICENSES[isLicense(meta?.license) ? meta.license : DEFAULT_LICENSE],
parentId: meta?.parentId || null,
royalty: meta?.royalty || null,
createdAt: Number(creation.createdAt) || meta?.publishedAt || 0,
@@ -399,7 +402,7 @@ async function handleFeed(req, res, url) {
type: TYPES.includes(url.searchParams.get('type')) ? url.searchParams.get('type') : null,
style: STYLES.includes(url.searchParams.get('style')) ? url.searchParams.get('style') : null,
creator: sanitizeOptionalString(url.searchParams.get('creator'), 64),
- license: LICENSES[url.searchParams.get('license')] ? url.searchParams.get('license') : null,
+ license: isLicense(url.searchParams.get('license')) ? url.searchParams.get('license') : null,
};
// Pull a deep slice of the canonical Loom feed, enrich, filter, then rank.
@@ -625,7 +628,7 @@ async function handlePublish(req, res, body) {
const tags = sanitizeTags(body?.tags);
const type = TYPES.includes(body?.type) ? body.type : null;
const style = STYLES.includes(body?.style) ? body.style : null;
- const license = LICENSES[body?.license] ? body.license : DEFAULT_LICENSE;
+ const license = isLicense(body?.license) ? body.license : DEFAULT_LICENSE;
const royalty = sanitizeRoyalty(body?.royalty);
const parentId = sanitizeOptionalString(body?.parentId, 64);
const previewImageUrl = sanitizeOptionalString(body?.previewImageUrl, 600);
diff --git a/src/bounties.js b/src/bounties.js
index 1ebdf7387..d812fef32 100644
--- a/src/bounties.js
+++ b/src/bounties.js
@@ -380,9 +380,11 @@ function timeLeft(iso) {
const m = Math.floor((ms % 3600000) / 60000);
return `${h}h ${m}m`;
}
+// Addresses come from pump.fun's feed, so the result is escaped for innerHTML.
function shortAddr(a) {
if (!a) return 'anon';
- return a.length > 12 ? `${a.slice(0, 4)}…${a.slice(-4)}` : a;
+ const s = String(a);
+ return esc(s.length > 12 ? `${s.slice(0, 4)}…${s.slice(-4)}` : s);
}
function iconUser() {
return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="8" r="3.2"/><path d="M5 20c0-3.3 3.1-5.5 7-5.5s7 2.2 7 5.5"/></svg>`;
diff --git a/src/bounty-detail.js b/src/bounty-detail.js
index 93b2842e9..60bf30dd6 100644
--- a/src/bounty-detail.js
+++ b/src/bounty-detail.js
@@ -232,9 +232,11 @@ function timeAgo(iso) {
if (h < 24) return `${h}h ago`;
return `${Math.floor(h / 24)}d ago`;
}
+// Addresses come from pump.fun's feed, so the result is escaped for innerHTML.
function shortAddr(a) {
if (!a) return 'anon';
- return a.length > 12 ? `${a.slice(0, 4)}…${a.slice(-4)}` : a;
+ const s = String(a);
+ return esc(s.length > 12 ? `${s.slice(0, 4)}…${s.slice(-4)}` : s);
}
init();
diff --git a/src/drops.js b/src/drops.js
index 04676227c..696a975c4 100644
--- a/src/drops.js
+++ b/src/drops.js
@@ -107,7 +107,14 @@ function cardFor(drop) {
const meta = document.createElement('div');
meta.className = 'dr-card-meta';
- meta.innerHTML = `<span>${drop.symbol}</span><span aria-hidden="true">·</span><span>${supply.toLocaleString()} supply</span>`;
+ const symbolEl = document.createElement('span');
+ symbolEl.textContent = drop.symbol;
+ const dot = document.createElement('span');
+ dot.setAttribute('aria-hidden', 'true');
+ dot.textContent = '·';
+ const supplyEl = document.createElement('span');
+ supplyEl.textContent = `${supply.toLocaleString()} supply`;
+ meta.append(symbolEl, dot, supplyEl);
if (drop.status !== 'live') {
const status = document.createElement('span');
status.className = 'dr-status';
diff --git a/src/feedback-companion.js b/src/feedback-companion.js
index 643bcd4b2..aa64c5a60 100644
--- a/src/feedback-companion.js
+++ b/src/feedback-companion.js
@@ -321,8 +321,8 @@ export function installFeedback({ getInstance, getHostEl } = {}) {
const signals = capturedSignals();
const sha = await buildSha();
const steps = capturedSteps();
- const bits = [`<b>Page</b> <code>${location.pathname}</code>`];
- if (sha) bits.push(`<b>Build</b> <code>${sha}</code>`);
+ const bits = [`<b>Page</b> <code>${escapeHtml(location.pathname)}</code>`];
+ if (sha) bits.push(`<b>Build</b> <code>${escapeHtml(sha)}</code>`);
if (signals.errors.length) bits.push(`<b>${signals.errors.length}</b> console error${signals.errors.length > 1 ? 's' : ''}`);
if (signals.failures.length) bits.push(`<b>${signals.failures.length}</b> failed request${signals.failures.length > 1 ? 's' : ''}`);
// Naming the step count is what makes the recorder feel like help rather
diff --git a/src/globe-intel.js b/src/globe-intel.js
index 72735f827..3607ddcf7 100644
--- a/src/globe-intel.js
+++ b/src/globe-intel.js
@@ -45,6 +45,7 @@ import {
WebGLRenderer,
} from 'three';
import { escapeHtml } from './shared/coin-format.js';
+import { safeUrl } from './safe-url.js';
import {
GLOBE_RADIUS,
LAYERS,
@@ -853,6 +854,10 @@ function renderDetail() {
['Source', event.source || data?.source || 'Unattributed'],
].filter(Boolean);
+ // Source links come from third-party feeds (GDELT, EONET, GDACS), so only an
+ // http(s) or site-relative link is ever rendered as a clickable anchor.
+ const sourceHref = safeUrl(event.url, '');
+
dom.detailBody.innerHTML = `
<span class="gi-detail-kind">${escapeHtml(layer?.label || layerId || 'Event')}</span>
<h3>${escapeHtml(event.title)}</h3>
@@ -861,7 +866,7 @@ function renderDetail() {
<dl>${rows.map(([k, v]) => `<dt>${escapeHtml(k)}</dt><dd>${escapeHtml(String(v))}</dd>`).join('')}</dl>
<div class="gi-detail-actions">
<button type="button" data-action="focus">Focus on globe</button>
- ${event.url ? `<a href="${escapeHtml(event.url)}" target="_blank" rel="noopener noreferrer">Open source</a>` : ''}
+ ${sourceHref ? `<a href="${escapeHtml(sourceHref)}" target="_blank" rel="noopener noreferrer">Open source</a>` : ''}
</div>
`;
dom.detail.hidden = false;
diff --git a/src/hood-desk.js b/src/hood-desk.js
index d3122fc24..ef393f93b 100644
--- a/src/hood-desk.js
+++ b/src/hood-desk.js
@@ -546,7 +546,7 @@ function ridgeSvg(ridge) {
1,
)}" height="${(frontBase - padT).toFixed(1)}" data-bin="${i}"><title>${count} token${
count === 1 ? '' : 's'
- } at ${b.from.toFixed(2)}% to ${b.to.toFixed(2)}%${symbols ? `: ${symbols}` : ''}</title></rect>`;
+ } at ${b.from.toFixed(2)}% to ${b.to.toFixed(2)}%${symbols ? `: ${esc(symbols)}` : ''}</title></rect>`;
})
.join('');
diff --git a/tests/safe-url.test.js b/tests/safe-url.test.js
new file mode 100644
index 000000000..3e25d4f24
--- /dev/null
+++ b/tests/safe-url.test.js
@@ -0,0 +1,25 @@
+import { describe, it, expect } from 'vitest';
+import { safeUrl } from '../src/safe-url.js';
+
+describe('safeUrl', () => {
+ it('keeps http(s) and site-relative links', () => {
+ expect(safeUrl('https://example.com/a?b=1')).toBe('https://example.com/a?b=1');
+ expect(safeUrl('HTTP://example.com')).toBe('HTTP://example.com');
+ expect(safeUrl('/oracle/coin/abc')).toBe('/oracle/coin/abc');
+ expect(safeUrl('./x')).toBe('./x');
+ expect(safeUrl('#top')).toBe('#top');
+ });
+
+ it('rejects script-bearing and odd schemes', () => {
+ for (const bad of ['javascript:alert(1)', ' JavaScript:alert(1)', 'data:text/html,<script>', 'vbscript:x', '//evil.example/x', 'java\tscript:alert(1)']) {
+ expect(safeUrl(bad)).toBe('#');
+ }
+ });
+
+ it('returns the caller fallback so a rejected link can be omitted entirely', () => {
+ expect(safeUrl('javascript:alert(1)', '')).toBe('');
+ expect(safeUrl(null, '')).toBe('');
+ expect(safeUrl('', '')).toBe('');
+ expect(safeUrl(42, '')).toBe('');
+ });
+});