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 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-03 10:49:29 +01:00
co-authored by Claude Opus 5.5
parent 2efcb9b1d9
commit a67f528425
4 changed files with 33 additions and 21 deletions
+24 -15
View File
@@ -157,22 +157,31 @@ async fn role_setting_caps_every_token(db: Pool<Postgres>) -> 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,
+4 -3
View File
@@ -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;
@@ -7,7 +7,7 @@ export type WorkspaceAccess = McpWorkspaceAccess['access']
/** What each access level lets the client do. */
export const ACCESS_HINTS: Record<McpAccess, string> = {
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.',
@@ -610,10 +610,10 @@
{#if same}
{@const restricted = restriction(first, access)}
<div class="flex flex-wrap items-center gap-x-1.5">
<span class="text-xs text-primary">{accessLabel(first, access)}</span>
{#if restricted}
<Badge color="gray" small>Restricted</Badge>
{/if}
<span class="text-xs text-primary">{accessLabel(first, access)}</span>
<Tooltip small>{restricted ?? accessHint(first, access)}</Tooltip>
{@render pen()}
</div>
@@ -662,7 +662,9 @@
<div class="flex flex-col gap-1">
{#each leftOut as w (w.id)}
<div class="flex items-center justify-between gap-2">
<span class="text-xs text-emphasis truncate">{w.name}</span>
{#if !one}
<span class="text-xs font-semibold text-emphasis truncate">{w.name}</span>
{/if}
<div class="flex shrink-0 gap-1">
<Button
variant="default"