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(agents): accept only http(s) URLs or same-origin paths as an agent's home link

nirholasfed52244b0ab
diff --git a/api/agents.js b/api/agents.js
index 7cc069f44..296eef00e 100644
--- a/api/agents.js
+++ b/api/agents.js
@@ -80,6 +80,30 @@ const STUDIO_ALLOWED_KEYS = new Set([
'skills',
]);
+// The agent's home link is rendered as an `href` on other people's screens
+// (featured agent, agent picker, galaxy, IRL card), so it may only ever be an
+// http(s) URL or a same-origin path. Anything else (`javascript:`, `data:`, a
+// protocol-relative `//host`) is refused at the write boundary.
+// Returns { value } with the cleaned URL (null when absent) or { error }.
+export function normalizeHomeUrl(input) {
+ if (input == null || input === '') return { value: null };
+ if (typeof input !== 'string') return { error: 'home_url must be a string' };
+ const v = input.trim();
+ if (!v) return { value: null };
+ if (v.length > 2048) return { error: 'home_url is too long' };
+ if (v.startsWith('/') && !v.startsWith('//') && !v.startsWith('/\\')) return { value: v };
+ let u;
+ try {
+ u = new URL(v);
+ } catch {
+ return { error: 'home_url must be an http(s) URL or a path starting with /' };
+ }
+ if (u.protocol !== 'https:' && u.protocol !== 'http:') {
+ return { error: 'home_url must be an http(s) URL or a path starting with /' };
+ }
+ return { value: u.href };
+}
+
// Returns an error message when the client-supplied meta.studio bag is malformed,
// or null when it's absent (nothing to validate) / null (explicit clear) / valid.
// Validates the CLIENT INPUT only — never re-validates already-stored data, so a
@@ -434,6 +458,8 @@ async function handleUpdate(req, res, id, auth) {
// studio_version) so the shared meta.studio contract stays clean for P1-P5.
const studioErr = validateStudioMeta(body.meta);
if (studioErr) return error(res, 400, 'validation_error', studioErr);
+ const homeUrl = normalizeHomeUrl(body.home_url);
+ if (homeUrl.error) return error(res, 400, 'validation_error', homeUrl.error);
// Server-side meta merge. GET strips encrypted_wallet_key /
// encrypted_solana_secret before returning meta, so a client read-modify-write
@@ -501,7 +527,7 @@ async function handleUpdate(req, res, id, auth) {
skills = COALESCE(${body.skills || null}, skills),
meta = COALESCE(${mergedMeta ? JSON.stringify(mergedMeta) : null}::jsonb, meta),
persona_prompt = COALESCE(${personaPrompt}, persona_prompt),
- home_url = COALESCE(${body.home_url || null}, home_url),
+ home_url = COALESCE(${homeUrl.value}, home_url),
updated_at = now()
WHERE id = ${id}
RETURNING *
diff --git a/tests/agents-home-url.test.js b/tests/agents-home-url.test.js
new file mode 100644
index 000000000..f30af8894
--- /dev/null
+++ b/tests/agents-home-url.test.js
@@ -0,0 +1,32 @@
+import { describe, it, expect } from 'vitest';
+
+import { normalizeHomeUrl } from '../api/agents.js';
+
+describe('agents: normalizeHomeUrl', () => {
+ it('keeps http(s) URLs and same-origin paths', () => {
+ expect(normalizeHomeUrl('https://example.com/me')).toEqual({ value: 'https://example.com/me' });
+ expect(normalizeHomeUrl('http://example.com')).toEqual({ value: 'http://example.com/' });
+ expect(normalizeHomeUrl('/agents/abc')).toEqual({ value: '/agents/abc' });
+ });
+
+ it('treats an absent or blank value as no change', () => {
+ expect(normalizeHomeUrl(undefined)).toEqual({ value: null });
+ expect(normalizeHomeUrl('')).toEqual({ value: null });
+ expect(normalizeHomeUrl(' ')).toEqual({ value: null });
+ });
+
+ it('refuses script and data schemes that would run when the link is clicked', () => {
+ for (const bad of ['javascript:alert(1)', ' JavaScript:alert(1)', 'data:text/html,<script>1</script>', 'vbscript:x']) {
+ expect(normalizeHomeUrl(bad).error).toBeTruthy();
+ }
+ });
+
+ it('refuses protocol-relative and backslash paths that leave the origin', () => {
+ expect(normalizeHomeUrl('//evil.example/x').error).toBeTruthy();
+ expect(normalizeHomeUrl('/\\evil.example/x').error).toBeTruthy();
+ });
+
+ it('refuses non-string input', () => {
+ expect(normalizeHomeUrl({ href: 'x' }).error).toBeTruthy();
+ });
+});