From a67f5284253d97ef8a272deaf8a19a4db8603dc3 Mon Sep 17 00:00:00 2001 From: hugocasa Date: Thu, 3 Dec 2026 10:49:29 +0100 Subject: [PATCH] fix: refuse the tools preview to a token withholding superadmin rights, restricted badge after a single access line Co-Authored-By: Claude Opus 5.5 --- backend/tests/mcp_role_access.rs | 39 ++++++++++++------- backend/windmill-api/src/mcp/role_access.rs | 7 ++-- .../src/lib/components/mcp/workspaceAccess.ts | 2 +- .../oauth/mcp_authorize/+page@(root).svelte | 6 ++- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/backend/tests/mcp_role_access.rs b/backend/tests/mcp_role_access.rs index 57fc70919f..a123b378e6 100644 --- a/backend/tests/mcp_role_access.rs +++ b/backend/tests/mcp_role_access.rs @@ -157,22 +157,31 @@ async fn role_setting_caps_every_token(db: Pool) -> anyhow::Result<()> .filter_map(|t| t["name"].as_str()) .collect(); assert_eq!(names, ["in_set"], "{preview}"); - // A token holding back its owner's admin rights would list scripts only an admin reads. - sqlx::query( - "INSERT INTO token (token_hash, token_prefix, email, label, super_admin, admin) - VALUES (encode(sha256('NOADMIN_TOKEN'::bytea), 'hex'), 'NOADMIN_TO', $1, 'mcp', false, false)", - ) - .bind(admin) - .execute(&db) - .await?; - let refused = reqwest::Client::new() - .get(format!( - "http://localhost:{port}/api/mcp/gateway/oauth/server/runnable_tools?workspace_id=test-workspace" - )) - .bearer_auth("NOADMIN_TOKEN") - .send() + // A token holding back its owner's admin or superadmin rights would list scripts only those + // rights read. + for (name, admin_rights) in [("NOADMIN_TOKEN", false), ("NOSUPER_TOKEN", true)] { + sqlx::query( + "INSERT INTO token (token_hash, token_prefix, email, label, super_admin, admin) + VALUES (encode(sha256($1::text::bytea), 'hex'), left($1::text, 10), $2, 'mcp', false, $3)", + ) + .bind(name) + .bind(admin) + .bind(admin_rights) + .execute(&db) .await?; - assert!(!refused.status().is_success(), "{}", refused.status()); + let refused = reqwest::Client::new() + .get(format!( + "http://localhost:{port}/api/mcp/gateway/oauth/server/runnable_tools?workspace_id=test-workspace" + )) + .bearer_auth(name) + .send() + .await?; + assert!( + !refused.status().is_success(), + "{name}: {}", + refused.status() + ); + } let call = |url: &'static str, token: &'static str, name: &'static str, args: Value| async move { mcp( port, diff --git a/backend/windmill-api/src/mcp/role_access.rs b/backend/windmill-api/src/mcp/role_access.rs index 47dc4b1d9b..461599101b 100644 --- a/backend/windmill-api/src/mcp/role_access.rs +++ b/backend/windmill-api/src/mcp/role_access.rs @@ -389,10 +389,11 @@ pub async fn list_runnable_tools( "A scope-restricted token cannot list its owner's tools".to_string(), )); } - // The listing runs with the owner's admin rights, which this token does not carry. - if authed.admin_withheld { + // The listing runs with the owner's admin and superadmin rights, which this token may not + // carry: only a credential holding both may list. + if authed.admin_withheld || authed.super_admin_withheld { return Err(Error::NotAuthorized( - "A token without its owner's admin rights cannot list its owner's tools".to_string(), + "A token without all of its owner's rights cannot list its owner's tools".to_string(), )); } let w_id = query.workspace_id; diff --git a/frontend/src/lib/components/mcp/workspaceAccess.ts b/frontend/src/lib/components/mcp/workspaceAccess.ts index c8f4130345..de87b0f84f 100644 --- a/frontend/src/lib/components/mcp/workspaceAccess.ts +++ b/frontend/src/lib/components/mcp/workspaceAccess.ts @@ -7,7 +7,7 @@ export type WorkspaceAccess = McpWorkspaceAccess['access'] /** What each access level lets the client do. */ export const ACCESS_HINTS: Record = { - full: 'Everything you can do yourself: explore, write, test and deploy drafts, and run.', + full: 'Everything you can do yourself: explore, build, test, deploy and run.', read_run: 'Explore, and run deployed scripts, flows and agents. The client changes nothing itself; what it runs can.', read: 'Explore and read. Nothing is run or changed.', diff --git a/frontend/src/routes/(root)/(logged)/oauth/mcp_authorize/+page@(root).svelte b/frontend/src/routes/(root)/(logged)/oauth/mcp_authorize/+page@(root).svelte index 2e4d7a4e7a..e8e1799de2 100644 --- a/frontend/src/routes/(root)/(logged)/oauth/mcp_authorize/+page@(root).svelte +++ b/frontend/src/routes/(root)/(logged)/oauth/mcp_authorize/+page@(root).svelte @@ -610,10 +610,10 @@ {#if same} {@const restricted = restriction(first, access)}
+ {accessLabel(first, access)} {#if restricted} Restricted {/if} - {accessLabel(first, access)} {restricted ?? accessHint(first, access)} {@render pen()}
@@ -662,7 +662,9 @@
{#each leftOut as w (w.id)}
- {w.name} + {#if !one} + {w.name} + {/if}