Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Verify Mastodon instances before forwarding public media URLs

Emre Sokullu2b8852c58608
diff --git a/docs/architecture.md b/docs/architecture.md
index d255f6d62..0bd30e343 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -469,9 +469,14 @@ tracks as a successful video or hand ffmpeg work to the user.
The packaged FreeSkillz resolver and downloader allow Bluesky post URLs.
Mastodon uses an `inputUrlAllowlist` rule of `{ "siteAdapter": "mastodon" }`
so supported instances do not need a fixed host list in the skill manifest.
-That rule accepts only exact HTTPS status permalinks recognized by the Mastodon
-adapter, rejects credentials, custom ports, and local-network destinations, and
-keeps feeds/profiles behind the visible-target guard. Both sites use the existing
+That rule accepts only exact HTTPS status permalinks on known instances or
+instances independently verified through same-origin NodeInfo discovery and
+`software.name: mastodon`. The credentialless verification rejects redirects,
+limits metadata reads to 64 KiB and 10 seconds, and never probes the post URL.
+Internationalized domains are accepted using URL-normalized IDNA hostnames.
+Credentials, custom ports, and local-network destinations are rejected; query
+strings and fragments are removed before forwarding Mastodon status URLs.
+Feeds/profiles stay behind the visible-target guard. Both sites use the existing
provider job lifecycle to deliver one final media file and clean up the job.
| User intent | Expected skill | Catalog modes | Notes |
diff --git a/docs/privacy-and-data-flow.md b/docs/privacy-and-data-flow.md
index 5725517f9..801bdb2da 100644
--- a/docs/privacy-and-data-flow.md
+++ b/docs/privacy-and-data-flow.md
@@ -496,8 +496,14 @@ configured LLM provider. The article fallback is limited to allowlisted
`nytimes.com` URLs (including The Athletic paths) and sends only that URL
without browser credentials or cookies. The transcript tool is limited to
YouTube/youtu.be URLs, while the media tools are limited to public media hosts
-declared in the skill manifest. The read-only article, transcript, and resolver
-tools do not require
+declared in the skill manifest. Mastodon status URLs must use HTTPS and a
+known instance host or an instance verified through public NodeInfo metadata.
+For unknown hosts, WebBrain first reads `/.well-known/nodeinfo` and its
+same-origin metadata link without cookies or credentials, with redirects
+blocked. Those checks do not include the post path, query string, or fragment.
+Only the verified status origin and path are sent to FreeSkillz; Mastodon query
+strings and fragments are discarded. The read-only article, transcript, and
+resolver tools do not require
`/allow-api`; `download_public_media` is available only in action modes and
requires download permission because it creates a short-lived provider job,
saves the completed file through the browser Downloads API, and then asks the
diff --git a/src/chrome/src/agent/adapters.js b/src/chrome/src/agent/adapters.js
index f04dbfd5a..10b213304 100644
--- a/src/chrome/src/agent/adapters.js
+++ b/src/chrome/src/agent/adapters.js
@@ -15660,6 +15660,12 @@ const KNOWN_MASTODON_HOSTS = new Set([
'zzz.frotz.net',
]);
+// Exact generated instance membership can be used by network allowlists.
+// The broader routing heuristic below is not proof of a Mastodon server.
+export function isKnownMastodonHost(hostname) {
+ return KNOWN_MASTODON_HOSTS.has(String(hostname || '').toLowerCase());
+}
+
// Keep direct URL matching conservative: bare /@user and /users/user routes are
// only Mastodon when the host is in the generated known-instance list.
export function isLikelyMastodonHost(hostname) {
diff --git a/src/chrome/src/agent/public-media-url.js b/src/chrome/src/agent/public-media-url.js
index 68aa59cbb..633144714 100644
--- a/src/chrome/src/agent/public-media-url.js
+++ b/src/chrome/src/agent/public-media-url.js
@@ -30,7 +30,7 @@ function hasPathId(path, pattern) {
export function isMastodonMediaPage(rawUrl) {
let parsed;
try { parsed = new URL(rawUrl); } catch { return false; }
- if (!['http:', 'https:'].includes(parsed.protocol)) return false;
+ if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port) return false;
const adapter = getActiveAdapter(rawUrl);
return adapter?.name === 'mastodon' || (!adapter && isLikelyMastodonHost(parsed.hostname));
}
@@ -38,7 +38,7 @@ export function isMastodonMediaPage(rawUrl) {
export function isMastodonPublicMediaUrl(rawUrl) {
let parsed;
try { parsed = new URL(rawUrl); } catch { return false; }
- if (!['http:', 'https:'].includes(parsed.protocol) || !isMastodonMediaPage(rawUrl)) return false;
+ if (!isMastodonMediaPage(rawUrl)) return false;
return /^\/@[A-Za-z0-9_]+(?:@[A-Za-z0-9.-]+)?\/\d+\/?$/.test(parsed.pathname)
|| /^\/users\/[A-Za-z0-9_]+\/statuses\/\d+\/?$/.test(parsed.pathname)
|| /^\/web\/statuses\/\d+\/?$/.test(parsed.pathname);
diff --git a/src/chrome/src/network/network-tools.js b/src/chrome/src/network/network-tools.js
index 2fa9dc281..b96cf7458 100644
--- a/src/chrome/src/network/network-tools.js
+++ b/src/chrome/src/network/network-tools.js
@@ -1,5 +1,6 @@
import { createRequestDeadline, readResponseText, responseAbortError } from './response-body.js';
import { isMastodonPublicMediaUrl } from '../agent/public-media-url.js';
+import { isKnownMastodonHost } from '../agent/adapters.js';
/**
* Network & download tools for the WebBrain agent.
*
@@ -406,26 +407,68 @@ function providerError(status, data, rawText) {
return typeof detail === 'string' ? detail.slice(0, 1000) : JSON.stringify(detail).slice(0, 1000);
}
-function inputUrlAllowed(rawUrl, rules = []) {
- if (!rules.length) return true;
+// Unknown instances must identify their software independently of the status
+// path. Probe only public metadata on that origin, never the supplied post URL.
+async function verifyMastodonInstance(origin) {
+ const deadline = createRequestDeadline({ timeoutMs: 10000 });
+ const readJson = async (url) => {
+ const response = await fetch(url, {
+ method: 'GET', headers: { Accept: 'application/json' },
+ credentials: 'omit', redirect: 'manual', signal: deadline.signal,
+ });
+ if (!response.ok || response.type === 'opaqueredirect'
+ || (response.url && response.url !== url)) return null;
+ const body = await readResponseText(response, {
+ signal: deadline.signal, maxBytes: 65536, idleTimeoutMs: 10000,
+ });
+ return body.exceeded ? null : JSON.parse(body.text);
+ };
+ try {
+ const discovery = await readJson(`${origin}/.well-known/nodeinfo`);
+ const links = Array.isArray(discovery?.links) ? discovery.links : [];
+ const link = ['2.1', '2.0'].map(version => links.find(item =>
+ item?.rel === `http://nodeinfo.diaspora.software/ns/schema/${version}`)).find(Boolean);
+ if (!link || typeof link.href !== 'string') return false;
+ const metadataUrl = new URL(link.href);
+ if (metadataUrl.origin !== origin || metadataUrl.username || metadataUrl.password) return false;
+ const metadata = await readJson(metadataUrl.href);
+ return metadata?.software?.name === 'mastodon';
+ } catch (_) {
+ return false;
+ } finally {
+ deadline.dispose();
+ }
+}
+
+async function allowedSkillInputUrl(rawUrl, rules = []) {
+ if (!rules.length) return rawUrl;
let u;
- try { u = new URL(rawUrl); } catch (_) { return false; }
+ try { u = new URL(rawUrl); } catch (_) { return null; }
const host = u.hostname.toLowerCase();
const path = u.pathname || '/';
- return rules.some((rule) => {
+ for (const rule of rules) {
if (rule.siteAdapter === 'mastodon') {
- return u.protocol === 'https:' && !u.username && !u.password && !u.port
- && /^(?:[a-z0-9-]+\.)+[a-z]{2,63}$/i.test(host)
- && !/\.(?:local|internal|localhost|lan|home|corp)$/i.test(host)
- && validateFetchUrl(rawUrl).ok && isMastodonPublicMediaUrl(rawUrl);
+ // URL already normalizes Unicode domains to IDNA. Check DNS labels rather
+ // than requiring an alphabetic TLD, which would reject punycoded TLDs.
+ const labels = host.split('.');
+ const publicDomain = host.length <= 253 && labels.length > 1
+ && labels.every(label => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(label))
+ && !/^\d+$/.test(labels.at(-1))
+ && !/\.(?:local|internal|localhost|lan|home|corp)$/i.test(host);
+ if (u.protocol !== 'https:' || u.username || u.password || u.port
+ || !publicDomain || !validateFetchUrl(rawUrl).ok || !isMastodonPublicMediaUrl(rawUrl)) continue;
+ if (isKnownMastodonHost(host) || await verifyMastodonInstance(u.origin)) {
+ // A public status needs only its path; never forward query tokens.
+ return `${u.origin}${path}`;
+ }
+ continue;
}
const ruleHost = String(rule.host || '').toLowerCase();
- if (!ruleHost) return false;
- const hostMatches = host === ruleHost || host.endsWith(`.${ruleHost}`);
- if (!hostMatches) return false;
+ if (!ruleHost || !(host === ruleHost || host.endsWith(`.${ruleHost}`))) continue;
const paths = Array.isArray(rule.paths) && rule.paths.length ? rule.paths : ['/'];
- return paths.some((prefix) => path.startsWith(String(prefix || '/')));
- });
+ if (paths.some(prefix => path.startsWith(String(prefix || '/')))) return rawUrl;
+ }
+ return null;
}
function applySkillResponseLimits(value, limits = {}) {
@@ -1218,8 +1261,12 @@ export async function executeHttpSkillTool(tool, args = {}, ctx = {}) {
if (tool.activeTabUrlArg && !payload[tool.activeTabUrlArg]) {
payload[tool.activeTabUrlArg] = await currentTabUrl(ctx.tabId);
}
- if (tool.inputUrlArg && payload[tool.inputUrlArg] && !inputUrlAllowed(payload[tool.inputUrlArg], tool.allowedInputUrls || [])) {
- return { success: false, error: `Skill tool input URL is outside its declared allowlist: ${tool.inputUrlArg}`, provider: endpoint.hostname };
+ if (tool.inputUrlArg && payload[tool.inputUrlArg]) {
+ const allowedUrl = await allowedSkillInputUrl(payload[tool.inputUrlArg], tool.allowedInputUrls || []);
+ if (!allowedUrl) {
+ return { success: false, error: `Skill tool input URL is outside its declared allowlist: ${tool.inputUrlArg}`, provider: endpoint.hostname };
+ }
+ payload[tool.inputUrlArg] = allowedUrl;
}
if (tool.kind === 'httpDownloadJob') {
diff --git a/src/firefox/src/agent/adapters.js b/src/firefox/src/agent/adapters.js
index 00b09bc3d..2658783ff 100644
--- a/src/firefox/src/agent/adapters.js
+++ b/src/firefox/src/agent/adapters.js
@@ -15660,6 +15660,12 @@ const KNOWN_MASTODON_HOSTS = new Set([
'zzz.frotz.net',
]);
+// Exact generated instance membership can be used by network allowlists.
+// The broader routing heuristic below is not proof of a Mastodon server.
+export function isKnownMastodonHost(hostname) {
+ return KNOWN_MASTODON_HOSTS.has(String(hostname || '').toLowerCase());
+}
+
// Keep direct URL matching conservative: bare /@user and /users/user routes are
// only Mastodon when the host is in the generated known-instance list.
export function isLikelyMastodonHost(hostname) {
diff --git a/src/firefox/src/agent/public-media-url.js b/src/firefox/src/agent/public-media-url.js
index 68aa59cbb..633144714 100644
--- a/src/firefox/src/agent/public-media-url.js
+++ b/src/firefox/src/agent/public-media-url.js
@@ -30,7 +30,7 @@ function hasPathId(path, pattern) {
export function isMastodonMediaPage(rawUrl) {
let parsed;
try { parsed = new URL(rawUrl); } catch { return false; }
- if (!['http:', 'https:'].includes(parsed.protocol)) return false;
+ if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port) return false;
const adapter = getActiveAdapter(rawUrl);
return adapter?.name === 'mastodon' || (!adapter && isLikelyMastodonHost(parsed.hostname));
}
@@ -38,7 +38,7 @@ export function isMastodonMediaPage(rawUrl) {
export function isMastodonPublicMediaUrl(rawUrl) {
let parsed;
try { parsed = new URL(rawUrl); } catch { return false; }
- if (!['http:', 'https:'].includes(parsed.protocol) || !isMastodonMediaPage(rawUrl)) return false;
+ if (!isMastodonMediaPage(rawUrl)) return false;
return /^\/@[A-Za-z0-9_]+(?:@[A-Za-z0-9.-]+)?\/\d+\/?$/.test(parsed.pathname)
|| /^\/users\/[A-Za-z0-9_]+\/statuses\/\d+\/?$/.test(parsed.pathname)
|| /^\/web\/statuses\/\d+\/?$/.test(parsed.pathname);
diff --git a/src/firefox/src/network/network-tools.js b/src/firefox/src/network/network-tools.js
index d38960337..9561f1e28 100644
--- a/src/firefox/src/network/network-tools.js
+++ b/src/firefox/src/network/network-tools.js
@@ -1,5 +1,6 @@
import { createRequestDeadline, readResponseText, responseAbortError } from './response-body.js';
import { isMastodonPublicMediaUrl } from '../agent/public-media-url.js';
+import { isKnownMastodonHost } from '../agent/adapters.js';
import { firefoxRestrictedDomainFailure } from '../firefox-restricted-domains.js';
import { filenameInConfiguredDownloadDirectory } from '../download-directory.js';
@@ -371,26 +372,68 @@ function providerError(status, data, rawText) {
return typeof detail === 'string' ? detail.slice(0, 1000) : JSON.stringify(detail).slice(0, 1000);
}
-function inputUrlAllowed(rawUrl, rules = []) {
- if (!rules.length) return true;
+// Unknown instances must identify their software independently of the status
+// path. Probe only public metadata on that origin, never the supplied post URL.
+async function verifyMastodonInstance(origin) {
+ const deadline = createRequestDeadline({ timeoutMs: 10000 });
+ const readJson = async (url) => {
+ const response = await fetch(url, {
+ method: 'GET', headers: { Accept: 'application/json' },
+ credentials: 'omit', redirect: 'manual', signal: deadline.signal,
+ });
+ if (!response.ok || response.type === 'opaqueredirect'
+ || (response.url && response.url !== url)) return null;
+ const body = await readResponseText(response, {
+ signal: deadline.signal, maxBytes: 65536, idleTimeoutMs: 10000,
+ });
+ return body.exceeded ? null : JSON.parse(body.text);
+ };
+ try {
+ const discovery = await readJson(`${origin}/.well-known/nodeinfo`);
+ const links = Array.isArray(discovery?.links) ? discovery.links : [];
+ const link = ['2.1', '2.0'].map(version => links.find(item =>
+ item?.rel === `http://nodeinfo.diaspora.software/ns/schema/${version}`)).find(Boolean);
+ if (!link || typeof link.href !== 'string') return false;
+ const metadataUrl = new URL(link.href);
+ if (metadataUrl.origin !== origin || metadataUrl.username || metadataUrl.password) return false;
+ const metadata = await readJson(metadataUrl.href);
+ return metadata?.software?.name === 'mastodon';
+ } catch (_) {
+ return false;
+ } finally {
+ deadline.dispose();
+ }
+}
+
+async function allowedSkillInputUrl(rawUrl, rules = []) {
+ if (!rules.length) return rawUrl;
let u;
- try { u = new URL(rawUrl); } catch (_) { return false; }
+ try { u = new URL(rawUrl); } catch (_) { return null; }
const host = u.hostname.toLowerCase();
const path = u.pathname || '/';
- return rules.some((rule) => {
+ for (const rule of rules) {
if (rule.siteAdapter === 'mastodon') {
- return u.protocol === 'https:' && !u.username && !u.password && !u.port
- && /^(?:[a-z0-9-]+\.)+[a-z]{2,63}$/i.test(host)
- && !/\.(?:local|internal|localhost|lan|home|corp)$/i.test(host)
- && validateFetchUrl(rawUrl).ok && isMastodonPublicMediaUrl(rawUrl);
+ // URL already normalizes Unicode domains to IDNA. Check DNS labels rather
+ // than requiring an alphabetic TLD, which would reject punycoded TLDs.
+ const labels = host.split('.');
+ const publicDomain = host.length <= 253 && labels.length > 1
+ && labels.every(label => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(label))
+ && !/^\d+$/.test(labels.at(-1))
+ && !/\.(?:local|internal|localhost|lan|home|corp)$/i.test(host);
+ if (u.protocol !== 'https:' || u.username || u.password || u.port
+ || !publicDomain || !validateFetchUrl(rawUrl).ok || !isMastodonPublicMediaUrl(rawUrl)) continue;
+ if (isKnownMastodonHost(host) || await verifyMastodonInstance(u.origin)) {
+ // A public status needs only its path; never forward query tokens.
+ return `${u.origin}${path}`;
+ }
+ continue;
}
const ruleHost = String(rule.host || '').toLowerCase();
- if (!ruleHost) return false;
- const hostMatches = host === ruleHost || host.endsWith(`.${ruleHost}`);
- if (!hostMatches) return false;
+ if (!ruleHost || !(host === ruleHost || host.endsWith(`.${ruleHost}`))) continue;
const paths = Array.isArray(rule.paths) && rule.paths.length ? rule.paths : ['/'];
- return paths.some((prefix) => path.startsWith(String(prefix || '/')));
- });
+ if (paths.some(prefix => path.startsWith(String(prefix || '/')))) return rawUrl;
+ }
+ return null;
}
function applySkillResponseLimits(value, limits = {}) {
@@ -1227,8 +1270,12 @@ export async function executeHttpSkillTool(tool, args = {}, ctx = {}) {
if (tool.activeTabUrlArg && !payload[tool.activeTabUrlArg]) {
payload[tool.activeTabUrlArg] = await currentTabUrl(ctx.tabId);
}
- if (tool.inputUrlArg && payload[tool.inputUrlArg] && !inputUrlAllowed(payload[tool.inputUrlArg], tool.allowedInputUrls || [])) {
- return { success: false, error: `Skill tool input URL is outside its declared allowlist: ${tool.inputUrlArg}`, provider: endpoint.hostname };
+ if (tool.inputUrlArg && payload[tool.inputUrlArg]) {
+ const allowedUrl = await allowedSkillInputUrl(payload[tool.inputUrlArg], tool.allowedInputUrls || []);
+ if (!allowedUrl) {
+ return { success: false, error: `Skill tool input URL is outside its declared allowlist: ${tool.inputUrlArg}`, provider: endpoint.hostname };
+ }
+ payload[tool.inputUrlArg] = allowedUrl;
}
if (tool.kind === 'httpDownloadJob') {
diff --git a/test/run.js b/test/run.js
index 8a30aae6f..f20546daa 100644
--- a/test/run.js
+++ b/test/run.js
@@ -24499,6 +24499,16 @@ test('public media recommendations carry immediate download_public_media fast pa
assert.equal(unsupported?.runOptions, undefined, 'unsupported public-media host should not get the skill fast path');
assert.doesNotMatch(unsupported?.prompt || '', /download_public_media/, 'unsupported public-media host should not force the skill tool');
+ for (const url of [
+ 'http://fosstodon.org/@alice/123', 'http://mastodon.social/home',
+ 'https://alice:[email protected]/@alice/123', 'https://fosstodon.org:8443/@alice/123',
+ ]) {
+ const action = buildRecommendedActions({ url, media: { videoCount: 1 } })
+ .find(item => item.id === 'download-media');
+ assert.equal(action?.runOptions, undefined, `unsupported Mastodon URL must not get a skill fast path: ${url}`);
+ assert.doesNotMatch(action?.prompt || '', /download_public_media/, `unsupported URL should use generic download advice: ${url}`);
+ }
+
const feedAction = buildRecommendedActions({
url: 'https://www.instagram.com/',
title: 'Instagram',
@@ -30667,6 +30677,20 @@ test('executeHttpSkillTool caps FreeSkillz transcript segments while leaving tex
}
});
+function mastodonNodeInfoResponse(url) {
+ const parsed = new URL(url);
+ if (parsed.pathname === '/.well-known/nodeinfo') {
+ return new Response(JSON.stringify({ links: [{
+ rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
+ href: `${parsed.origin}/nodeinfo/2.0`,
+ }] }));
+ }
+ if (parsed.pathname === '/nodeinfo/2.0') {
+ return new Response(JSON.stringify({ version: '2.0', software: { name: 'mastodon' } }));
+ }
+ return null;
+}
+
test('FreeSkillz resolves Bluesky and federated Mastodon posts without broadening the URL allowlist', async () => {
const originalFetch = globalThis.fetch;
try {
@@ -30678,7 +30702,8 @@ test('FreeSkillz resolves Bluesky and federated Mastodon posts without broadenin
const calls = [];
globalThis.fetch = async (url, opts) => {
calls.push({ url, opts });
- return { ok: true, status: 200, text: async () => JSON.stringify({ ext: 'mp4', formats: [{ ext: 'mp4' }] }) };
+ return mastodonNodeInfoResponse(url)
+ || { ok: true, status: 200, text: async () => JSON.stringify({ ext: 'mp4', formats: [{ ext: 'mp4' }] }) };
};
for (const url of [
'https://bsky.app.evil.example/profile/alice/post/123', 'https://bsky.app/home',
@@ -30718,6 +30743,118 @@ test('FreeSkillz resolves Bluesky and federated Mastodon posts without broadenin
}
});
+test('Mastodon media allowlists verify unknown hosts and never forward unverified URLs or query tokens', async () => {
+ const originalFetch = globalThis.fetch;
+ const origin = 'https://social.example.org';
+ const discoveryUrl = `${origin}/.well-known/nodeinfo`;
+ const metadataUrl = `${origin}/nodeinfo/2.0`;
+ const discovery = (href = metadataUrl) => new Response(JSON.stringify({ links: [{
+ rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', href,
+ }] }));
+ const cases = [
+ ['unrelated status-shaped page', 'https://example.com/@alice/123?token=secret', () => new Response('{}'), 1],
+ ['prefix heuristic is not proof', 'https://mastodon.example.org/@alice/123', () => new Response('{}'), 1],
+ ['known host suffix is not proof', 'https://fosstodon.org.evil.example/@alice/123', () => new Response('{}'), 1],
+ ['other fediverse software', `${origin}/@alice/123`, url => url === discoveryUrl ? discovery() : new Response(JSON.stringify({ software: { name: 'pleroma' } })), 2],
+ ['cross-origin metadata', `${origin}/@alice/123`, () => discovery('https://mastodon.social/nodeinfo/2.0'), 1],
+ ['HTTP metadata', `${origin}/@alice/123`, () => discovery('http://social.example.org/nodeinfo/2.0'), 1],
+ ['local metadata', `${origin}/@alice/123`, () => discovery('https://127.0.0.1/nodeinfo/2.0'), 1],
+ ['credentialed metadata', `${origin}/@alice/123`, () => discovery('https://user:[email protected]/nodeinfo/2.0'), 1],
+ ['redirecting discovery', `${origin}/@alice/123`, () => new Response('', { status: 302, headers: { Location: 'https://mastodon.social/.well-known/nodeinfo' } }), 1],
+ ['redirecting metadata', `${origin}/@alice/123`, url => url === discoveryUrl ? discovery() : new Response('', { status: 302 }), 2],
+ ['oversized discovery', `${origin}/@alice/123`, () => new Response(' '.repeat(65537)), 1],
+ ['oversized metadata', `${origin}/@alice/123`, url => url === discoveryUrl ? discovery() : new Response(' '.repeat(65537)), 2],
+ ['invalid metadata JSON', `${origin}/@alice/123`, url => url === discoveryUrl ? discovery() : new Response('<html>'), 2],
+ ['network failure', `${origin}/@alice/123`, () => { throw new Error('offline'); }, 1],
+ ];
+ try {
+ for (const [label, prefix, executeTool, normalizeSkills, buildRegistry] of [
+ ['chrome', 'src/chrome', executeHttpSkillToolCh, normalizeCustomSkillsCh, buildSkillToolRegistryCh],
+ ['firefox', 'src/firefox', executeHttpSkillToolFx, normalizeCustomSkillsFx, buildSkillToolRegistryFx],
+ ]) {
+ const registry = buildRegistry(normalizeSkills([packagedFreeSkillzRecord(prefix)]));
+ for (const name of ['resolve_public_media', 'download_public_media']) {
+ const tool = registry.get(name);
+ for (const [scenario, url, response, expectedCount] of cases) {
+ const calls = [];
+ globalThis.fetch = async (requestUrl, opts) => {
+ calls.push({ url: requestUrl, opts });
+ assert.notEqual(new URL(requestUrl).hostname, 'freeskillz.xyz', `${label}/${name}: ${scenario} must not reach provider`);
+ return response(requestUrl);
+ };
+ const result = await executeTool(tool, { url });
+ assert.equal(result.success, false, `${label}/${name}: reject ${scenario}`);
+ assert.equal(calls.length, expectedCount, `${label}/${name}: ${scenario} probe count`);
+ assert.equal(calls[0].url, `${new URL(url).origin}/.well-known/nodeinfo`);
+ for (const call of calls) {
+ assert.equal(call.opts.credentials, 'omit');
+ assert.equal(call.opts.redirect, 'manual');
+ assert.equal(call.opts.method, 'GET');
+ assert.equal(call.opts.signal.aborted, true, 'verification deadline must be disposed');
+ assert.equal(new URL(call.url).search, '', 'post query must not enter verification');
+ assert.equal(new URL(call.url).hash, '', 'post fragment must not enter verification');
+ }
+ }
+ }
+ for (const [url, expected, expectedProbes] of [
+ ['https://fosstodon.org/@alice/123?token=secret#private', 'https://fosstodon.org/@alice/123', 0],
+ [`${origin}/@alice/123?token=secret#private`, `${origin}/@alice/123`, 2],
+ ['https://social.みんな/@alice/123?token=secret#private', 'https://social.xn--q9jyb4c/@alice/123', 2],
+ ]) {
+ const probes = [];
+ const providerCalls = [];
+ globalThis.fetch = async (requestUrl, opts) => {
+ const metadata = mastodonNodeInfoResponse(requestUrl);
+ if (metadata) { probes.push({ url: requestUrl, opts }); return metadata; }
+ providerCalls.push({ url: requestUrl, opts });
+ return new Response(JSON.stringify({ ext: 'mp4' }));
+ };
+ const result = await executeTool(registry.get('resolve_public_media'), { url });
+ assert.equal(result.success, true, `${label}: verified public URL ${url}`);
+ assert.equal(probes.length, expectedProbes, `${label}: known hosts must not require discovery`);
+ assert.equal(providerCalls.length, 1);
+ assert.deepEqual(JSON.parse(providerCalls[0].opts.body), { url: expected });
+ }
+ }
+ } finally {
+ globalThis.fetch = originalFetch;
+ }
+});
+
+test('Mastodon instance verification bounds stalled response headers and bodies', async () => {
+ const originalFetch = globalThis.fetch;
+ const originalSetTimeout = globalThis.setTimeout;
+ try {
+ // Exercise the real timeout/abort path without waiting ten seconds per case.
+ globalThis.setTimeout = (fn, ms, ...args) => originalSetTimeout(fn, ms === 10000 ? 5 : ms, ...args);
+ for (const [prefix, executeTool, normalizeSkills, buildRegistry] of [
+ ['src/chrome', executeHttpSkillToolCh, normalizeCustomSkillsCh, buildSkillToolRegistryCh],
+ ['src/firefox', executeHttpSkillToolFx, normalizeCustomSkillsFx, buildSkillToolRegistryFx],
+ ]) {
+ const tool = buildRegistry(normalizeSkills([packagedFreeSkillzRecord(prefix)])).get('resolve_public_media');
+ let calls = 0;
+ globalThis.fetch = async (_url, opts) => {
+ calls++;
+ return new Promise((resolve, reject) => opts.signal.addEventListener('abort', () => reject(opts.signal.reason), { once: true }));
+ };
+ assert.equal((await executeTool(tool, { url: 'https://social.example.org/@alice/123' })).success, false);
+ assert.equal(calls, 1, 'stalled headers must not reach the provider');
+ let cancelled = false;
+ calls = 0;
+ globalThis.fetch = async () => {
+ calls++;
+ return new Response(new ReadableStream({ cancel() { cancelled = true; } }));
+ };
+ assert.equal((await executeTool(tool, { url: 'https://social.example.org/@alice/123' })).success, false);
+ assert.equal(calls, 1, 'stalled body must not reach the provider');
+ assert.equal(cancelled, true, 'stalled reader must be cancelled');
+ }
+ } finally {
+ globalThis.fetch = originalFetch;
+ globalThis.setTimeout = originalSetTimeout;
+ }
+});
+
test('executeHttpSkillTool runs FreeSkillz media download jobs and cleans up', async () => {
const originalFetch = globalThis.fetch;
const originalChrome = globalThis.chrome;
@@ -30739,6 +30876,8 @@ test('executeHttpSkillTool runs FreeSkillz media download jobs and cleans up', a
text: async () => JSON.stringify(body),
});
globalThis.fetch = async (url, opts = {}) => {
+ const metadata = mastodonNodeInfoResponse(url);
+ if (metadata) return metadata;
providerCalls.push({ url, opts });
if (url === 'https://freeskillz.xyz/v1/media/jobs' && opts.method === 'POST') {
return jsonResponse(200, { job_id: 'job_123' });
@@ -70474,7 +70613,7 @@ test('extended provider catalog is complete, mirrored, safe, and excluded-provid
302ai abacus aihubmix alibaba-coding-plan alibaba-coding-plan-cn
azure-cognitive-services bailing baseten berget cerebras chutes clarifai
cloudferro-sherlock cohere cortecs deepinfra demonroute digitalocean dinference drun
- evroc fastrouter friendli google-vertex google-vertex-anthropic helicone
+ evroc fastrouter freebuff2api friendli google-vertex google-vertex-anthropic helicone
iflowcn inception inference io-net jiekou kilo kimi-for-coding
kuae-cloud-coding-plan llama lucidquery meganova minimax-cn-coding-plan
minimax-coding-plan moark modelscope morph nano-gpt nearai nebius nova novita-ai
@@ -70486,7 +70625,7 @@ test('extended provider catalog is complete, mirrored, safe, and excluded-provid
`.trim().split(/\s+/);
const excluded = ['github-models', 'github-copilot', 'gitlab', 'sap-ai-core'];
- assert.equal(expectedIds.length, 80);
+ assert.equal(expectedIds.length, 81);
assert.deepEqual(ProviderCatalogCh.ADDITIONAL_PROVIDER_IDS, expectedIds);
assert.deepEqual(ProviderCatalogFx.ADDITIONAL_PROVIDER_IDS, expectedIds);
assert.deepEqual(
@@ -70500,7 +70639,7 @@ test('extended provider catalog is complete, mirrored, safe, and excluded-provid
['firefox', ProviderManagerFx, 'src/firefox'],
]) {
const defaults = new PM()._defaultConfigs();
- const expectedDefaultCount = label === 'chrome' ? 113 : 112;
+ const expectedDefaultCount = label === 'chrome' ? 114 : 113;
assert.equal(
Object.keys(defaults).length,
expectedDefaultCount,
@@ -70517,7 +70656,7 @@ test('extended provider catalog is complete, mirrored, safe, and excluded-provid
expectedAskStreaming,
`${label}: ${id} Ask streaming capability mismatch`,
);
- assert.ok(config.model || id === 'azure-cognitive-services', `${label}: ${id} missing model`);
+ assert.ok(config.model || config.requiresModel === true || id === 'azure-cognitive-services', `${label}: ${id} missing model`);
const icon = path.join(ROOT, prefix, 'icons/providers', `${id}.svg`);
assert.equal(fs.existsSync(icon), true, `${label}: missing icon for ${id}`);