mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
fix(mcp): consent checkboxes post as grant so they never shadow the original scope
This commit is contained in:
@@ -81,7 +81,7 @@ export function consentPage(view: ConsentView, csrf: string, formAction: string,
|
||||
const scopes = view.scopes
|
||||
.map(
|
||||
({ scope, label }) =>
|
||||
`<li><label><input type="checkbox" name="scope" value="${esc(scope)}" checked><span>${esc(label)}<br><code>${esc(scope)}</code></span></label></li>`
|
||||
`<li><label><input type="checkbox" name="grant" value="${esc(scope)}" checked><span>${esc(label)}<br><code>${esc(scope)}</code></span></label></li>`
|
||||
)
|
||||
.join('')
|
||||
const body =
|
||||
|
||||
@@ -313,7 +313,7 @@ export async function authorize(request: Request, url: URL, env: OAuthEnv): Prom
|
||||
return consentPage(viewFor(req, client, fresh, 'That approval code or API key is not valid (it may have expired or been used). Get a new one from Orca.'), fresh, redirectTarget(req.redirectUri).formAction, 401)
|
||||
}
|
||||
// Only what was requested, what the user left ticked, and what the credential itself may do.
|
||||
const ticked = new Set(form.getAll('scope'))
|
||||
const ticked = new Set(form.getAll('grant'))
|
||||
const scopes = req.scopes.filter((scope) => ticked.has(scope) && grantor.scopes.has(scope))
|
||||
if (scopes.length === 0) {
|
||||
return redirectWith(req.redirectUri, { error: 'invalid_scope', error_description: 'None of the requested scopes could be granted', state: req.state, iss: env.origin })
|
||||
|
||||
@@ -74,8 +74,8 @@ async function harness() {
|
||||
for (const [, name = '', value = ''] of html.matchAll(/<input type="hidden" name="([^"]+)" value="([^"]*)">/g)) {
|
||||
form.set(name, value.replaceAll('&', '&').replaceAll('"', '"').replaceAll(''', "'").replaceAll('<', '<').replaceAll('>', '>'))
|
||||
}
|
||||
for (const [, scope = ''] of html.matchAll(/name="scope" value="([^"]+)" checked/g)) {
|
||||
if (!opts.untick?.includes(scope)) form.append('scope', scope)
|
||||
for (const [, scope = ''] of html.matchAll(/name="grant" value="([^"]+)" checked/g)) {
|
||||
if (!opts.untick?.includes(scope)) form.append('grant', scope)
|
||||
}
|
||||
if (opts.csrf !== undefined) {
|
||||
opts.csrf === null ? form.delete('csrf') : form.set('csrf', opts.csrf)
|
||||
|
||||
Reference in New Issue
Block a user