Skip to content

fix: apply token path scope to apps that depend on a runnable - #12828

Draft
rubenfiszel wants to merge 2 commits into
mainfrom
ruben/win-2882-apply-token-path-scope-to-apps
Draft

rubenfiszel wants to merge 2 commits into
mainfrom
ruben/win-2882-apply-token-path-scope-to-apps

Conversation

@rubenfiszel

@rubenfiszel rubenfiszel commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

GET /api/w/{workspace}/apps/list_paths_from_workspace_runnable/{runnable_kind}/{path} returned the paths of every app that depends on a script or flow without applying the token's path scope. A token restricted with apps:read:<prefix> received app paths outside that prefix, even though apps/get for those paths returns 403. RLS still limited results to apps the token owner can read, so only out-of-scope paths leaked.

Changes

  • list_paths_from_workspace_runnable (backend/windmill-api/src/apps.rs) filters its rows through build_scope_path_predicate(&authed, "apps", "read"), as list_search_apps already does. Unscoped tokens and sessions are unaffected. The endpoint is not paginated, so filtering after the fetch reveals nothing through page sizes.
  • Regression test backend/tests/app_runnable_paths_scope.rs: an unscoped token sees both dependent apps, an apps:read:u/test-user/* token sees only the one in scope. It fails without the fix.

Out of scope, noted for follow-up: the scripts and flows variants of list_paths_from_workspace_runnable (and list_paths_linking_agent) don't filter their returned paths by the token's path scope either.

Test plan

  • cargo test --features quickjs --test app_runnable_paths_scope passes, and fails with the handler change reverted
  • On the running dev instance: two apps depending on u/admin/s in f/allowed and f/other; an unscoped token gets ["f/allowed/app1","f/other/app2"], an apps:read:f/allowed/* token gets ["f/allowed/app1"]

Left in draft: touches a token-scope (auth) path, wants a human look before ready.

🤖 Generated with Claude Code


Summary by cubic

Fixes GET /apps/list_paths_from_workspace_runnable so tokens restricted with apps:read:<prefix> no longer receive app paths outside that prefix. Previously the endpoint returned out-of-scope paths even though apps/get on the same paths returns 403; RLS still limited results to apps the token owner can read.

  • Filters returned rows through build_scope_path_predicate, matching what list_search_apps already does.
  • Adds a regression test covering both an unscoped token (sees all dependent apps) and an apps:read:u/test-user/* token (sees only in-scope apps).
  • The scripts and flows variants of this endpoint, and list_paths_linking_agent, still don't filter by token path scope; noted for follow-up.

Written for commit 99f95b5. Summary will update on new commits.

View guided diff Turn on auto-fix

rubenfiszel and others added 2 commits December 3, 2026 00:09
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rubenfiszel

Copy link
Copy Markdown
Contributor Author

/review

@claude

claude Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @rubenfiszel's task in 22s —— View job


Good to merge

Summary

list_paths_from_workspace_runnable in backend/windmill-api/src/apps.rs:2912 now filters its rows through build_scope_path_predicate(&authed, "apps", "read"). That is the same predicate list_search_apps and the other apps listings already use (apps.rs:664, apps.rs:860).

  • Correctness: the predicate uses the same rule as check_scopes to decide whether a token is scoped. Tokens with no scopes, and tokens whose only scopes are if_jobs:filter_tags: ones, still pass everything, so sessions and unscoped tokens behave as before. An unparseable scope still counts as a restriction and matches nothing, which fails closed.
  • No leak through paging: the endpoint is not paginated, so filtering after the fetch cannot reveal anything through page sizes. RLS still applies first.
  • No new public surface: the change adds no pub fn, endpoint or schema change, so the public-surface checklist doesn't apply.

Findings

None blocking.

The scripts and flows variants of this endpoint, and list_paths_linking_agent, still return paths without applying the token's path scope. That gap is already there before this PR and the description notes it as a follow-up, so it isn't a finding here.

AGENTS.md compliance

  • The test is minimal and pins the regression: two dependent apps, one unscoped token and one apps:read:u/test-user/* token. That follows "Ship only the tests the PR needs".
  • The module doc comment states a lasting constraint: the route layer checks only the scope domain and RLS doesn't know about token scopes. That is the kind of comment "Comments record constraints, not narration" allows.

Test coverage

  • Backend: the integration test backend/tests/app_runnable_paths_scope.rs covers the scoped and unscoped cases against a real ApiServer. That is enough for a one-line handler filter, and no unit test is needed.
  • Manual check: the PR's test plan already covers it. On a dev instance, two apps depending on the same script under different folders both come back for an unscoped token, and only the in-scope one comes back for an apps:read:<folder>/* token. The change has no UI surface beyond this response.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Codex Review

Good to merge

No issues found. The handler applies the existing app-read scope predicate to every returned path while preserving RLS and unscoped-token behavior. The endpoint has no pagination, so filtering the fetched results is appropriate.

Test coverage

The focused API integration test covers both scoped and unscoped tokens against two dependent apps. That sufficiently guards this handler-only change; no new predicate logic needs unit tests.

I did not run tests. The PR reports the integration test passes and fails when the fix is reverted.

The PR also reports live verification: requesting /api/w/{workspace}/apps/list_paths_from_workspace_runnable/script/u/admin/s returns both dependent apps with an unscoped token and only f/allowed/app1 with apps:read:f/allowed/*. No further manual verification is needed for this focused fix.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying windmill with  Cloudflare Pages  Cloudflare Pages

Latest commit: 99f95b5
Status: ✅  Deploy successful!
Preview URL: https://b30532d8.windmill.pages.dev
Branch Preview URL: https://ruben-win-2882-apply-token-p.windmill.pages.dev

View logs

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Pi Review

Good to merge

Summary

list_paths_from_workspace_runnable (backend/windmill-api/src/apps.rs:2893) now filters its result rows through build_scope_path_predicate(&authed, "apps", "read") (lines 2912–2913), the same predicate list_search_apps (line 664) and list_apps (line 860) already use. The endpoint returns JsonResult<Vec<String>> with no pagination, so post-fetch filtering cannot leak anything through page sizes or cursors. The change adds no pub fn, endpoint, or schema change, so the public-surface checklist does not apply.

I verified the predicate semantics in build_scope_path_predicate (windmill-api-auth/src/lib.rs:822) and scope_contains/resource_matches_pattern (windmill-common/src/scopes.rs): unscoped tokens and tokens whose only scopes are if_jobs:filter_tags: still pass everything; apps:write:<path> correctly subsumes read; an unparseable scope still marks the token as restricted and matches nothing (fails closed). All consistent with check_scopes.

The regression test (backend/tests/app_runnable_paths_scope.rs) is valid: both tokens are owned by test@windmill.dev (a workspace admin), so RLS (windmill_admin role has BYPASSRLS) lets both read both apps, and only the scope filter distinguishes the results. apps:read:u/test-user/* matches u/test-user/a but not u/test-user-2/b (the / boundary check in resource_matches_pattern), so the assertions pin exactly the behavior being fixed. The omitted runnable_is_agent and flow_path/script_hash columns are nullable or defaulted, and summary/extra_perms have defaults, so the inserts are complete.

Considered and dismissed

  • Missing check_scopes(&authed, || "apps:read") like list_search_apps — the endpoint doesn't do a handler-level domain check, so an apps:run-only embed token can still reach it. But scope_contains does not treat run as covering read, so the new predicate returns false for every path for such a token — it now receives an empty list instead of (previously) every app path. The fix is strictly fail-closed here; the remaining inconsistency (200-with-empty-list vs 403) is pre-existing and not a leak.
  • Post-fetch filtering instead of a SQL WHERE — build_scope_path_filter documents SQL-side filtering as mandatory only "wherever the result is paginated". This endpoint fetches everything into a Vec<String> and returns it unpaginated, so in-memory retain is safe and matches list_apps.
  • Filtering after tx.commit() — the filter operates on an already-fetched in-memory Vec, so the commit ordering is irrelevant.
  • Doc comment accuracy ("the route layer only checks the scope domain…") — accurate: route-level access is enforced by check_scopes_for_route/check_route_access against the apps domain, and RLS policies on app know nothing of token scopes. The comment states a durable constraint, not narration.
  • Test hardcoded IDs / fixtures — ids 999801/999802 are arbitrary and don't collide with the base fixture; sqlx::query (runtime, not query!) avoids the compile-time .sqlx cache. The assert_eq!(..., "list: {}", resp.text().await?) message arg is only evaluated on failure, so the body isn't consumed before resp.json().

Test coverage

  • Backend: the new integration test backend/tests/app_runnable_paths_scope.rs covers the scoped and unscoped cases against a real ApiServer. That is sufficient for a one-line handler filter — no unit test is needed, and it follows the "ship only the tests the PR needs" rule.

The PR's test plan already describes the manual verification (two apps depending on one script in different folders, unscoped vs apps:read:f/allowed/* token), and the change has no UI surface beyond the response of this endpoint. No additional manual verification is required beyond running cargo test --features quickjs --test app_runnable_paths_scope.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant