fix(mcp): consent checkboxes post as grant so they never shadow the original scope

This commit is contained in:
Neil
2026-11-09 04:53:57 -08:00
parent 36ef481da6
commit 56688adfe1
3 changed files with 4 additions and 4 deletions
@@ -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 =
+1 -1
View File
@@ -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 })
+2 -2
View File
@@ -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('&amp;', '&').replaceAll('&quot;', '"').replaceAll('&#39;', "'").replaceAll('&lt;', '<').replaceAll('&gt;', '>'))
}
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)