🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(ai-team): verify ChatGPT MCP resource audience (#3544)
rUv9016dd6720e2
diff --git a/plugins/ruflo-ai-team/README.md b/plugins/ruflo-ai-team/README.mdindex 43bce86be7..b9f9ccf426 100644--- a/plugins/ruflo-ai-team/README.md+++ b/plugins/ruflo-ai-team/README.md@@ -21,7 +21,7 @@ npm testnpm run smoke```-Run locally with `RUFLO_AI_TEAM_STORE=memory npm start`. Production requires a unique OAuth audience, Firestore IAM, and the environment variables documented in `deploy/cloud-run.yaml`.+Run locally with `RUFLO_AI_TEAM_STORE=memory npm start`. Production requires the exact OAuth resource audience `https://team.ruv.io/mcp`, Firestore IAM, and the environment variables documented in `deploy/cloud-run.yaml`. ChatGPT connections registered before the `team:*` scope ceiling was added must be created again so dynamic client registration includes those scopes.## Compatibilitydiff --git a/plugins/ruflo-ai-team/deploy/cloud-run.yaml b/plugins/ruflo-ai-team/deploy/cloud-run.yamlindex f6cad16153..c94d99c1ca 100644--- a/plugins/ruflo-ai-team/deploy/cloud-run.yaml+++ b/plugins/ruflo-ai-team/deploy/cloud-run.yaml@@ -21,4 +21,4 @@ spec:- { name: RUFLO_AI_TEAM_PUBLIC_URL, value: "https://team.ruv.io" }- { name: RUFLO_AI_TEAM_STORE, value: "firestore" }- { name: RUFLO_AI_TEAM_OAUTH_ISSUER, value: "https://auth.cognitum.one" }- - { name: RUFLO_AI_TEAM_OAUTH_CLIENT_ID, value: "REPLACE_WITH_RESOURCE_CLIENT_ID" }+ - { name: RUFLO_AI_TEAM_OAUTH_AUDIENCE, value: "https://team.ruv.io/mcp" }diff --git a/plugins/ruflo-ai-team/src/server.mjs b/plugins/ruflo-ai-team/src/server.mjsindex d93d0d061e..eede5aa37f 100644--- a/plugins/ruflo-ai-team/src/server.mjs+++ b/plugins/ruflo-ai-team/src/server.mjs@@ -35,7 +35,7 @@ export async function createAiTeamService({ store, vectorMemory, verifyToken, povectorMemory ||= await vectorMemoryFromEnv(store);const publicUrl = (process.env.RUFLO_AI_TEAM_PUBLIC_URL || 'https://team.ruv.io').replace(/\/$/, '');const issuer = (process.env.RUFLO_AI_TEAM_OAUTH_ISSUER || 'https://auth.cognitum.one').replace(/\/$/, '');- const audience = process.env.RUFLO_AI_TEAM_OAUTH_CLIENT_ID || 'ruflo-ai-team';+ const audience = process.env.RUFLO_AI_TEAM_OAUTH_AUDIENCE || `${publicUrl}/mcp`;const jwksUri = process.env.RUFLO_AI_TEAM_OAUTH_JWKS_URI || `${issuer}/.well-known/jwks.json`;const authConfig = { issuer, audience, jwksUri };const metadataUrl = `${publicUrl}/.well-known/oauth-protected-resource/mcp`;@@ -94,10 +94,14 @@ export async function createAiTeamService({ store, vectorMemory, verifyToken, poif(req.method==='GET'&&(url.pathname==='/'||url.pathname==='/mcp'))return res.writeHead(200,{'content-type':'application/json'}).end(JSON.stringify({service:'ruflo-ai-team',version:VERSION,endpoint:`${publicUrl}/mcp`,authentication:'oauth2',scopes:Object.values(SCOPES),resources:['ruv://team/templates']}));if(url.pathname!=='/mcp'||req.method!=='POST')return res.writeHead(404).end('not found');let parsed; try{parsed=JSON.parse(await readBody(req)||'{}');}catch{return res.writeHead(400,{'content-type':'application/json'}).end('{"error":"invalid_request"}');}- const auth=await authenticate(req,authConfig,verifyToken);- if(auth.mode==='denied')return res.writeHead(401,{'content-type':'application/json','www-authenticate':challengeHeader(metadataUrl,{error:auth.error,description:auth.description})}).end(JSON.stringify({error:auth.error,error_description:auth.description}));const called=parsed?.method==='tools/call'?parsed?.params?.name:null;const needsAuth=called||parsed?.method==='resources/read';+ // Discovery is public even when a client sends an expired or legacy-audience+ // bearer. Never downgrade a protected call or an unknown method.+ const publicDiscovery=new Set(['initialize','ping','tools/list','resources/list','prompts/list']);+ let auth=await authenticate(req,authConfig,verifyToken);+ if(auth.mode==='denied'&&publicDiscovery.has(parsed?.method))auth={mode:'anonymous',scopes:[]};+ if(auth.mode==='denied')return res.writeHead(401,{'content-type':'application/json','www-authenticate':challengeHeader(metadataUrl,{error:auth.error,description:auth.description,scope:SCOPES.read})}).end(JSON.stringify({error:auth.error,error_description:auth.description}));if(needsAuth&&auth.mode!=='oauth'){const scope=called?TOOL_SCOPES[called]:SCOPES.read;return res.writeHead(401,{'content-type':'application/json','www-authenticate':challengeHeader(metadataUrl,{error:'invalid_token',description:'OAuth authorization is required for tenant data',scope})}).end(JSON.stringify({error:'invalid_token'}));}if(called&&TOOL_SCOPES[called]&&!hasScope(auth,TOOL_SCOPES[called]))return res.writeHead(403,{'content-type':'application/json','www-authenticate':challengeHeader(metadataUrl,{error:'insufficient_scope',description:`${TOOL_SCOPES[called]} is required`,scope:TOOL_SCOPES[called]})}).end(JSON.stringify({error:'insufficient_scope'}));const mcp=buildMcp(auth); const transport=new StreamableHTTPServerTransport({sessionIdGenerator:undefined}); res.on('close',()=>{transport.close();mcp.close();}); await mcp.connect(transport); return transport.handleRequest(req,res,parsed);diff --git a/plugins/ruflo-ai-team/test/service.node.mjs b/plugins/ruflo-ai-team/test/service.node.mjsindex 0a3c3e1ff4..92e291554a 100644--- a/plugins/ruflo-ai-team/test/service.node.mjs+++ b/plugins/ruflo-ai-team/test/service.node.mjs@@ -4,11 +4,13 @@ import { createAiTeamService } from '../src/server.mjs';import { InMemoryStore } from '../src/store.mjs';import { TenantVectorMemory } from '../src/vector-memory.mjs';-const fakeVerify = async (token) => {+const fakeVerify = async (token, _jwks, options) => {const [tenant, mode = 'all'] = String(token).split(':');if (tenant === 'bad') throw new Error('signature verification failed');const scope = mode === 'read' ? 'team:read' : mode === 'write' ? 'team:write' : mode === 'run' ? 'team:run' : 'team:read team:write team:run';- return { payload: { iss: 'https://auth.cognitum.one', aud: 'ruflo-ai-team', sub: `${tenant}-user`, tenant_id: tenant, scope } };+ const aud = tenant === 'legacy' ? 'ruflo-ai-team' : 'https://team.ruv.io/mcp';+ if (aud !== options.audience) throw new Error('unexpected JWT audience');+ return { payload: { iss: 'https://auth.cognitum.one', aud, sub: `${tenant}-user`, tenant_id: tenant, scope } };};async function fixture() {@@ -43,6 +45,16 @@ test('tools/list is open but tenant calls challenge with RFC 9728 metadata', asyassert.equal(deniedCall.status,401); assert.match(deniedCall.wwwAuth,/oauth-protected-resource\/mcp/); assert.match(deniedCall.wwwAuth,/team:read/);});+test('legacy client-audience bearer tokens cannot access or mask discovery', async (t) => {+ const f=await fixture(); t.after(()=>f.server.close());+ const listed=await rpc(f.base,{jsonrpc:'2.0',id:1,method:'tools/list',params:{}},'legacy:all');+ assert.equal(listed.status,200);+ assert.equal(listed.body.result.tools.length,12);+ const deniedCall=await call(f.base,'team_list',{},'legacy:all');+ assert.equal(deniedCall.status,401);+ assert.match(deniedCall.wwwAuth,/invalid_token/);+});+test('every tool has explicit annotations and no secret-bearing input field', async (t) => {const f=await fixture(); t.after(()=>f.server.close());const listed=await rpc(f.base,{jsonrpc:'2.0',id:1,method:'tools/list',params:{}});