diff --git a/marketplace/index.html b/marketplace/index.html index 2c9db94..6b66fcf 100644 --- a/marketplace/index.html +++ b/marketplace/index.html @@ -23,5 +23,5 @@

Make the ecosystem bigger

Your integration belongs here.

Connect a framework, platform, policy engine, or governance product to the AgenTrust stack. The submission path is public, self-serve, and governed by the same rules for everyone.

List your integration ↗
- + diff --git a/marketplace/marketplace.js b/marketplace/marketplace.js index 2f3da6a..0912e28 100644 --- a/marketplace/marketplace.js +++ b/marketplace/marketplace.js @@ -1,12 +1,14 @@ (async function () { 'use strict'; + function escape(value) { return String(value).replace(/[&<>"']/g, (character) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[character])); } + function safeUrl(value) { try { const parsed = new URL(String(value)); return parsed.protocol === 'https:' ? parsed.href : '#'; } catch (_) { return '#'; } } + if (typeof module !== 'undefined' && module.exports) { module.exports = { escape, safeUrl }; return; } const AGENTRUST_CATALOG = 'https://raw.githubusercontent.com/agentrust-io/integrations/main/marketplace/catalog.json'; const AGT_CATALOG = 'https://raw.githubusercontent.com/agentrust-io/integrations/main/marketplace/agt-catalog.json'; let items = []; const state = { query: '', stacks: new Set(), types: new Set(), sort: 'featured' }; const search = document.getElementById('market-search'), grid = document.getElementById('market-grid'), empty = document.getElementById('market-empty'), status = document.getElementById('catalog-status'); const slug = (value) => value.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, ''); - function escape(value) { const node = document.createElement('span'); node.textContent = value; return node.innerHTML; } async function fetchJson(url) { const controller = new AbortController(), timeout = setTimeout(() => controller.abort(), 8000); try { const response = await fetch(url, { headers: { Accept: 'application/json' }, signal: controller.signal }); if (!response.ok) throw new Error(`${url} returned ${response.status}`); return await response.json(); } finally { clearTimeout(timeout); } } function normalizeAgenTrust(catalog) { if (catalog.catalog_version !== 1 || !Array.isArray(catalog.integrations) || catalog.count !== catalog.integrations.length) throw new Error('unsupported AgenTrust catalog'); @@ -19,7 +21,7 @@ function card(item, compact) { const tags = item.stack.map((tag) => `${escape(tag)}`).join(''); const tier = item.source === 'AGT' ? 'AGT project' : `${item.tier[0].toUpperCase()}${item.tier.slice(1)}`; - return `
${escape(item.mark)} ${escape(tier)}

By ${escape(item.vendor)}

${escape(item.name)}

${escape(item.description)}

${tags}
View integration ↗
`; + return `
${escape(item.mark)} ${escape(tier)}

By ${escape(item.vendor)}

${escape(item.name)}

${escape(item.description)}

${tags}
View integration ↗
`; } function addFilters(target, values, key) { document.getElementById(target).innerHTML = values.map((value) => { const count = items.filter((item) => key === 'stacks' ? item.stack.includes(value) : item.type === value).length, id = `${key}-${slug(value)}`; return ``; }).join(''); diff --git a/marketplace/marketplace.test.js b/marketplace/marketplace.test.js new file mode 100644 index 0000000..5f48e87 --- /dev/null +++ b/marketplace/marketplace.test.js @@ -0,0 +1,14 @@ +'use strict'; + +const assert = require('node:assert/strict'); +const { escape, safeUrl } = require('./marketplace.js'); + +assert.equal( + escape('" onmouseover="alert(1)" '), '#'); +assert.equal(safeUrl('http://example.com/insecure'), '#'); +assert.equal(safeUrl('not a URL'), '#'); +assert.equal(safeUrl('https://github.com/agentrust-io/integrations'), 'https://github.com/agentrust-io/integrations');