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.

737 B
Raw Blame
// ── sanitize-url.js — shared URL scheme guard for rendered markdown links ───
//
// Used wherever LLM/persona/model output is converted to HTML anchors. Blocks
// script-bearing schemes (javascript:, data:, vbscript:) while allowing the
// link shapes that legitimate chat output uses: absolute http(s), site-relative
// paths, in-page anchors, and mailto:. Anything else collapses to '#'.

const SAFE_URL = /^(?:https?:\/\/|\/(?!\/)|#|mailto:)/i;
const UNSAFE_SCHEME = /^\s*(?:javascript|data|vbscript):/i;

export function sanitizeUrl(url) {
	if (typeof url !== 'string') return '#';
	const trimmed = url.trim();
	if (!trimmed || UNSAFE_SCHEME.test(trimmed)) return '#';
	return SAFE_URL.test(trimmed) ? trimmed : '#';
}