x402-payguard / tree / scripts/injectscan-listing.mjs ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Runs every public listing text (402 descriptions, openapi, .well-known, MCP tools, landing, README) through
// InjectScan's rules (sibling repo ../x402-prompt-injection-scan) and fails if anything is not "safe".
import { readFileSync } from 'node:fs';
import { scan } from '../../x402-prompt-injection-scan/src/detect.js';
import { scanTools } from '../../x402-prompt-injection-scan/src/scanner.js';
import { createApp, ADDRESS_DESCRIPTION, BATCH_DESCRIPTION } from '../src/app.js';
import { TOOLS as STDIO_TOOLS } from '../src/mcp-stdio.js';
const app = createApp({ facilitatorClient: { getSupported: async () => ({ kinds: [{ x402Version: 2, scheme: 'exact', network: 'eip155:8453' }], extensions: ['bazaar'], signers: {} }) }, publicUrl: 'https://payguard.agentgate.workers.dev' });
const get = async (p, h = {}) => (await app.fetch(new Request(`https://payguard.agentgate.workers.dev${p}`, { headers: h }))).text();
const rpc = async (body) => (await app.fetch(new Request('https://payguard.agentgate.workers.dev/mcp', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }))).json();
const remoteTools = (await rpc({ jsonrpc: '2.0', id: 1, method: 'tools/list' })).result.tools;
const r402 = await app.fetch(new Request('https://payguard.agentgate.workers.dev/v1/address'));
const texts = {
  address_description: ADDRESS_DESCRIPTION, batch_description: BATCH_DESCRIPTION,
  payment_required: Buffer.from(r402.headers.get('PAYMENT-REQUIRED'), 'base64').toString('utf8'),
  openapi: await get('/openapi.json'), well_known: await get('/.well-known/x402'), root: await get('/'),
  landing: (await get('/', { accept: 'text/html' })).replace(/<style>[\s\S]*?<\/style>|<script>[\s\S]*?<\/script>/g, ''),
  readme: readFileSync(new URL('../README.md', import.meta.url), 'utf8'),
  package_description: JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).description,
};
let bad = 0;
for (const [k, t] of Object.entries(texts)) { const r = scan(t); console.log(k.padEnd(20), r.verdict, r.risk_score, (r.findings || []).map((f) => f.rule || f.id).join(",")); if (r.verdict !== 'safe') bad++; }
for (const [k, tools] of [['mcp_remote', remoteTools], ['mcp_stdio', STDIO_TOOLS]]) { const r = scanTools(tools); console.log(k.padEnd(20), r.verdict, r.risk_score); if (r.verdict !== 'safe') bad++; }
process.exit(bad ? 1 : 0);

agentgate-source: code mirror on Cloudflare Pages. All repos