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(logos): proxy upstream protocol icons so a retired one paints the neutral disc instead of a console 404

nirholas23160dc9fcc8
diff --git a/api/img.js b/api/img.js
index f7edd01cc..78f20f82b 100644
--- a/api/img.js
+++ b/api/img.js
@@ -26,6 +26,14 @@
// external dependency that could itself be down, and is unique per seed:
// an abstract gradient "gem" that reads as token art rather than a generic
// "broken image" tile.
+// 5. `?fallback=none` opts out of step 4 and answers 204 No Content instead.
+// Token art wants the gem; a surface that already designs its own "no
+// logo" state (the neutral disc on every DeFi table) does not, and would
+// rather paint that disc than a gem that belongs to a different visual
+// language. 204 rather than 404 because a withdrawn upstream icon is an
+// ordinary outcome, not an error: the browser logs nothing for a 204, and
+// the <img> still fires `error` with no bytes, so the caller's designed
+// fallback runs exactly as it always did.
//
// Responses are immutable and CDN-cached: a given upstream URL yields the same
// bytes forever, so we cache hard at the edge and the proxy is hit once per art.
@@ -287,6 +295,9 @@ export default wrap(async function handler(req, res) {
const metaUri = url.searchParams.get('meta');
const seed = url.searchParams.get('seed') || directUrl || metaUri || '';
const width = requestedWidth(url.searchParams.get('w'));
+ // Callers that paint their own "no image" state ask for 204 instead of the
+ // placeholder art; anything else (including an absent param) keeps the gem.
+ const placeholderOff = url.searchParams.get('fallback') === 'none';
// Accept one of: ?url=<image>, ?meta=<metadata-json>, or ?seed=<x> (placeholder
// only). Callers streaming launch feeds pass `meta` so the real artwork is
@@ -351,6 +362,16 @@ export default wrap(async function handler(req, res) {
// the texture/image loader resolves with a 200 instead of logging an error.
// Served same-origin (no external dependency to fail) and cached, but for a
// shorter window than real art so a transiently-down source can recover.
+ if (placeholderOff) {
+ // `?fallback=none`: the caller draws its own empty state, so send no
+ // body at all. Cached on the same short window as the placeholder, for
+ // the same reason: a source that comes back should be picked up soon.
+ res.statusCode = 204;
+ res.setHeader('access-control-allow-origin', '*');
+ res.setHeader('cache-control', 'public, max-age=300, s-maxage=3600');
+ res.end();
+ return;
+ }
res.statusCode = 200;
res.setHeader('content-type', 'image/svg+xml; charset=utf-8');
res.setHeader('access-control-allow-origin', '*');
diff --git a/src/chain-page.js b/src/chain-page.js
index a376ccad0..66c4a4b49 100644
--- a/src/chain-page.js
+++ b/src/chain-page.js
@@ -13,6 +13,7 @@ import {
formatChartTick,
escapeHtml as esc,
} from './shared/coin-format.js';
+import { upstreamLogoURL, swapFailedLogos } from './shared/upstream-logo.js';
const $ = (id) => document.getElementById(id);
@@ -333,8 +334,9 @@ function changeCell(v) {
function protoRow(p) {
const label = esc(p.name || 'Unknown');
- const logo = p.logo
- ? `<img class="ch-proto-logo" src="${esc(p.logo)}" alt="" width="22" height="22" loading="lazy" data-no-dark-filter />`
+ const src = p.logo ? upstreamLogoURL(p.logo, 22) : '';
+ const logo = src
+ ? `<img class="ch-proto-logo" src="${esc(src)}" alt="" width="22" height="22" loading="lazy" data-no-dark-filter />`
: '<span class="ch-proto-logo ch-proto-logo-fallback" aria-hidden="true"></span>';
const nameCell = p.slug
? `<a class="ch-proto-link" href="/protocol/${encodeURIComponent(p.slug)}">${logo}<span>${label}</span></a>`
@@ -400,6 +402,10 @@ function drawProtoTable() {
</div>
${note}`;
+ // A protocol icon the CDN has retired arrives empty (204 through the proxy);
+ // paint the same neutral disc a logo-less row already gets.
+ swapFailedLogos(el, '.ch-proto-logo', 'ch-proto-logo ch-proto-logo-fallback');
+
el.querySelectorAll('.ch-sortable').forEach((th) => {
const apply = () => {
const key = th.dataset.sort;
diff --git a/src/defi.js b/src/defi.js
index 67565bc75..150431517 100644
--- a/src/defi.js
+++ b/src/defi.js
@@ -5,6 +5,7 @@
// cv-table, designed loading / empty / error states.
import { formatUsd, formatPercent, escapeHtml as esc } from './shared/coin-format.js';
+import { upstreamLogoURL, swapFailedLogos } from './shared/upstream-logo.js';
const $ = (id) => document.getElementById(id);
@@ -130,6 +131,16 @@ const state = {
error: false,
};
+// Upstream logos are proxied same-origin so a retired icon answers 204 instead
+// of 404ing in every reader's console; the swap above turns that empty image
+// into the neutral disc.
+function logoImg(logo) {
+ const src = logo ? upstreamLogoURL(logo, 24) : '';
+ return src
+ ? `<img class="defi-logo" src="${esc(src)}" alt="" loading="lazy" width="24" height="24" data-no-dark-filter />`
+ : '<span class="defi-logo-fallback" aria-hidden="true"></span>';
+}
+
function pctCell(v, extraClass = '') {
if (v == null) return `<td class="pct dim ${extraClass}">—</td>`;
const up = v >= 0;
@@ -221,7 +232,7 @@ function renderTable() {
<tr${nav}>
<td class="rank hide-sm cv-mono">${p.__rank}</td>
<td class="left name-cell"><span class="inner">
- ${p.logo ? `<img src="${esc(p.logo)}" alt="" loading="lazy" width="24" height="24" data-no-dark-filter />` : '<span class="defi-logo-fallback" aria-hidden="true"></span>'}
+ ${logoImg(p.logo)}
<span class="nm">${esc(p.name)}</span>
${p.symbol ? `<span class="sym">${esc(p.symbol)}</span>` : ''}
</span></td>
@@ -242,6 +253,10 @@ function renderTable() {
</table>
</div>`;
+ // A protocol icon the CDN has retired arrives empty (204 through the proxy);
+ // paint the same neutral disc a logo-less row already gets.
+ swapFailedLogos(el, '.defi-logo', 'defi-logo-fallback');
+
el.querySelectorAll('th[data-key]').forEach((th) => {
const activate = () => {
const key = th.dataset.key;
diff --git a/src/dex-volumes.js b/src/dex-volumes.js
index 441b4417d..7b4b1ac37 100644
--- a/src/dex-volumes.js
+++ b/src/dex-volumes.js
@@ -12,6 +12,7 @@ import {
formatChartTick,
escapeHtml as esc,
} from './shared/coin-format.js';
+import { upstreamLogoURL, swapFailedLogos } from './shared/upstream-logo.js';
const $ = (id) => document.getElementById(id);
@@ -275,8 +276,9 @@ function shareCell(share, maxShare) {
}
function nameCell(p) {
- const logo = p.logo
- ? `<img src="${esc(p.logo)}" alt="" loading="lazy" width="24" height="24" data-no-dark-filter />`
+ const src = p.logo ? upstreamLogoURL(p.logo, 24) : '';
+ const logo = src
+ ? `<img class="dx-logo" src="${esc(src)}" alt="" loading="lazy" width="24" height="24" data-no-dark-filter />`
: '<span class="dx-logo-fallback" aria-hidden="true"></span>';
const inner = `${logo}<span class="nm">${esc(p.name)}</span>`;
if (p.slug) {
@@ -364,6 +366,10 @@ function renderTable() {
</table>
</div>`;
+ // A DEX icon the CDN has retired arrives empty (204 through the proxy); paint
+ // the same neutral disc a logo-less row already gets.
+ swapFailedLogos(el, '.dx-logo', 'dx-logo-fallback');
+
el.querySelectorAll('th[data-key]').forEach((th) => {
const activate = () => {
const key = th.dataset.key;
diff --git a/src/exchange-page.js b/src/exchange-page.js
index 4efe3a972..2d3100905 100644
--- a/src/exchange-page.js
+++ b/src/exchange-page.js
@@ -14,6 +14,7 @@ import {
formatChartTick,
escapeHtml as esc,
} from './shared/coin-format.js';
+import { upstreamLogoURL, swapFailedLogos } from './shared/upstream-logo.js';
const $ = (id) => document.getElementById(id);
@@ -130,11 +131,12 @@ function heroDescription(d) {
function renderHero(d) {
$('ex-crumb-name').textContent = d.name;
+ const logoSrc = d.image ? upstreamLogoURL(d.image, 72) : '';
$('ex-hero').innerHTML = `
<div class="ex-hero">
${
- d.image
- ? `<img class="ex-logo" src="${esc(d.image)}" alt="${esc(d.name)} logo" width="72" height="72" loading="eager" data-no-dark-filter />`
+ logoSrc
+ ? `<img class="ex-logo" src="${esc(logoSrc)}" alt="${esc(d.name)} logo" width="72" height="72" loading="eager" data-no-dark-filter />`
: '<div class="ex-logo ex-logo-fallback" aria-hidden="true"></div>'
}
<div class="ex-hero-body">
@@ -148,6 +150,10 @@ function renderHero(d) {
${heroLinks(d)}
</div>
</div>`;
+
+ // Proxied same-origin: a logo host that has dropped the image answers 204
+ // and arrives empty instead of logging a 404, and this paints the disc.
+ swapFailedLogos($('ex-hero'), '.ex-logo', 'ex-logo ex-logo-fallback', 'div');
}
// ── Stat cards ───────────────────────────────────────────────────────────────
diff --git a/src/fees.js b/src/fees.js
index 2d0a9f70b..c7d251323 100644
--- a/src/fees.js
+++ b/src/fees.js
@@ -12,6 +12,7 @@ import {
formatChartTick,
escapeHtml as esc,
} from './shared/coin-format.js';
+import { upstreamLogoURL, swapFailedLogos } from './shared/upstream-logo.js';
const $ = (id) => document.getElementById(id);
@@ -298,8 +299,9 @@ function sortedProtocols() {
}
function nameCell(p) {
- const logo = p.logo
- ? `<img src="${esc(p.logo)}" alt="" loading="lazy" width="24" height="24" data-no-dark-filter />`
+ const src = p.logo ? upstreamLogoURL(p.logo, 24) : '';
+ const logo = src
+ ? `<img class="fx-logo" src="${esc(src)}" alt="" loading="lazy" width="24" height="24" data-no-dark-filter />`
: '<span class="fx-logo-fallback" aria-hidden="true"></span>';
const inner = `${logo}<span class="nm">${esc(p.name)}</span>`;
if (p.slug) {
@@ -364,23 +366,10 @@ function renderTable() {
</table>
</div>`;
- // A protocol icon is fetched from a third-party CDN, so one that has been
- // renamed or pulled answers 404 and the row renders a broken-image glyph.
- // Swap any icon that fails to load for the same neutral disc a logo-less
- // protocol already gets. The error event does not bubble, so this listens in
- // the capture phase on the container rather than per image.
- el.addEventListener(
- 'error',
- (e) => {
- const img = e.target;
- if (!(img instanceof HTMLImageElement) || !img.closest('.name-cell')) return;
- const fallback = document.createElement('span');
- fallback.className = 'fx-logo-fallback';
- fallback.setAttribute('aria-hidden', 'true');
- img.replaceWith(fallback);
- },
- true,
- );
+ // A protocol icon the CDN has retired resolves to 204 through the proxy, so
+ // the image arrives empty: swap it for the same neutral disc a logo-less
+ // protocol already gets.
+ swapFailedLogos(el, '.fx-logo', 'fx-logo-fallback');
el.querySelectorAll('th[data-key]').forEach((th) => {
const activate = () => {
diff --git a/src/ipfs.js b/src/ipfs.js
index 004c1b6a8..a2dca732b 100644
--- a/src/ipfs.js
+++ b/src/ipfs.js
@@ -154,12 +154,19 @@ export function isSafeImageURL(url) {
* that are a few hundred pixels on screen. Pass the size the art is actually
* used at; leave it off to get the original bytes.
*
+ * `fallback: 'none'` asks the proxy for 204 No Content instead of the gem when
+ * every source fails. Use it wherever the surface already designs its own "no
+ * image" state (the neutral logo disc on the DeFi tables): the browser logs
+ * nothing for a 204, and the <img> still fires `error`, so the designed state
+ * renders and the console stays clean. Leave it off for token art, which wants
+ * the placeholder.
+ *
* @param {string} url Image URL (https://, ipfs:// or ar:// accepted).
* @param {string} [seed] Stable placeholder seed (e.g. the token mint).
- * @param {{ width?: number }} [opts] Max delivered width in pixels.
+ * @param {{ width?: number, fallback?: 'art'|'none' }} [opts]
* @returns {string}
*/
-export function proxiedImageURL(url, seed = '', { width = 0 } = {}) {
+export function proxiedImageURL(url, seed = '', { width = 0, fallback = 'art' } = {}) {
if (typeof url !== 'string' || !url) return '';
// Protocol-relative art still deserves the proxy's CORS and gateway retry,
// so give it the scheme the page is already on before anything else looks
@@ -172,6 +179,7 @@ export function proxiedImageURL(url, seed = '', { width = 0 } = {}) {
const q = new URLSearchParams({ url: resolveURI(raw) });
if (seed) q.set('seed', seed);
if (width > 0) q.set('w', String(Math.round(width)));
+ if (fallback === 'none') q.set('fallback', 'none');
return `/api/img?${q.toString()}`;
}
diff --git a/src/protocol-page.js b/src/protocol-page.js
index cbb839d57..89df4e608 100644
--- a/src/protocol-page.js
+++ b/src/protocol-page.js
@@ -9,6 +9,7 @@
// the /exchange/:id detail-page pattern (src/exchange-page.js).
import { formatUsd, formatDateShort, escapeHtml as esc } from './shared/coin-format.js';
+import { upstreamLogoURL, swapFailedLogos } from './shared/upstream-logo.js';
const $ = (id) => document.getElementById(id);
@@ -139,11 +140,12 @@ function heroDescription(d) {
function renderHero(d) {
$('pr-crumb-name').textContent = d.name;
+ const logoSrc = d.logo ? upstreamLogoURL(d.logo, 72) : '';
$('pr-hero').innerHTML = `
<div class="pr-hero">
${
- d.logo
- ? `<img class="pr-logo" src="${esc(d.logo)}" alt="${esc(d.name)} logo" width="72" height="72" loading="eager" data-no-dark-filter />`
+ logoSrc
+ ? `<img class="pr-logo" src="${esc(logoSrc)}" alt="${esc(d.name)} logo" width="72" height="72" loading="eager" data-no-dark-filter />`
: '<div class="pr-logo pr-logo-fallback" aria-hidden="true"></div>'
}
<div class="pr-hero-body">
@@ -157,6 +159,11 @@ function renderHero(d) {
${heroLinks(d)}
</div>
</div>`;
+
+ // The logo is proxied same-origin, so an icon upstream has retired answers
+ // 204 and arrives empty rather than 404ing in the console: swap it for the
+ // same disc a logo-less protocol gets.
+ swapFailedLogos($('pr-hero'), '.pr-logo', 'pr-logo pr-logo-fallback', 'div');
}
// ── Stat cards ───────────────────────────────────────────────────────────────
diff --git a/src/shared/upstream-logo.js b/src/shared/upstream-logo.js
new file mode 100644
index 000000000..e3b65baae
--- /dev/null
+++ b/src/shared/upstream-logo.js
@@ -0,0 +1,75 @@
+// Protocol / chain / exchange logos come from third-party CDNs (DeFiLlama's
+// icons.llamao.fi, exchange logo hosts). Two things go wrong with them, and
+// both are visible to every reader:
+//
+// 1. An icon that upstream renamed or withdrew answers 404. The browser logs
+// "Failed to load resource" before any onerror handler can run, so no
+// amount of client-side recovery keeps the console clean, and the URL
+// cannot be repaired ahead of time because only the CDN knows which icons
+// still exist. On 2026-09-04 one protocol in the top 100 by fee revenue
+// was in that state, and /fees logged seven 404s per load.
+// 2. Every reader's IP is handed to the icon host on every table paint.
+//
+// Routing the icon through the same-origin /api/img proxy fixes both. The proxy
+// fetches server-side (SSRF-hardened, CDN-cached, resized to the painted size),
+// and `fallback=none` makes a withdrawn icon answer 204 No Content instead of
+// the token-art placeholder: the browser logs nothing for a 204, the <img>
+// still fires `error` with no bytes, and the surface paints the neutral disc it
+// already designs for a logo-less row.
+//
+// Used by /fees, /defi, /dex-volumes, /chain/:id, /protocol/:slug and
+// /exchange/:id, which each own a fallback class of their own.
+
+import { proxiedImageURL } from '../ipfs.js';
+
+/**
+ * Same-origin URL for an upstream logo, sized for the box it is painted in.
+ *
+ * @param {string} url Upstream logo URL.
+ * @param {number} [size] CSS pixels the logo is painted at; the proxy is asked
+ * for 2x that so it stays crisp on retina displays.
+ * @returns {string} A `/api/img?...` URL, or '' when the input is not a usable
+ * image source, so callers fall through to their own state.
+ */
+export function upstreamLogoURL(url, size = 0) {
+ return proxiedImageURL(url, '', {
+ width: size > 0 ? size * 2 : 0,
+ fallback: 'none',
+ });
+}
+
+// Containers already carrying the listener, so a re-render does not stack one
+// per sort click.
+const wired = new WeakSet();
+
+/**
+ * Replace any logo image inside `container` that fails to load with a neutral
+ * disc, so a withdrawn upstream icon lands in the surface's designed empty
+ * state instead of a broken-image glyph.
+ *
+ * The `error` event does not bubble, so this listens in the capture phase on
+ * the container: one listener covers every row, including rows rendered later.
+ * Callers re-render on every sort, so a repeat call on the same container is a
+ * no-op rather than a second listener.
+ *
+ * @param {Element} container Element whose descendants hold the logos.
+ * @param {string} imgSelector Selector identifying a logo image.
+ * @param {string} fallbackClass Class list for the replacement element.
+ * @param {'span'|'div'} [tag] Element to swap in (match the img's display).
+ */
+export function swapFailedLogos(container, imgSelector, fallbackClass, tag = 'span') {
+ if (!container || wired.has(container)) return;
+ wired.add(container);
+ container.addEventListener(
+ 'error',
+ (e) => {
+ const img = e.target;
+ if (!(img instanceof HTMLImageElement) || !img.matches(imgSelector)) return;
+ const fallback = document.createElement(tag);
+ fallback.className = fallbackClass;
+ fallback.setAttribute('aria-hidden', 'true');
+ img.replaceWith(fallback);
+ },
+ true,
+ );
+}
diff --git a/tests/api-img-proxy.test.js b/tests/api-img-proxy.test.js
index 599e65596..4d0f9ae2b 100644
--- a/tests/api-img-proxy.test.js
+++ b/tests/api-img-proxy.test.js
@@ -19,6 +19,9 @@
// 8. A data: image in a followed doc is rejected → placeholder.
// 9. ?url=<image> is served directly, unchanged (no JSON path taken).
// 10. The `?meta=` path does not accept JSON for the artwork itself.
+//
+// Plus `?fallback=none`, the opt-out the DeFi logo tables use: 204 No Content
+// instead of the placeholder, so a retired upstream icon logs nothing.
import { describe, it, expect, vi, beforeEach } from 'vitest';
@@ -129,6 +132,58 @@ describe('api/img metadata resolution', () => {
});
});
+// `?fallback=none` is what the DeFi tables (/fees, /defi, /dex-volumes,
+// /chain/:id, /protocol/:slug, /exchange/:id) ask for: they already draw a
+// neutral disc for a logo-less row, so a withdrawn upstream icon should arrive
+// empty rather than as token-art. 204 keeps the browser console silent (a 404
+// logs a failed resource on every table paint) while still firing `error` on
+// the <img>, which is what swaps in the disc.
+describe('api/img ?fallback=none', () => {
+ beforeEach(() => {
+ safeFetchJson.mockReset();
+ fetchModel.mockReset();
+ });
+
+ it('answers 204 with no body when every source fails', async () => {
+ fetchModel.mockRejectedValue(new Error('404 from the icon CDN'));
+
+ const res = mockRes();
+ await handler(mockReq('?url=https%3A%2F%2Ficons.example%2Fgone.png&fallback=none'), res);
+
+ expect(res.statusCode).toBe(204);
+ expect(res.body).toBeUndefined();
+ expect(res.headers['content-type']).toBeUndefined();
+ expect(res.headers['access-control-allow-origin']).toBe('*');
+ });
+
+ it('still serves the real image when the upstream resolves', async () => {
+ fetchModel.mockResolvedValue({
+ bytes: new Uint8Array([9, 9]),
+ url: 'https://icons.example/live.png',
+ contentType: 'image/png',
+ filename: 'live.png',
+ });
+
+ const res = mockRes();
+ await handler(mockReq('?url=https%3A%2F%2Ficons.example%2Flive.png&fallback=none'), res);
+
+ expect(res.statusCode).toBe(200);
+ expect(res.headers['content-type']).toBe('image/png');
+ expect([...res.body]).toEqual([9, 9]);
+ });
+
+ it('keeps the placeholder for every other caller', async () => {
+ fetchModel.mockRejectedValue(new Error('gone'));
+
+ const res = mockRes();
+ await handler(mockReq('?url=https%3A%2F%2Fcdn.example%2Fart.png&seed=THREE'), res);
+
+ expect(res.statusCode).toBe(200);
+ expect(res.headers['content-type']).toMatch(/image\/svg\+xml/);
+ expect(String(res.body)).toContain('<svg');
+ });
+});
+
// Serve `doc` as a JSON response and `art` as image bytes, keyed by URL, so a
// single mock can satisfy both hops of the follow.
function mockUpstream({ jsonAt = {}, imageAt = {} } = {}) {
diff --git a/tests/ipfs-image-url-safety.test.js b/tests/ipfs-image-url-safety.test.js
index 3fd40eafa..4a25f6406 100644
--- a/tests/ipfs-image-url-safety.test.js
+++ b/tests/ipfs-image-url-safety.test.js
@@ -119,6 +119,20 @@ describe('proxiedImageURL', () => {
expect(proxiedImageURL('javascript:alert(1)', '', { width: 512 })).toBe('');
});
+ // The DeFi logo tables draw their own neutral disc, so they ask the proxy for
+ // 204 rather than the gem placeholder. Token art must keep the placeholder,
+ // which is why the flag is opt-in and absent by default.
+ it("carries fallback=none only when the caller asks for it", () => {
+ const dflt = new URL(proxiedImageURL('https://icons.example/logo.png'), 'http://l');
+ expect(dflt.searchParams.has('fallback')).toBe(false);
+ const none = new URL(
+ proxiedImageURL('https://icons.example/logo.png', '', { width: 48, fallback: 'none' }),
+ 'http://l',
+ );
+ expect(none.searchParams.get('fallback')).toBe('none');
+ expect(none.searchParams.get('w')).toBe('48');
+ });
+
it('routes cross-origin art through the same-origin proxy, carrying the seed', () => {
const out = proxiedImageURL('https://ipfs.io/ipfs/bafyexample', MINT);
expect(out.startsWith('/api/img?')).toBe(true);