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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(xss): escape owner and third-party fields in character, segment, IBM proof, mission control and gallery views
nirholas1dd6de58cff2
diff --git a/pages/a-edit.html b/pages/a-edit.htmlindex 8a95bcfae..0d98fe9fe 100644--- a/pages/a-edit.html+++ b/pages/a-edit.html@@ -287,7 +287,10 @@document.title = `Edit Agent #${agentId} — three.ws`;mountChainEdit(root, chainId, agentId).catch((err) => {- root.innerHTML = `<div class="ce-error">${err.message}</div>`;+ const box = document.createElement('div');+ box.className = 'ce-error';+ box.textContent = err.message;+ root.replaceChildren(box);});}</script>diff --git a/public/dashboard/portfolio-asset.html b/public/dashboard/portfolio-asset.htmlindex 4caa479be..c91d9f95b 100644--- a/public/dashboard/portfolio-asset.html+++ b/public/dashboard/portfolio-asset.html@@ -373,7 +373,7 @@const name = m.name || asset.symbol || asset.id;const isAddr = !asset.is_native;const explorerHref = isAddr- ? (asset.chain === 'solana' ? `https://solscan.io/token/${asset.id}` : `https://etherscan.io/token/${asset.id}`)+ ? (asset.chain === 'solana' ? `https://solscan.io/token/${encodeURIComponent(asset.id)}` : `https://etherscan.io/token/${encodeURIComponent(asset.id)}`): null;$$('root').innerHTML = `@@ -402,7 +402,7 @@<section><div class="panel"><div class="head-row">- <h2>Price · ${asset.symbol}/USD</h2>+ <h2>Price · ${escapeHtml(asset.symbol)}/USD</h2><div id="chart-change" class="muted" style="font-size:12px"></div></div><div class="chart-wrap">@@ -426,7 +426,7 @@<div class="panel" style="margin-top:14px"><h2>About ${escapeHtml(name)}</h2><div class="desc">${escapeHtml(m.description)}</div>- ${m.homepage ? `<p style="margin-top:10px"><a href="${escapeHtml(m.homepage)}" target="_blank" rel="noopener noreferrer">${escapeHtml(m.homepage)} ↗</a></p>` : ''}+ ${m.homepage && /^https?:\/\//i.test(m.homepage) ? `<p style="margin-top:10px"><a href="${escapeHtml(m.homepage)}" target="_blank" rel="noopener noreferrer">${escapeHtml(m.homepage)} ↗</a></p>` : ''}${isAddr ? `<div class="address"><span>${escapeHtml(asset.id)}</span>diff --git a/public/demos/agents/auto-rig.html b/public/demos/agents/auto-rig.htmlindex e99a9a4ee..26bfea103 100644--- a/public/demos/agents/auto-rig.html+++ b/public/demos/agents/auto-rig.html@@ -340,7 +340,9 @@async function pickFile(file) {currentFile = file;- dropTitle.innerHTML = `<strong>${file.name}</strong>`;+ const nameEl = document.createElement('strong');+ nameEl.textContent = file.name;+ dropTitle.replaceChildren(nameEl);dropSub.textContent = `${(file.size / 1024 / 1024).toFixed(2)} MB`;runBtn.disabled = false;dlBtn.classList.remove('visible');diff --git a/public/discover/discover.js b/public/discover/discover.jsindex a154b5115..066ccad48 100644--- a/public/discover/discover.js+++ b/public/discover/discover.js@@ -777,7 +777,7 @@ function openEmbedModal({ chainId, agentId, name }) {const snippets = {webComponent: `<script type="module" src="${LIB_CDN_URL}"></script>\n<agent-3d src="${agentUri}" mode="inline" width="480px" responsive></agent-3d>`,- iframe: `<iframe src="${embedUrl}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" sandbox="allow-scripts allow-same-origin allow-popups" title="${displayName}"></iframe>`,+ iframe: `<iframe src="${embedUrl}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" sandbox="allow-scripts allow-same-origin allow-popups" title="${escapeAttr(displayName)}"></iframe>`,link: pageUrl,markdown: `[](${pageUrl})`,farcaster: pageUrl,@@ -906,7 +906,7 @@ function openAvatarEmbedModal({ avatarId, glbUrl, name }) {const snippets = {webComponent: `<script type="module" src="${LIB_CDN_URL}"></script>\n<agent-3d src="${apiUrl}" mode="inline" width="480px" responsive></agent-3d>`,- iframe: `<iframe src="${viewerUrl}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" sandbox="allow-scripts allow-same-origin allow-popups" title="${displayName}"></iframe>`,+ iframe: `<iframe src="${viewerUrl}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" sandbox="allow-scripts allow-same-origin allow-popups" title="${escapeAttr(displayName)}"></iframe>`,link: viewerUrl,markdown: `[${displayName}](${viewerUrl})`,};diff --git a/public/gallery/gallery.js b/public/gallery/gallery.jsindex 5334d1c68..1baa292a9 100644--- a/public/gallery/gallery.js+++ b/public/gallery/gallery.js@@ -681,9 +681,9 @@ function openAvatarEmbedModal({ avatarId, glbUrl, name }) {const snippets = {webComponent: `<script type="module" src="${LIB_CDN_URL}"><\/script>\n<agent-3d src="${apiUrl}" mode="inline" width="480px" responsive></agent-3d>`,- iframe: `<iframe src="${viewerUrl}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" sandbox="allow-scripts allow-same-origin allow-popups" title="${displayName}"></iframe>`,+ iframe: `<iframe src="${viewerUrl}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" sandbox="allow-scripts allow-same-origin allow-popups" title="${escapeAttr(displayName)}"></iframe>`,link: viewerUrl,- markdown: `[${displayName}](${viewerUrl})`,+ markdown: `[${displayName.replace(/[[\]\\]/g, '\\$&')}](${viewerUrl})`,};const modal = document.createElement('div');diff --git a/src/agent-wallet-hub/tabs/withdraw.js b/src/agent-wallet-hub/tabs/withdraw.jsindex bc98a681b..a4a6b01c9 100644--- a/src/agent-wallet-hub/tabs/withdraw.js+++ b/src/agent-wallet-hub/tabs/withdraw.js@@ -697,8 +697,9 @@ registerWalletTab({const META = {key_recover: { ic: '🔑', label: 'Key recovered to sign' },limit_change: { ic: '⚙', label: 'Limits updated' },+ receive: { ic: '↓', label: 'Fees claimed' },};- const CAT = { trade: 'Trade', snipe: 'Snipe', x402: 'x402 payment', withdraw: 'Withdrawal' };+ const CAT = { trade: 'Trade', snipe: 'Snipe', x402: 'x402 payment', withdraw: 'Withdrawal', launch: 'Coin launch' };// A spend row marked failed by a policy rule (reason policy_*) is a payment// the natural-language policy STOPPED — surfaced inline so the owner sees// exactly which rule fired. A limit_change with a policy reason is adiff --git a/src/animations-gallery.js b/src/animations-gallery.jsindex d290b4f3b..71bfa8b56 100644--- a/src/animations-gallery.js+++ b/src/animations-gallery.js@@ -963,7 +963,7 @@ els.modalCopyEmbed?.addEventListener('click', async () => {const clip = state.filtered[state.modalIndex];if (!clip) return;const src = `${location.origin}/embed/avatar?anim=${encodeURIComponent(clip.id)}`;- const snippet = `<iframe src="${src}" width="360" height="480" style="border:0;border-radius:12px" allow="autoplay" title="${clip.name} on three.ws"></iframe>`;+ const snippet = `<iframe src="${src}" width="360" height="480" style="border:0;border-radius:12px" allow="autoplay" title="${escHtml(clip.name)} on three.ws"></iframe>`;await navigator.clipboard.writeText(snippet).catch(() => {});flashButton(els.modalCopyEmbed, 'Copied!');});diff --git a/src/character.js b/src/character.jsindex 2a84ee070..1b5f05e78 100644--- a/src/character.js+++ b/src/character.js@@ -13,6 +13,8 @@ import './ui-juice.css';import { countUp } from './ui-juice.js';import { fetchFirstOrNull } from './shared/failover-fetch.js';import { gmgnTokenUrl, dextoolsTokenUrl } from './shared/trading-terminals.js';+import { escapeHtml } from './shared/coin-format.js';+import { safeUrl } from './safe-url.js';let chNetWorthAura = null;@@ -243,13 +245,13 @@ function buildTokenHtml(symbol, mint, marketCapUsd, priceUsd, change24h, holdersconst metaHtml = metaItems.map(m =>`<div class="ch-token-meta-item"><span class="ch-token-meta-label">${m.label}</span>- <span class="ch-token-meta-val">${m.val}</span>+ <span class="ch-token-meta-val">${escapeHtml(m.val)}</span></div>`).join('');return `<div class="ch-token-header">- <span class="ch-token-name">${symbol}</span>+ <span class="ch-token-name">${escapeHtml(symbol)}</span><span class="ch-token-dot"></span></div><div class="ch-token-price">@@ -289,37 +291,6 @@ async function renderToken(agent) {let holders = token.holders ?? 0;let volume24h = token.volume_24h_usd ?? token.volume24hUsd ?? null;- const displayPrice = marketCapUsd != null- ? formatUsd(marketCapUsd)- : priceUsd != null- ? formatUsd(priceUsd)- : '—';-- const priceLabel = marketCapUsd != null ? 'MCAP' : 'PRICE';-- let changeHtml = '';- if (change24h != null) {- const sign = change24h >= 0 ? '+' : '';- const cls = change24h >= 0 ? 'up' : 'down';- const arrow = change24h >= 0 ? '▲' : '▼';- changeHtml = `<span class="ch-price-change ${cls}">${arrow} ${sign}${Number(change24h).toFixed(2)}%</span>`;- }-- const tradeUrl = mint ? gmgnTokenUrl(mint) : '#';- const chartUrl = mint ? dextoolsTokenUrl(mint, { from: 'character' }) : '#';-- const metaItems = [];- if (holders) metaItems.push({ label: 'Holders', val: formatNum(holders) });- if (volume24h) metaItems.push({ label: '24h Vol', val: formatUsd(volume24h) });- if (symbol) metaItems.push({ label: 'Symbol', val: '$' + symbol });-- const metaHtml = metaItems.map(m =>- `<div class="ch-token-meta-item">- <span class="ch-token-meta-label">${m.label}</span>- <span class="ch-token-meta-val">${m.val}</span>- </div>`- ).join('');-tokenSection.innerHTML = buildTokenHtml(symbol, mint, marketCapUsd, priceUsd, change24h, holders, volume24h);// Fetch live market data from DexScreener and update card@@ -340,14 +311,14 @@ async function renderToken(agent) {function renderMemes(agent) {const grid = $('ch-memes-grid');- const memes = agent.meta?.memes || [];+ const memes = Array.isArray(agent.meta?.memes) ? agent.meta.memes : [];const createCard = `- <a class="ch-meme-create" href="/agents/${agent.id}?meme=1" title="Create meme">+ <a class="ch-meme-create" href="/agents/${encodeURIComponent(agent.id)}?meme=1" title="Create meme"><div class="ch-meme-create-icon">- <img loading="lazy" decoding="async" src="${agent.meta?.profile_image_url || agent.avatar_thumbnail_url || ''}"+ <img loading="lazy" decoding="async" src="${escapeHtml(safeUrl(agent.meta?.profile_image_url || agent.avatar_thumbnail_url, ''))}"data-fallback="hide"- alt="${agent.name}" />+ alt="${escapeHtml(agent.name)}" /></div><span class="ch-meme-create-label">Create Meme</span></a>@@ -360,8 +331,8 @@ function renderMemes(agent) {const memeCards = memes.slice(0, 5).map(m => `<div class="ch-meme-item">- <img src="${m.image_url}" alt="meme" loading="lazy" />- ${m.creator ? `<div class="ch-meme-author">${m.creator}</div>` : ''}+ <img src="${escapeHtml(safeUrl(m?.image_url, ''))}" alt="meme" loading="lazy" />+ ${m?.creator ? `<div class="ch-meme-author">${escapeHtml(m.creator)}</div>` : ''}</div>`).join('');diff --git a/src/create-prompt.js b/src/create-prompt.jsindex 184975e5d..57cc2ce9b 100644--- a/src/create-prompt.js+++ b/src/create-prompt.js@@ -268,7 +268,7 @@ function jobError(raw) {// ceiling. Name the two places that actually clear it and drop the retry.function planLimitError(description) {const lead = description && /\S/.test(description)- ? description.replace(/\s*(Delete an avatar or upgrade[^.]*\.|Delete an avatar[^.]*\.)\s*$/i, '').trim()+ ? escapeHtml(description).replace(/\s*(Delete an avatar or upgrade[^.]*\.|Delete an avatar[^.]*\.)\s*$/i, '').trim(): 'Your avatar library is full on this plan.';return new ApiError(`${lead} <a href="/dashboard">Delete one from your dashboard</a> or ` +@@ -325,7 +325,7 @@ function submitError(status, data) {return new ApiError('The avatar engines are all busy right now. Try again in a moment, or use the <a href="/create/selfie">selfie scanner</a> instead.',);- return new ApiError(description || `The avatar engine returned ${status}. Try again.`);+ return new ApiError(description ? escapeHtml(description) : `The avatar engine returned ${status}. Try again.`);}async function pollUntilDone(jobId, run) {@@ -558,7 +558,7 @@ function failBuild(err) {const retryable = !(err instanceof ApiError) || err.retryable !== false;setError(buildError,- `<span>${escapeHtml(message)}</span>` ++ `<span>${message}</span>` +(retryable? ` <button type="button" id="build-retry-now" class="cancel-build" style="margin-left:10px">Try again</button>`: '') +diff --git a/src/dashboard-next/pages/api.js b/src/dashboard-next/pages/api.jsindex f63c78890..eb1d0ecc7 100644--- a/src/dashboard-next/pages/api.js+++ b/src/dashboard-next/pages/api.js@@ -1080,7 +1080,7 @@ function buildSnippet(state) {'overflow:hidden',];if (background === 'transparent') styleParts.push('background:transparent');- return `<iframe src="${src}" allow="camera; microphone; autoplay" style="${styleParts.join(';')}" title="${sel.label}"></iframe>`;+ return `<iframe src="${src}" allow="camera; microphone; autoplay" style="${styleParts.join(';')}" title="${esc(sel.label)}"></iframe>`;}if (tab === 'component') {diff --git a/src/ibm-proof.js b/src/ibm-proof.jsindex 8c51f73b0..cb8d647bd 100644--- a/src/ibm-proof.js+++ b/src/ibm-proof.js@@ -428,7 +428,7 @@ async function verifyProof(sig) {${explorerHref(v.explorer) ? `<a href="${escapeHtml(explorerHref(v.explorer))}" target="_blank" rel="noopener">View on Solscan ↗</a>` : ''}</div>`;} catch (e) {- out.innerHTML = `<div class="notice warn">Verification failed: ${e?.message || e}</div>`;+ out.innerHTML = `<div class="notice warn">Verification failed: ${escapeHtml(e?.message || e)}</div>`;}}function escapeHtml(s) { return String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); }@@ -539,6 +539,6 @@ window.addEventListener('resize', () => { clearTimeout(resizeT); resizeT = setTirenderPicker();select(state.pools[0].address || state.pools[0].pool);} catch (e) {- $('picker').innerHTML = `<div class="notice warn" style="flex:1">Could not load trending tokens (${e?.message || e}). In local dev, /api/* proxies to production; this resolves once the endpoint is deployed, or run <code>node scripts/dev-ibm-proof.mjs</code>.</div>`;+ $('picker').innerHTML = `<div class="notice warn" style="flex:1">Could not load trending tokens (${escapeHtml(e?.message || e)}). In local dev, /api/* proxies to production; this resolves once the endpoint is deployed, or run <code>node scripts/dev-ibm-proof.mjs</code>.</div>`;}})();diff --git a/src/marketplace-analytics.js b/src/marketplace-analytics.jsindex 1049a2815..c0fdc3b4b 100644--- a/src/marketplace-analytics.js+++ b/src/marketplace-analytics.js@@ -80,8 +80,8 @@ function rankRow(num, name, sub, primary, secondary) {<div class="rank-row"><span class="rank-num">${num}</span><div class="rank-meta">- <div class="rank-name">${name}</div>- ${sub ? `<div class="rank-sub">${sub}</div>` : ''}+ <div class="rank-name">${esc(name)}</div>+ ${sub ? `<div class="rank-sub">${esc(sub)}</div>` : ''}</div><div class="rank-val"><div class="rank-primary">${primary}</div>diff --git a/src/mission-control/focus.js b/src/mission-control/focus.jsindex 647bba48d..f8e614008 100644--- a/src/mission-control/focus.js+++ b/src/mission-control/focus.js@@ -217,7 +217,7 @@ export function createFocusPane({ store, bus, enrich, mount }) {(row.twitter || coin.twitter) && { href: row.twitter || coin.twitter, label: 'X' },(row.telegram || coin.telegram) && { href: row.telegram || coin.telegram, label: 'TG' },(row.website || coin.website) && { href: row.website || coin.website, label: 'Web' },- ].filter(Boolean);+ ].filter((s) => s && typeof s.href === 'string' && /^https?:\/\//i.test(s.href.trim()));head.innerHTML = `${img ? `<img class="mc-focus-img" src="${escapeHtml(img)}" alt="" loading="lazy" decoding="async" />` : '<div class="mc-focus-img" aria-hidden="true"></div>'}diff --git a/src/segment.js b/src/segment.jsindex face7140f..e5c2d1cd4 100644--- a/src/segment.js+++ b/src/segment.js@@ -312,7 +312,7 @@ function renderPartsPanel() {row.setAttribute('role', 'listitem');row.innerHTML = `- <button class="part-main" type="button" data-act="select" aria-label="Select ${p.name}">+ <button class="part-main" type="button" data-act="select" aria-label="Select ${escapeHtml(p.name)}"><span class="swatch" style="background:${p.color}"></span><span class="part-text"><span class="part-name">${escapeHtml(p.name)}</span>@@ -320,9 +320,9 @@ function renderPartsPanel() {</span></button><span class="part-actions">- <button class="icon-btn" type="button" data-act="isolate" title="Isolate this part" aria-label="Isolate ${p.name}">⤢</button>- <button class="icon-btn" type="button" data-act="visibility" title="Toggle visibility" aria-label="Toggle visibility of ${p.name}" aria-pressed="true">👁</button>- <button class="icon-btn" type="button" data-act="download" title="Download this part as GLB" aria-label="Download ${p.name}">⭳</button>+ <button class="icon-btn" type="button" data-act="isolate" title="Isolate this part" aria-label="Isolate ${escapeHtml(p.name)}">⤢</button>+ <button class="icon-btn" type="button" data-act="visibility" title="Toggle visibility" aria-label="Toggle visibility of ${escapeHtml(p.name)}" aria-pressed="true">👁</button>+ <button class="icon-btn" type="button" data-act="download" title="Download this part as GLB" aria-label="Download ${escapeHtml(p.name)}">⭳</button></span>`;row.addEventListener('mouseenter', () => setHover(p.id));diff --git a/tests/character-page-escaping.test.js b/tests/character-page-escaping.test.jsnew file mode 100644index 000000000..0a0d8538b--- /dev/null+++ b/tests/character-page-escaping.test.js@@ -0,0 +1,96 @@+// @vitest-environment jsdom+//+// /character/:id renders an agent's owner-controlled fields (name, meta.token,+// meta.memes, meta.profile_image_url) for every visitor. Those strings must+// reach the page as text, never as markup, and remote image URLs must never+// carry a non-http(s) scheme.++import { describe, it, expect, vi, beforeAll } from 'vitest';++vi.mock('../src/shared/onchain-badge.js', () => ({ onchainBadgeEl: () => null }));+vi.mock('../src/shared/agent-wallet-chip.js', () => ({ walletChipEl: () => null }));+vi.mock('../src/shared/wallet-aura.js', () => ({ hydrateAvatarWallet: () => Promise.resolve(null) }));+vi.mock('../src/ui-juice.css', () => ({}));+vi.mock('../src/ui-juice.js', () => ({+ countUp: (el, _from, to, { format } = {}) => {+ if (el) el.textContent = format ? format(to) : String(to);+ },+}));+vi.mock('../src/shared/failover-fetch.js', () => ({ fetchFirstOrNull: async () => null }));++const AGENT_ID = '0b9c3a7e-4d2f-4f6a-9e1b-2c3d4e5f6a7b';+const NAME = '"><iframe srcdoc="<b>x</b>"></iframe>';+const SYMBOL = '<iframe srcdoc="pwn"></iframe>';+const HOLDERS = '<form action="https://evil.example"><input name=p></form>';+const CREATOR = '<a href="https://evil.example">claim</a>';++const agent = {+ id: AGENT_ID,+ name: NAME,+ description: 'desc',+ chat_count: 3,+ meta: {+ profile_image_url: '" onerror="alert(1)',+ token: { symbol: SYMBOL, holders: HOLDERS, mint: 'THREEsynthetic1111111111111111111111111111' },+ memes: [+ { image_url: 'javascript:alert(1)', creator: CREATOR },+ { image_url: 'https://cdn.example/meme.png', creator: 'alice' },+ ],+ },+};++function mountShell() {+ document.body.innerHTML = `+ <div class="ch-shell ch-loading">+ <div id="ch-avatar-wrap"><img id="ch-avatar-img" /><div id="ch-avatar-ph"></div></div>+ <h1 id="ch-name"></h1>+ <div id="ch-creator"></div>+ <span id="ch-stat-chats"></span><span id="ch-stat-holders"></span>+ <p id="ch-desc"></p>+ <a id="ch-chat-btn"></a>+ <section id="ch-token-section"></section>+ <div id="ch-memes-grid"></div>+ </div>`;+}++beforeAll(async () => {+ window.history.replaceState(null, '', `/character/${AGENT_ID}`);+ mountShell();+ globalThis.fetch = vi.fn(async () => ({ ok: true, status: 200, json: async () => ({ agent }) }));+ await import('../src/character.js');+ await vi.waitFor(() => {+ expect(document.querySelector('.ch-meme-item')).not.toBeNull();+ });+});++describe('character page escaping', () => {+ it('injects no markup from owner-controlled fields', () => {+ expect(document.querySelector('iframe')).toBeNull();+ expect(document.querySelector('form')).toBeNull();+ expect(document.querySelector('.ch-meme-author a')).toBeNull();+ });++ it('renders the token symbol and holder count as text', () => {+ expect(document.querySelector('.ch-token-name').textContent).toBe(SYMBOL);+ const vals = [...document.querySelectorAll('.ch-token-meta-val')].map((el) => el.textContent);+ expect(vals).toContain(HOLDERS);+ expect(vals).toContain('$' + SYMBOL);+ });++ it('keeps the agent name inside the alt attribute', () => {+ const img = document.querySelector('.ch-meme-create-icon img');+ expect(img.getAttribute('alt')).toBe(NAME);+ expect(img.hasAttribute('onerror')).toBe(false);+ });++ it('drops non-http(s) meme image URLs and keeps https ones', () => {+ const imgs = [...document.querySelectorAll('.ch-meme-item img')];+ expect(imgs[0].getAttribute('src')).toBe('');+ expect(imgs[1].getAttribute('src')).toBe('https://cdn.example/meme.png');+ });++ it('renders meme creators as text', () => {+ const authors = [...document.querySelectorAll('.ch-meme-author')].map((el) => el.textContent);+ expect(authors).toEqual([CREATOR, 'alice']);+ });+});diff --git a/tests/create-prompt-failure-states.test.js b/tests/create-prompt-failure-states.test.jsindex fbf4d356a..d1f7f0f82 100644--- a/tests/create-prompt-failure-states.test.js+++ b/tests/create-prompt-failure-states.test.js@@ -122,6 +122,29 @@ describe('/create/prompt failure states', () => {expect(document.getElementById('build-retry-now')).not.toBeNull();});+ it('renders a server error description as text, never as markup', async () => {+ await mount(async () =>+ jsonResponse(500, { error: 'upstream_error', error_description: 'bad <iframe id="inj"></iframe> reply' }),+ );+ await generate();++ const box = document.getElementById('build-error');+ expect(box.querySelector('#inj')).toBeNull();+ expect(box.textContent).toContain('bad <iframe id="inj"></iframe> reply');+ });++ it('keeps a full-library description as text while still linking the exits', async () => {+ await mount(async () =>+ jsonResponse(402, { error: 'plan_limit', error_description: 'Full <img id="inj"> library.' }),+ );+ await generate();++ const box = document.getElementById('build-error');+ expect(box.querySelector('#inj')).toBeNull();+ expect(box.textContent).toContain('Full <img id="inj"> library.');+ expect([...box.querySelectorAll('a')].map((a) => a.getAttribute('href'))).toEqual(['/dashboard', '/pricing']);+ });+it('clears the failed look when the user goes back to edit the prompt', async () => {await mount(async () => jsonResponse(503, { error: 'regen_provider_error' }));await generate();diff --git a/tests/home-oracle-card-escape.test.js b/tests/home-oracle-card-escape.test.jsnew file mode 100644index 000000000..12126b8a9--- /dev/null+++ b/tests/home-oracle-card-escape.test.js@@ -0,0 +1,64 @@+// @vitest-environment jsdom+//+// Regression guard: the homepage Oracle strip renders pump.fun coin names and+// symbols, which are chosen by whoever launches the coin. The card builder used+// to interpolate them straight into innerHTML, so a coin named with markup put+// that markup on three.ws's front page for every visitor once it scored high+// enough to surface. The builder is authored inline in pages/home.html, so the+// test lifts the IIFE out of the page source and runs it against a stubbed feed.++import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';++const source = readFileSync(resolve(__dirname, '..', 'pages/home.html'), 'utf8');++function liftOracleIife() {+ const m = source.match(/\(async function initHomeOracle\(\) \{[\s\S]*?\n\t\}\)\(\);/);+ if (!m) throw new Error('initHomeOracle IIFE not found in pages/home.html');+ return m[0];+}++describe('homepage Oracle strip escapes coin metadata', () => {+ let realFetch;++ beforeEach(() => {+ realFetch = globalThis.fetch;+ document.body.innerHTML = '<div id="hoc-items"></div>';+ });++ afterEach(() => {+ globalThis.fetch = realFetch;+ document.body.innerHTML = '';+ });++ it('renders a hostile name, symbol and tier as text', async () => {+ const hostile = '<iframe srcdoc="x"></iframe><form id="phish"></form>';+ globalThis.fetch = vi.fn(async () => ({+ ok: true,+ json: async () => ({+ items: [+ {+ mint: 'THREEsynthetic1111111111111111111111111111',+ name: hostile,+ symbol: '<b id="sym">x</b>',+ tier: '"><img id="tier">',+ score: 80,+ pillars: { pedigree: 50, structure: 50, narrative: 50, momentum: 50 },+ },+ ],+ }),+ }));++ await new Function(`return ${liftOracleIife().replace(/;\s*$/, '')}`)();++ const host = document.getElementById('hoc-items');+ expect(host.querySelector('iframe')).toBeNull();+ expect(host.querySelector('form')).toBeNull();+ expect(host.querySelector('#sym')).toBeNull();+ expect(host.querySelector('#tier')).toBeNull();+ expect(host.querySelector('.hoc-name').textContent).toBe(hostile);+ expect(host.querySelector('.hoc-sym').textContent).toBe('$<B ID="SYM">X</B>');+ expect(host.querySelector('.hoc-tier').className).toBe('hoc-tier t-watch');+ });+});