fix(32.2): WR-06 check the consent provider's redirect against the request's redirect URI
cabana loads the pending request on both decisions and refuses (500) a Decide answer whose scheme, user info, host, path or opaque part differ from the registered redirect URI. The admin SPA also refuses blob:, file:, about: and filesystem: and a destination that does not return to the host the consent card showed. Regenerated the admin OpenAPI document and rebuilt modules/boardwalk/dist.
This commit is contained in:
@@ -5316,7 +5316,7 @@
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"description": "Allows or denies a pending MCP authorization request for the signed-in admin and answers the client redirect URI. Submitted scopes that were not requested or that the admin cannot grant are dropped, * collapses as for personal tokens, and 422 no_grantable_scopes answers when nothing is left. Needs X-Requested-With; the body is capped at 16 KiB and unknown fields are refused (400). Personal API tokens are refused (403 interactive_only).",
|
||||
"description": "Allows or denies a pending MCP authorization request for the signed-in admin and answers the client redirect URI. Submitted scopes that were not requested or that the admin cannot grant are dropped, * collapses as for personal tokens, and 422 no_grantable_scopes answers when nothing is left. Both decisions load the request first; a provider redirect that does not go back to the request's redirect URI (same scheme, host and path) is refused (500). Needs X-Requested-With; the body is capped at 16 KiB and unknown fields are refused (400). Personal API tokens are refused (403 interactive_only).",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Pending request id",
|
||||
|
||||
2
admin/src/api/schema.d.ts
vendored
2
admin/src/api/schema.d.ts
vendored
@@ -1705,7 +1705,7 @@ export interface paths {
|
||||
put?: never;
|
||||
/**
|
||||
* Allow or deny an MCP consent request
|
||||
* @description Allows or denies a pending MCP authorization request for the signed-in admin and answers the client redirect URI. Submitted scopes that were not requested or that the admin cannot grant are dropped, * collapses as for personal tokens, and 422 no_grantable_scopes answers when nothing is left. Needs X-Requested-With; the body is capped at 16 KiB and unknown fields are refused (400). Personal API tokens are refused (403 interactive_only).
|
||||
* @description Allows or denies a pending MCP authorization request for the signed-in admin and answers the client redirect URI. Submitted scopes that were not requested or that the admin cannot grant are dropped, * collapses as for personal tokens, and 422 no_grantable_scopes answers when nothing is left. Both decisions load the request first; a provider redirect that does not go back to the request's redirect URI (same scheme, host and path) is refused (500). Needs X-Requested-With; the body is capped at 16 KiB and unknown fields are refused (400). Personal API tokens are refused (403 interactive_only).
|
||||
*/
|
||||
post: {
|
||||
parameters: {
|
||||
|
||||
@@ -188,7 +188,41 @@ function scopeDisabled(name: string): boolean {
|
||||
return starChecked.value && name !== '*'
|
||||
}
|
||||
|
||||
/** The server-issued redirect, refused when its scheme could run script (T-32.2-09). */
|
||||
/** Schemes a consent redirect never uses: script, inline content and local files. */
|
||||
const FORBIDDEN_PROTOCOLS = new Set(['javascript:', 'data:', 'vbscript:', 'blob:', 'file:', 'about:', 'filesystem:'])
|
||||
|
||||
/**
|
||||
* Whether url returns to the place the consent screen showed: the
|
||||
* redirect host (with its port) for a URI with a host, or the URI without
|
||||
* query and fragment for one without (a custom scheme). Both sides go
|
||||
* through the URL parser, so case and default ports compare as the browser
|
||||
* sees them.
|
||||
*/
|
||||
function returnsTo(url: URL, host: string): boolean {
|
||||
if (host === '') {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
if (url.host !== '') {
|
||||
return new URL(`${url.protocol}//${host}`).host === url.host
|
||||
}
|
||||
const want = new URL(host)
|
||||
const got = new URL(url.href)
|
||||
for (const u of [want, got]) {
|
||||
u.search = ''
|
||||
u.hash = ''
|
||||
}
|
||||
return want.href === got.href
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The server-issued redirect, refused when its scheme could run script or
|
||||
* open local content, or when it leaves for another place than the one the
|
||||
* screen named (T-32.2-09).
|
||||
*/
|
||||
function safeDestination(uri: string): string | null {
|
||||
let url: URL
|
||||
try {
|
||||
@@ -196,7 +230,7 @@ function safeDestination(uri: string): string | null {
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
if (url.protocol === 'javascript:' || url.protocol === 'data:' || url.protocol === 'vbscript:') {
|
||||
if (FORBIDDEN_PROTOCOLS.has(url.protocol) || !returnsTo(url, redirectHost.value)) {
|
||||
return null
|
||||
}
|
||||
return uri
|
||||
|
||||
@@ -258,13 +258,22 @@ describe('no auto-allow and the decision navigation (UI backstop)', () => {
|
||||
expect(wrapper.find('[data-action="allow"]').exists()).toBe(false)
|
||||
expect(document.activeElement).toBe(card.find('h1').element)
|
||||
|
||||
const custom = await open('/connect?request=req1', routes(consentView(), ok({ redirect_uri: 'myagent:/callback?code=1' })))
|
||||
const customView = consentView({ client: { id: 'client-1', name: 'Acme Agent', redirect_host: 'myagent:/callback', logo_url: '' } })
|
||||
const custom = await open('/connect?request=req1', routes(customView, ok({ redirect_uri: 'myagent:/callback?code=1' })))
|
||||
await custom.wrapper.find('[data-connect-state="ready"]').trigger('submit')
|
||||
await flushPromises()
|
||||
expect(assign).toHaveBeenLastCalledWith('myagent:/callback?code=1')
|
||||
const returning = custom.wrapper.find('[data-connect-state="returning"]')
|
||||
expect(returning.find('[data-connect-continue]').exists()).toBe(false)
|
||||
expect(returning.find('h1').text()).toBe('Returning to agent.example.test')
|
||||
expect(returning.find('h1').text()).toBe('Returning to myagent:/callback')
|
||||
})
|
||||
|
||||
it('leaves for a redirect whose host matches the shown one as the browser compares hosts', async () => {
|
||||
const view = consentView({ client: { id: 'client-1', name: 'Acme Agent', redirect_host: 'Agent.Example.Test:443', logo_url: '' } })
|
||||
const { wrapper } = await open('/connect?request=req1', routes(view))
|
||||
await wrapper.find('[data-connect-state="ready"]').trigger('submit')
|
||||
await flushPromises()
|
||||
expect(assign).toHaveBeenCalledWith(REDIRECT)
|
||||
})
|
||||
|
||||
it('disables both buttons and the scopes while a decision is in flight', async () => {
|
||||
@@ -290,7 +299,21 @@ describe('no auto-allow and the decision navigation (UI backstop)', () => {
|
||||
})
|
||||
|
||||
describe('submit failures', () => {
|
||||
it.each(['javascript:alert(1)', 'data:text/html,<script>x</script>', 'vbscript:msgbox(1)', 'JavaScript:alert(1)', 'not a uri'])(
|
||||
it.each([
|
||||
'javascript:alert(1)',
|
||||
'data:text/html,<script>x</script>',
|
||||
'vbscript:msgbox(1)',
|
||||
'JavaScript:alert(1)',
|
||||
'not a uri',
|
||||
'blob:https://agent.example.test/0b7c',
|
||||
'file:///etc/passwd',
|
||||
'about:blank',
|
||||
'filesystem:https://agent.example.test/temporary/x',
|
||||
'https://evil.example.test/callback?code=abc123',
|
||||
'https://agent.example.test.evil.example/callback?code=abc123',
|
||||
'https://agent.example.test:8443/callback?code=abc123',
|
||||
'myagent:/callback?code=1',
|
||||
])(
|
||||
'treats the redirect %j as a submit failure',
|
||||
async (uri) => {
|
||||
const { wrapper, push, replace } = await open('/connect?request=req1', routes(consentView(), ok({ redirect_uri: uri })))
|
||||
|
||||
Reference in New Issue
Block a user