From 8e57691cbcf1db8af4c9994d8f9486bcb0c8abd8 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Mon, 2 Nov 2026 08:22:30 +0100 Subject: [PATCH] fix: let scoped tokens reach shared_ui routes through the apps scope (#12141) Co-authored-by: Claude Opus 5.5 --- backend/windmill-api-auth/src/scopes.rs | 13 +++++++++++++ backend/windmill-api/src/workspace_shared_ui.rs | 4 ++++ backend/windmill-common/src/scopes.rs | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/backend/windmill-api-auth/src/scopes.rs b/backend/windmill-api-auth/src/scopes.rs index bdbab1bfe7..b5f082a6b4 100644 --- a/backend/windmill-api-auth/src/scopes.rs +++ b/backend/windmill-api-auth/src/scopes.rs @@ -1473,6 +1473,19 @@ mod tests { ); } + #[test] + fn test_shared_ui_routes_use_apps_scopes() { + let scopes = |s: &[&str]| s.iter().map(|s| s.to_string()).collect::>(); + for route in ["shared_ui/get", "shared_ui/list", "shared_ui/version"] { + let route = format!("/api/w/ws/{route}"); + assert!(check_route_access(&scopes(&["apps:read"]), &route, "GET").is_ok()); + assert!(check_route_access(&scopes(&["scripts:read"]), &route, "GET").is_err()); + } + let put = "/api/w/ws/shared_ui"; + assert!(check_route_access(&scopes(&["apps:write"]), put, "PUT").is_ok()); + assert!(check_route_access(&scopes(&["apps:read"]), put, "PUT").is_err()); + } + #[test] fn test_flow_conversations_scope_access() { let read_scopes = vec!["flow_conversations:read".to_string()]; diff --git a/backend/windmill-api/src/workspace_shared_ui.rs b/backend/windmill-api/src/workspace_shared_ui.rs index 810ea3420f..6df4ff6ddb 100644 --- a/backend/windmill-api/src/workspace_shared_ui.rs +++ b/backend/windmill-api/src/workspace_shared_ui.rs @@ -7,6 +7,7 @@ */ use crate::db::{ApiAuthed, DB}; +use crate::utils::check_scopes; use axum::{ extract::{Extension, Json, Path}, routing::{get, put}, @@ -152,6 +153,9 @@ async fn update_shared_ui( Json(payload): Json, ) -> Result { require_admin(authed.is_admin, &authed.username)?; + // The route layer matches `apps:write:` too; the store is workspace-wide, so + // only a grant spanning every app path may replace it. + check_scopes(&authed, || "apps:write".to_string())?; let files_json = serde_json::to_value(&payload.files) .map_err(|e| Error::internal_err(format!("serializing files: {e}")))?; diff --git a/backend/windmill-common/src/scopes.rs b/backend/windmill-common/src/scopes.rs index 2f58485896..bf10e07e59 100644 --- a/backend/windmill-common/src/scopes.rs +++ b/backend/windmill-common/src/scopes.rs @@ -381,7 +381,9 @@ impl ScopeDomain { "data_metrics" => Some(Self::DataMetrics), "flows" => Some(Self::Flows), "flow_conversations" => Some(Self::FlowConversations), - "apps" | "apps_u" => Some(Self::Apps), + // `shared_ui` is the workspace `ui/` folder raw apps import from, so a token + // that syncs apps reaches it without a scope of its own. + "apps" | "apps_u" | "shared_ui" => Some(Self::Apps), "variables" => Some(Self::Variables), "resources" => Some(Self::Resources), "schedules" => Some(Self::Schedules),