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(avatars): serve private avatars to the browser through the proxy, not a presigned S3 URL

nirholascad454c87c3b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc8748f5f..8bb2d2165 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@
Public history for [three.ws](https://three.ws), newest first. New pages come from `added` dates in data/pages.json; everything else is curated in data/changelog.json. Also available as [JSON](https://three.ws/changelog.json) and [RSS](https://three.ws/changelog.xml), live at [three.ws/changelog](https://three.ws/changelog).
+## 2026-09-09
+
+- **Your private avatars load on the dashboard again, and say so when they cannot**: Avatars you have not made public were failing to load on your dashboard, with nothing on the page to say why. The dashboard was being handed a temporary direct link into our storage provider rather than a link back through three.ws. When storage stopped accepting our credential, that direct link was refused in a way browsers deliberately hide, so the page could not tell the difference between a refusal and a dead connection: it just showed nothing. Private avatars now load through three.ws itself, which checks that the avatar is yours exactly as before, and which already knows how to fall back to a second copy when storage is having a bad day. As a side effect these links no longer expire, so a dashboard tab left open for an hour still shows your avatars when you come back to it. (`/dashboard/avatars`) `[fix]`
+
## 2026-09-08
- **Docs · Global Intel Globe** (`/docs/globe`): The live 3D globe at /globe: its eleven keyless open-data layers and where each comes from, the URL parameters that make any view a shareable link, the one API call that returns every layer, and why an ingest cron has to keep its own GDELT window for the time control to be honest.
@@ -36,6 +40,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **The Revenue view on Protocol Fees stopped calling itself Fees**: Open /fees, switch to Revenue, and the numbers, the chart and the stat cards all changed to revenue while the table heading and the browser tab kept saying "Fees". The page writes those two pieces of copy itself, and the site-wide translation pass, which lands a second or two after the page does, was overwriting them back to the fees wording. Both now hold the metric you actually selected, and hand themselves back to the translator when you switch to Fees, so a reader in another language keeps their own copy. Four more things on that page while we were in there: the footer line now says when a figure is a cached copy served because DeFiLlama is unreachable, rather than presenting it as live; a run where the feed returns nothing no longer paints three empty totals and a "Top 0 protocols" line that read like a claim DeFi earned nothing; toggling Fees and Revenue faster than the network answers can no longer land one metric's numbers under the other's heading; and screen readers are now told every column is sortable, told which metric each region is showing, and given a proper pair of toggle buttons instead of tabs with no panel behind them. The "+3" badge on a protocol's chain list also names the chains it is hiding. (`/fees`) `[fix, improvement]`
- **Two thirds of the site was missing its mobile stylesheet, and every page it reached got bigger buttons**: three.ws keeps one stylesheet for phones: it sets a 44px minimum on anything you tap, keeps 3D viewers from fighting the page scroll, and holds bottom bars clear of the iPhone home indicator. It was reaching 192 of the 584 pages that carry a stylesheet at all. The build injected it, and the injector only ever saw pages built through the bundler, so everything served as a plain HTML file quietly went without: the whole documentation site, this changelog, /ar and hundreds of others. The documentation sidebar was the clearest case, 296 links measured at 30 pixels tall on a Pixel 5, against a rule sizing them to 44 that had been sitting in that stylesheet unused. The build now sweeps every page it produces, which added the stylesheet to 210 more of them, and the same sweep switches on the setting iOS needs before safe-area spacing does anything at all. On top of that, the controls the audit still found short have been raised across the home page, the marketplace, /coin, /play, /launches, /forge, /markets, /news, /irl, /walk and the docs shell. (`/docs/start-here`) `[improvement, fix]`
- **Watch your model being made, instead of watching a spinner**: Making a model from a written prompt starts with work you never saw: an art director rewrites your words into a proper brief, then an image model paints the reference picture the mesh is actually sculpted from, and on our best lane it paints the extra angles that fill in the subject's back. All of that used to happen inside one long silent request, so Forge could only say "art-directing your prompt" for the whole wait and then reveal the reference picture at the very end, when it had already existed for half a minute. Now the pipeline reports each step the instant it finishes, so the stage list ticks over as the work really happens and the reference image appears on screen while the sculpting is still running. Nothing on that list is a guess: a step only lights up because the server said it finished. On a phone, pressing Generate now brings the panel into view instead of leaving the whole thing playing out below the fold, and the same is true when a model lands or when something goes wrong. If our asset storage is the thing that is down, Forge now says so plainly, tells you nothing was charged, and points you at the models you already made, which keep working throughout. A model on screen also stops spinning by itself for anyone who has asked their device for less motion, and the report-a-bug prompt no longer pops up on top of the recovery buttons on a narrow screen. (`/forge`) `[improvement, fix]`
+- **Your avatar shows up again on every page, instead of a stand-in robot**: When you were signed in, the little avatar that rides along with you across the site had quietly been replaced by a generic robot on every page. The models themselves were fine and sitting safely in storage the whole time: what broke was the signed request the site uses to read them. Our storage provider stopped accepting that credential, and the page that serves your avatar had only that one way to fetch it, so it gave up and returned an error while the same file was being served correctly on the public storage address the entire time. That page now falls back to the public address and streams the model through as usual when the signed read is refused, so your avatar keeps loading through an outage like this one. It still prefers the signed path and returns to it automatically the moment storage is healthy again, and nothing about who is allowed to see a private avatar changed. (`/avatars`) `[fix]`
- **Your avatars show up on the dashboard again, and a failed one says why**: The avatar previews on your dashboard, and every three.ws avatar embedded through the <threews-avatar> tag, were being pointed straight at the storage bucket that holds the 3D file. That address is on a different domain to the page asking for it, and the browser refuses cross-domain reads it has not been given permission for, so the model was blocked before a single byte arrived and the preview sat empty. Stored avatars now load through three.ws itself, which is the same origin as the page, carries your session so a private avatar stays private, and already knows to fall back to the public copy of the file when the signed read is refused. That last part is why this was invisible on our own site and total everywhere else: the bucket permits three.ws by name and nothing else, so a dashboard preview, a developer running the site locally, and a customer embedding an avatar on their own domain all failed for the same reason. When a model genuinely cannot be loaded, the frame no longer paints the raw network error, complete with an internal URL, into the box. It now says whether the avatar is private, gone, or the service is down, and what to do next. My Agents got the same treatment: a failed load explains the cause and gives you a Try again button instead of telling you to refresh the page, its keyboard focus outlines are visible again, and the page respects a reduced-motion preference. (`/dashboard`) `[fix, improvement]`
## 2026-09-07
diff --git a/api/_lib/avatars.js b/api/_lib/avatars.js
index 3fa5a0cec..ea4878c90 100644
--- a/api/_lib/avatars.js
+++ b/api/_lib/avatars.js
@@ -8,6 +8,10 @@ import { publicUrl, thumbnailUrl, presignGet, deleteObject } from './r2.js';
import { defaultStorageMode } from './storage-mode.js';
import { isUuid } from './validate.js';
+// Absolute, so the URL is equally usable from the dashboard, an SDK on another
+// origin, and a server rendering it into a page.
+const SITE_ORIGIN = (process.env.PUBLIC_BASE_URL || 'https://three.ws').replace(/\/$/, '');
+
/**
* Build the row-selection half of listAvatars.
*
@@ -519,11 +523,31 @@ export async function listForks({ avatarId, limit = 24, cursor }) {
};
}
-export async function resolveAvatarUrl(row, { expiresIn = 600 } = {}) {
+// Where the caller will hand this URL decides which private-avatar URL is
+// correct, so callers say, rather than every consumer inheriting the one shape
+// that suits a third-party fetcher.
+//
+// `browser: true` returns the same-origin proxy. A presigned S3 URL is the
+// wrong thing to hand a page: R2's S3 endpoint answers a rejected credential
+// with a 403 that carries NO access-control-allow-origin, so the browser hides
+// the status and the page sees an opaque CORS failure it can neither report nor
+// retry. The authenticated sweep of 2026-09-08 caught exactly that on
+// /dashboard and /dashboard/avatars, where every private avatar failed with
+// "blocked by CORS policy" while the real fault was a rotated storage secret.
+// The proxy enforces the identical owner-only rule, sends wildcard CORS, and
+// carries the public-bucket failover, so it degrades loudly instead of opaquely
+// and does not expire out from under a long-open tab.
+//
+// The default stays presigned because a third party we hand a URL to (the
+// Avaturn edit session, an MCP client) cannot authenticate against our proxy.
+export async function resolveAvatarUrl(row, { expiresIn = 600, browser = false } = {}) {
const key = _servedStorageKey(row);
if (row.visibility === 'public' || row.visibility === 'unlisted') {
return { url: publicUrl(key), cdn: true };
}
+ if (browser) {
+ return { url: `${SITE_ORIGIN}/api/avatars/${row.id}/glb`, cdn: false };
+ }
return {
url: await presignGet({ key, expiresIn }),
cdn: false,
diff --git a/api/avatars/[id].js b/api/avatars/[id].js
index 5ac3fc3f0..4d40b0217 100644
--- a/api/avatars/[id].js
+++ b/api/avatars/[id].js
@@ -76,7 +76,10 @@ export default wrap(async (req, res) => {
if (req.method === 'GET') {
const avatar = await getAvatar({ id, requesterId: auth?.userId });
if (!avatar) return error(res, 404, 'not_found', 'avatar not found');
- const urlInfo = await resolveAvatarUrl(avatar);
+ // The dashboard and every other page read this endpoint, so a private
+ // avatar has to come back as the same-origin proxy rather than a presigned
+ // S3 URL a browser cannot fail on legibly. See resolveAvatarUrl.
+ const urlInfo = await resolveAvatarUrl(avatar, { browser: true });
const [priceRow] = await sql`
SELECT amount, currency_mint, chain, mint_decimals
FROM asset_prices
diff --git a/data/changelog.json b/data/changelog.json
index c49b33dd9..228465b49 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,24 @@
{
"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-09-09",
+ "title": "Your private avatars load on the dashboard again, and say so when they cannot",
+ "summary": "Avatars you have not made public were failing to load on your dashboard, with nothing on the page to say why. The dashboard was being handed a temporary direct link into our storage provider rather than a link back through three.ws. When storage stopped accepting our credential, that direct link was refused in a way browsers deliberately hide, so the page could not tell the difference between a refusal and a dead connection: it just showed nothing. Private avatars now load through three.ws itself, which checks that the avatar is yours exactly as before, and which already knows how to fall back to a second copy when storage is having a bad day. As a side effect these links no longer expire, so a dashboard tab left open for an hour still shows your avatars when you come back to it.",
+ "tags": [
+ "fix"
+ ],
+ "link": "/dashboard/avatars"
+ },
+ {
+ "date": "2026-09-08",
+ "title": "Your avatar shows up again on every page, instead of a stand-in robot",
+ "summary": "When you were signed in, the little avatar that rides along with you across the site had quietly been replaced by a generic robot on every page. The models themselves were fine and sitting safely in storage the whole time: what broke was the signed request the site uses to read them. Our storage provider stopped accepting that credential, and the page that serves your avatar had only that one way to fetch it, so it gave up and returned an error while the same file was being served correctly on the public storage address the entire time. That page now falls back to the public address and streams the model through as usual when the signed read is refused, so your avatar keeps loading through an outage like this one. It still prefers the signed path and returns to it automatically the moment storage is healthy again, and nothing about who is allowed to see a private avatar changed.",
+ "tags": [
+ "fix"
+ ],
+ "link": "/avatars"
+ },
{
"date": "2026-09-08",
"title": "A live globe of what is happening on Earth, and every layer says how far back it can really see",
diff --git a/public/changelog-recent.json b/public/changelog-recent.json
index efe85f109..5bad41d93 100644
--- a/public/changelog-recent.json
+++ b/public/changelog-recent.json
@@ -1,14 +1,24 @@
{
- "generated_at": "2026-09-08T22:41:00.932Z",
+ "generated_at": "2026-09-09T01:28:27.284Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
"url": "https://three.ws"
},
- "total": 3576,
+ "total": 3578,
"complete": false,
"full_feed": "/changelog.json",
"entries": [
+ {
+ "date": "2026-09-09",
+ "type": "update",
+ "title": "Your private avatars load on the dashboard again, and say so when they cannot",
+ "summary": "Avatars you have not made public were failing to load on your dashboard, with nothing on the page to say why. The dashboard was being handed a temporary direct link into our storage provider rather than a link back through three.ws. When storage stopped accepting our credential, that direct link was refused in a way browsers deliberately hide, so the page could not tell the difference between a refusal and a dead connection: it just showed nothing. Private avatars now load through three.ws itself, which checks that the avatar is yours exactly as before, and which already knows how to fall back to a second copy when storage is having a bad day. As a side effect these links no longer expire, so a dashboard tab left open for an hour still shows your avatars when you come back to it.",
+ "link": "/dashboard/avatars",
+ "tags": [
+ "fix"
+ ]
+ },
{
"date": "2026-09-08",
"type": "launch",
@@ -333,6 +343,16 @@
"fix"
]
},
+ {
+ "date": "2026-09-08",
+ "type": "update",
+ "title": "Your avatar shows up again on every page, instead of a stand-in robot",
+ "summary": "When you were signed in, the little avatar that rides along with you across the site had quietly been replaced by a generic robot on every page. The models themselves were fine and sitting safely in storage the whole time: what broke was the signed request the site uses to read them. Our storage provider stopped accepting that credential, and the page that serves your avatar had only that one way to fetch it, so it gave up and returned an error while the same file was being served correctly on the public storage address the entire time. That page now falls back to the public address and streams the model through as usual when the signed read is refused, so your avatar keeps loading through an outage like this one. It still prefers the signed path and returns to it automatically the moment storage is healthy again, and nothing about who is allowed to see a private avatar changed.",
+ "link": "/avatars",
+ "tags": [
+ "fix"
+ ]
+ },
{
"date": "2026-09-08",
"type": "update",
@@ -1576,28 +1596,6 @@
"feature",
"improvement"
]
- },
- {
- "date": "2026-09-03",
- "type": "update",
- "title": "Endpoint Shopper takes payment on the page, so a paid run actually runs",
- "summary": "Paying for an Endpoint Shopper run used to send you to the generic payment page, which arrived with no price and no wallet options because it could not read the challenge this route sends. Even if it had, it would have replayed the run as an empty request: your task and budget were left behind on the previous page, so a completed payment unlocked nothing. Payment now happens on /shopper itself. The card quotes the real price, lists the Base and Solana wallets the endpoint accepts, reports connecting, signing and settling as they happen, and replays the exact task and budget you typed, so the answer and its cost breakdown appear right where you were, with a link to the settlement transaction. The example task chips are now real buttons you can reach with the keyboard, the task box and budget slider carry proper labels, and the Marketplace and Fact Checker links no longer vanish from the header on a phone.",
- "link": "/shopper",
- "tags": [
- "fix",
- "improvement"
- ]
- },
- {
- "date": "2026-09-03",
- "type": "update",
- "title": "Every 3D model now says whether a physics engine could actually use it",
- "summary": "A 3D model can look flawless on screen and still be unusable the moment you drop it into a physics engine: an open shell sinks through the floor, an inside-out surface spins like it is hollow, and a model fitted to a unit box is a metre tall when you asked for a teapot. Nothing in a GLB file has ever said so, so everyone building robotics, game or simulation pipelines has been finding out one broken asset at a time. Now every model page carries a verdict beside its geometry stats, and the GLB viewer will grade any public model you point it at. Four answers: ready to simulate as-is, sound but needs its real size set, needs its surface closed first, or nothing there to simulate. Open the badge and you get every number behind the verdict, including the exact volume, centre of mass and inertia tensor, copyable as JSON straight into your own pipeline. It is free, needs no account, and works on any public model, not just ours. Agents can ask the same question through the free grade_sim_readiness tool, so a shopping agent can check ten candidates for nothing and only pay for the one that works. Models forged here are graded the moment they are generated, so the answer is already waiting when the page opens, and when a model is credentialed the grade is signed along with it, which makes the physics claim as hard to forge as the authorship claim.",
- "link": "/docs/sim-readiness",
- "tags": [
- "feature",
- "sdk"
- ]
}
]
}
diff --git a/public/changelog.json b/public/changelog.json
index b74c7d9c2..8c0df4012 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,11 +1,21 @@
{
- "generated_at": "2026-09-08T22:41:00.905Z",
+ "generated_at": "2026-09-09T01:28:27.269Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
"url": "https://three.ws"
},
"entries": [
+ {
+ "date": "2026-09-09",
+ "type": "update",
+ "title": "Your private avatars load on the dashboard again, and say so when they cannot",
+ "summary": "Avatars you have not made public were failing to load on your dashboard, with nothing on the page to say why. The dashboard was being handed a temporary direct link into our storage provider rather than a link back through three.ws. When storage stopped accepting our credential, that direct link was refused in a way browsers deliberately hide, so the page could not tell the difference between a refusal and a dead connection: it just showed nothing. Private avatars now load through three.ws itself, which checks that the avatar is yours exactly as before, and which already knows how to fall back to a second copy when storage is having a bad day. As a side effect these links no longer expire, so a dashboard tab left open for an hour still shows your avatars when you come back to it.",
+ "link": "/dashboard/avatars",
+ "tags": [
+ "fix"
+ ]
+ },
{
"date": "2026-09-08",
"type": "launch",
@@ -330,6 +340,16 @@
"fix"
]
},
+ {
+ "date": "2026-09-08",
+ "type": "update",
+ "title": "Your avatar shows up again on every page, instead of a stand-in robot",
+ "summary": "When you were signed in, the little avatar that rides along with you across the site had quietly been replaced by a generic robot on every page. The models themselves were fine and sitting safely in storage the whole time: what broke was the signed request the site uses to read them. Our storage provider stopped accepting that credential, and the page that serves your avatar had only that one way to fetch it, so it gave up and returned an error while the same file was being served correctly on the public storage address the entire time. That page now falls back to the public address and streams the model through as usual when the signed read is refused, so your avatar keeps loading through an outage like this one. It still prefers the signed path and returns to it automatically the moment storage is healthy again, and nothing about who is allowed to see a private avatar changed.",
+ "link": "/avatars",
+ "tags": [
+ "fix"
+ ]
+ },
{
"date": "2026-09-08",
"type": "update",
diff --git a/public/changelog.xml b/public/changelog.xml
index 63821c580..f8964f7d7 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -6,6 +6,14 @@
<atom:link href="https://three.ws/changelog.xml" rel="self" type="application/rss+xml"/>
<description>What's new on three.ws: features, improvements, and releases, newest first.</description>
<language>en</language>
+ <item>
+ <title>Your private avatars load on the dashboard again, and say so when they cannot</title>
+ <link>https://three.ws/dashboard/avatars</link>
+ <guid isPermaLink="false">2026-09-09:Your private avatars load on the dashboard again, and say so when they cannot</guid>
+ <pubDate>Wed, 09 Sep 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>Avatars you have not made public were failing to load on your dashboard, with nothing on the page to say why. The dashboard was being handed a temporary direct link into our storage provider rather than a link back through three.ws. When storage stopped accepting our credential, that direct link was refused in a way browsers deliberately hide, so the page could not tell the difference between a refusal and a dead connection: it just showed nothing. Private avatars now load through three.ws itself, which checks that the avatar is yours exactly as before, and which already knows how to fall back to a second copy when storage is having a bad day. As a side effect these links no longer expire, so a dashboard tab left open for an hour still shows your avatars when you come back to it.</description>
+ </item>
<item>
<title>Docs · Global Intel Globe</title>
<link>https://three.ws/docs/globe</link>
@@ -246,6 +254,14 @@
<category>improvement</category>
<description>Making a model from a written prompt starts with work you never saw: an art director rewrites your words into a proper brief, then an image model paints the reference picture the mesh is actually sculpted from, and on our best lane it paints the extra angles that fill in the subject's back. All of that used to happen inside one long silent request, so Forge could only say &quot;art-directing your prompt&quot; for the whole wait and then reveal the reference picture at the very end, when it had already existed for half a minute. Now the pipeline reports each step the instant it finishes, so the stage list ticks over as the work really happens and the reference image appears on screen while the sculpting is still running. Nothing on that list is a guess: a step only lights up because the server said it finished. On a phone, pressing Generate now brings the panel into view instead of leaving the whole thing playing out below the fold, and the same is true when a model lands or when something goes wrong. If our asset storage is the thing that is down, Forge now says so plainly, tells you nothing was charged, and points you at the models you already made, which keep working throughout. A model on screen also stops spinning by itself for anyone who has asked their device for less motion, and the report-a-bug prompt no longer pops up on top of the recovery buttons on a narrow screen.</description>
</item>
+ <item>
+ <title>Your avatar shows up again on every page, instead of a stand-in robot</title>
+ <link>https://three.ws/avatars</link>
+ <guid isPermaLink="false">2026-09-08:Your avatar shows up again on every page, instead of a stand-in robot</guid>
+ <pubDate>Tue, 08 Sep 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>When you were signed in, the little avatar that rides along with you across the site had quietly been replaced by a generic robot on every page. The models themselves were fine and sitting safely in storage the whole time: what broke was the signed request the site uses to read them. Our storage provider stopped accepting that credential, and the page that serves your avatar had only that one way to fetch it, so it gave up and returned an error while the same file was being served correctly on the public storage address the entire time. That page now falls back to the public address and streams the model through as usual when the signed read is refused, so your avatar keeps loading through an outage like this one. It still prefers the signed path and returns to it automatically the moment storage is healthy again, and nothing about who is allowed to see a private avatar changed.</description>
+ </item>
<item>
<title>Your avatars show up on the dashboard again, and a failed one says why</title>
<link>https://three.ws/dashboard</link>
diff --git a/public/features.json b/public/features.json
index 92b3bc226..22ab8b0aa 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-09-08T22:41:00.887Z",
+ "generated_at": "2026-09-09T01:28:27.261Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/tests/api/avatars-resolve-url-audience.test.js b/tests/api/avatars-resolve-url-audience.test.js
new file mode 100644
index 000000000..85e21228f
--- /dev/null
+++ b/tests/api/avatars-resolve-url-audience.test.js
@@ -0,0 +1,70 @@
+// resolveAvatarUrl has to answer differently depending on who receives the URL,
+// and getting that wrong is invisible until storage breaks.
+//
+// A private avatar used to come back as a presigned S3 URL for every caller,
+// including the dashboard. R2's S3 endpoint allows our origin on the preflight,
+// so that looks correct right up until the credential is rejected: the 403 it
+// answers with carries NO access-control-allow-origin, the browser hides the
+// status, and the page sees an opaque "blocked by CORS policy" it can neither
+// report nor retry. The authenticated sweep of 2026-09-08 measured exactly that,
+// 32 confirmed errors across /dashboard and /dashboard/avatars, every one of
+// them a private avatar whose real fault was a rotated storage secret.
+//
+// Browser callers now get the same-origin proxy, which enforces the identical
+// owner-only rule, sends wildcard CORS and carries the public-bucket failover.
+// Third parties we hand a URL to (the Avaturn edit session, an MCP client)
+// cannot authenticate against that proxy, so they keep the presigned URL.
+
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+vi.mock('../../api/_lib/db.js', () => ({ sql: async () => [] }));
+vi.mock('../../api/_lib/cache.js', () => ({ cacheWrap: (_k, fn) => fn() }));
+vi.mock('../../api/_lib/r2.js', () => ({
+ publicUrl: (key) => `https://pub-test.r2.dev/${key}`,
+ thumbnailUrl: (key) => (key ? `https://pub-test.r2.dev/${key}` : null),
+ presignGet: async ({ key, expiresIn }) =>
+ `https://bucket.r2.cloudflarestorage.com/${key}?X-Amz-Signature=deadbeef&X-Amz-Expires=${expiresIn}`,
+ deleteObject: async () => {},
+}));
+
+const { resolveAvatarUrl } = await import('../../api/_lib/avatars.js');
+
+const PRIVATE = { id: 'aaaaaaaa-0000-4000-8000-000000000001', visibility: 'private', storage_key: 'u/o/a.glb' };
+
+beforeEach(() => vi.clearAllMocks());
+
+describe('resolveAvatarUrl audience', () => {
+ it('hands a browser the same-origin proxy for a private avatar, never a presigned URL', async () => {
+ const r = await resolveAvatarUrl(PRIVATE, { browser: true });
+ expect(r.url).toBe(`https://three.ws/api/avatars/${PRIVATE.id}/glb`);
+ expect(r.url).not.toMatch(/X-Amz-Signature/);
+ expect(r.cdn).toBe(false);
+ // No expiry to strand a long-open tab on.
+ expect(r.expires_in).toBeUndefined();
+ });
+
+ it('still presigns for a third party that cannot authenticate against the proxy', async () => {
+ const r = await resolveAvatarUrl(PRIVATE, { expiresIn: 3600 });
+ expect(r.url).toMatch(/X-Amz-Signature/);
+ expect(r.expires_in).toBe(3600);
+ });
+
+ it('serves public and unlisted avatars from the CDN either way', async () => {
+ for (const visibility of ['public', 'unlisted']) {
+ const row = { ...PRIVATE, visibility };
+ for (const opts of [{ browser: true }, {}]) {
+ const r = await resolveAvatarUrl(row, opts);
+ expect(r.url).toBe('https://pub-test.r2.dev/u/o/a.glb');
+ expect(r.cdn).toBe(true);
+ }
+ }
+ });
+
+ it('serves the baked GLB through the proxy id, not the raw key', async () => {
+ // The proxy resolves the served key itself, so a baked avatar needs no
+ // different URL here; the id is the whole address.
+ const baked = { ...PRIVATE, baked_storage_key: 'u/o/baked.glb', appearance_hash: 'x', appearance: {} };
+ const r = await resolveAvatarUrl(baked, { browser: true });
+ expect(r.url).toBe(`https://three.ws/api/avatars/${PRIVATE.id}/glb`);
+ });
+});