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(embed-doctor): route the headless page through the shared request guard

nirholasd76b3062e9f1
diff --git a/api/_lib/embed-doctor.js b/api/_lib/embed-doctor.js
index fcb0027e8..9bcc18cfb 100644
--- a/api/_lib/embed-doctor.js
+++ b/api/_lib/embed-doctor.js
@@ -33,6 +33,9 @@
// sends the developer to the wrong line).
import { assertSafePublicUrl, SsrfBlockedError } from './ssrf-guard.js';
+import { guardPageRequests } from './page-request-guard.js';
+
+export { guardPageRequests };
/** The canonical custom element, used in every fix snippet the report writes. */
export const EMBED_TAG = 'agent-3d';
@@ -1173,6 +1176,7 @@ export async function collectFromUrl({
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 three.ws-EmbedDoctor/1.0 (+https://three.ws/embed-doctor)',
);
const recorders = instrument(page);
+ await guardPageRequests(page, { platformOrigin });
let response = null;
try {
response = await page.goto(url, {
@@ -1238,10 +1242,11 @@ export async function collectFromSnippet({
// Served from the platform origin so relative URLs and module imports
// resolve exactly as they would in a browser, which `data:` URLs break.
let response = null;
- await page.setRequestInterception(true);
const sandboxUrl = `${platformOrigin}/__embed-doctor-sandbox`;
- page.on('request', (req) => {
- if (req.url() === sandboxUrl) {
+ await guardPageRequests(page, {
+ platformOrigin,
+ respond: (req) => {
+ if (req.url() !== sandboxUrl) return false;
req
.respond({
status: 200,
@@ -1249,9 +1254,8 @@ export async function collectFromSnippet({
body: snippetHostHtml(snippet),
})
.catch(() => {});
- return;
- }
- req.continue().catch(() => {});
+ return true;
+ },
});
response = await page.goto(sandboxUrl, {
waitUntil: 'domcontentloaded',
diff --git a/api/_lib/page-request-guard.js b/api/_lib/page-request-guard.js
new file mode 100644
index 000000000..0ae0ad3d7
--- /dev/null
+++ b/api/_lib/page-request-guard.js
@@ -0,0 +1,76 @@
+// SSRF guard for headless Chromium pages (puppeteer).
+//
+// A server-side browser is an outbound HTTP client like any other, with two
+// extra hazards: it follows redirects and loads sub-resources on its own, and
+// the bundled Chromium runs with --disable-web-security, so a page can read
+// cross-origin responses. Any page that loads a caller-influenced URL routes
+// its requests through guardPageRequests first.
+
+import { assertSafePublicUrl } from './ssrf-guard.js';
+
+/**
+ * Route every request the headless page makes through the SSRF guard.
+ *
+ * Checking only the URL handed to page.goto() left Chromium free to follow a
+ * redirect from that public page to an internal address, and to load any
+ * iframe, image or script the page (or a caller's snippet) names, with the
+ * screenshot, network log and console text handed back to the caller. With
+ * interception on, Chromium surfaces every request, redirect hops included,
+ * here first; a host that resolves to a private, loopback or metadata address
+ * is aborted before a socket opens. The configured platform origin is always
+ * allowed (it serves the embed itself, and is localhost in development).
+ *
+ * @param {import('puppeteer-core').Page} page
+ * @param {{ platformOrigin: string, respond?: (req: any) => boolean }} opts
+ * `respond` may answer a request itself and return true to claim it.
+ */
+export async function guardPageRequests(page, { platformOrigin, respond = () => false }) {
+ const verdicts = new Map();
+ let platform = null;
+ try {
+ platform = new URL(platformOrigin).origin;
+ } catch {
+ platform = null;
+ }
+ const hostAllowed = (url) => {
+ const key = `${url.protocol}//${url.host}`;
+ if (!verdicts.has(key)) {
+ verdicts.set(
+ key,
+ assertSafePublicUrl(url.href, { allowHttp: true }).then(
+ () => true,
+ () => false,
+ ),
+ );
+ }
+ return verdicts.get(key);
+ };
+ await page.setRequestInterception(true);
+ page.on('request', async (req) => {
+ try {
+ if (respond(req)) return;
+ let url;
+ try {
+ url = new URL(req.url());
+ } catch {
+ await req.abort('blockedbyclient');
+ return;
+ }
+ if (url.protocol === 'data:' || url.protocol === 'blob:') {
+ await req.continue();
+ return;
+ }
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
+ await req.abort('blockedbyclient');
+ return;
+ }
+ if (url.origin === platform || (await hostAllowed(url))) {
+ await req.continue();
+ return;
+ }
+ await req.abort('blockedbyclient');
+ } catch {
+ // The page closed or the request was already handled; nothing to do.
+ }
+ });
+}