Skip to content

fix: filter script and flow path listings by token path scope - #12801

Draft
rubenfiszel wants to merge 1 commit into
mainfrom
ruben/win-2861-fixauth-filter-scriptflow-list_paths-and
Draft

rubenfiszel wants to merge 1 commit into
mainfrom
ruben/win-2861-fixauth-filter-scriptflow-list_paths-and

Conversation

@rubenfiszel

@rubenfiszel rubenfiszel commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A token whose scopes restrict it to a path (e.g. scripts:read:f/allowed/*) could call GET /w/{w}/scripts/list_paths, GET /w/{w}/scripts/list_dedicated_with_deps and GET /w/{w}/flows/list_paths and receive every path in the workspace (and, for dedicated scripts, their language and workspace dependency names), including paths outside its scope. The main list endpoints and list_search_scripts already filter by token path scope; these three did not.

Fixes WIN-2861.

Changes

  • scripts/list_paths and scripts/list_dedicated_with_deps: filter fetched rows with build_scope_path_predicate(&authed, "scripts", "read").
  • flows/list_paths: filter with build_scope_path_predicate(&authed, "flows", "read").
  • Filtering happens after the fetch, like the existing list handlers. None of these endpoints paginate, so the post-fetch filter leaks no counts (the ScopePathFilter SQL requirement applies to paginated listings only).
  • Unscoped tokens, and tokens with only if_jobs:filter_tags: scopes, are unaffected.
  • New regression test backend/tests/list_paths_scope.rs.

Test plan

  • cargo test --test list_paths_scope passes; it fails on the unfixed handlers (scoped token got ["f/allowed/a", "f/other/b"]).
  • On the running dev instance, a token created via /users/tokens/create with scopes scripts:read:f/allowed/* and flows:read:f/allowed/* now gets only f/allowed/a from all three endpoints (same as scripts/list / flows/list). An unscoped token still gets every path.

Follow-up (not in this PR)

list_paths_from_workspace_runnable (scripts and flows) and flows/list_paths_linking_agent return importer/linking paths without filtering them by the token's path scope. That is a similar but separate gap.

Left in draft: touches an auth/token-scope path, so it wants a human look before ready.

🤖 Generated with Claude Code


Summary by cubic

Fixes three path-listing endpoints so a token scoped to a path only sees scripts and flows under that path, instead of every path in the workspace.

  • scripts/list_paths, scripts/list_dedicated_with_deps, and flows/list_paths now filter fetched rows through build_scope_path_predicate with the corresponding resource and read action.
  • Filtering happens after the fetch because none of these endpoints paginate, so no counts leak; this mirrors the existing list handlers.
  • Unscoped tokens, and tokens with only if_jobs:filter_tags: scopes, are unaffected.
  • Adds a regression test (backend/tests/list_paths_scope.rs) covering scoped and unscoped tokens on all three endpoints.
  • Follow-up: list_paths_from_workspace_runnable and flows/list_paths_linking_agent still return importer/linking paths without path-scope filtering, which is a similar but separate gap.

Written for commit fb533a8. Summary will update on new commits.

View guided diff Turn on auto-fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Deploying windmill with  Cloudflare Pages  Cloudflare Pages

Latest commit: fb533a8
Status: ✅  Deploy successful!
Preview URL: https://85cb057f.windmill.pages.dev
Branch Preview URL: https://ruben-win-2861-fixauth-filte.windmill.pages.dev

View logs

@rubenfiszel

Copy link
Copy Markdown
Contributor Author

/review

@claude

claude Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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


Good to merge

Review

  • Read AGENTS.md / review policy
  • Read the diff (git diff origin/main...HEAD)
  • Checked the handlers, build_scope_path_predicate, callers, and the test fixture

What I checked

  • Correctness of the filter. All three handlers now use build_scope_path_predicate, the same predicate the sibling list handlers already use (scripts.rs:173, scripts.rs:363, flows.rs:119, flows.rs:244). The predicate returns true for unscoped tokens and for tokens whose only scopes are if_jobs:filter_tags:, so existing callers see no change.
  • Domain and action. The handlers use scripts/read for both script endpoints and flows/read for flows, which matches the main list endpoints.
  • Count leak. None of the three endpoints paginates, so filtering after the fetch exposes nothing through page sizes or counts. A post-fetch filter is fine here.
  • list_dedicated_with_deps callers. Its only caller is DedicatedWorkersSelector.svelte. No worker or agent path calls it with a scoped token, so filtering cannot break dedicated-worker startup.
  • Test. SECRET_TOKEN in fixtures/base.sql is the unscoped super-admin token, so it is a valid control. paths() handles both the Vec<String> and the {path,…} response shapes, because Value::get("path") on a string returns None and falls back to the string itself. This is the first test in backend/tests for token path scopes, so a new file makes sense rather than appending to an unrelated one. Under the AGENTS.md rule "Ship only the tests the PR needs", it is a minimal regression guard that pins the leak.

Findings

No P0, P1 or P2 findings.

The follow-up named in the PR description is real and correctly kept out of scope: list_paths_from_workspace_runnable (scripts and flows) and flows/list_paths_linking_agent don't filter by path scope.

AGENTS.md compliance

The changes are small and focused, add no comments that narrate the change, and follow the existing pattern. No migrations, sqlx query changes or OpenAPI changes are needed, because the query text and response shapes are unchanged.

Test coverage

Backend: the new integration test backend/tests/list_paths_scope.rs covers all three endpoints, with both a scoped token and an unscoped token as the control. The author reports it fails on the unfixed handlers. Nothing else is needed.

Manual verification: the PR description already covers it. A token created through /users/tokens/create with scripts:read:f/allowed/* and flows:read:f/allowed/* gets only f/allowed/a from all three endpoints, and an unscoped token still gets every path. Beyond that, open the dedicated-workers selector in workspace settings as a normal (unscoped) session and confirm it still lists every dedicated script with its dependency names.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Codex Review

Good to merge

No P0/P1/P2 findings. All three handlers apply the existing predicate with the correct resource and read action. Existing workspace/RLS enforcement remains intact, and these unpaginated responses expose no unfiltered counts.

Test coverage

The new Rust integration test covers all three API/DB paths with scoped and unscoped tokens. Existing predicate unit tests cover exact paths, wildcards, unscoped tokens and filter-tags-only scopes; no new predicate logic needs unit coverage.

The author reports the regression test passes and fails against the unfixed handlers. My cargo test --test list_paths_scope --locked attempt failed before project compilation because the configured mold linker is unavailable. I did not independently exercise the endpoints.

The PR reports manual verification using tokens created through /users/tokens/create: scopes scripts:read:f/allowed/* and flows:read:f/allowed/* return only f/allowed/a from the three changed endpoints, while an unscoped token returns every path.

Remaining manual check: open the dedicated-workers selector in workspace settings with a normal unscoped session. Confirm all eligible dedicated scripts remain listed with their workspace dependency names.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Pi Review

Good to merge

The three handlers now filter through build_scope_path_predicate with the correct (domain, action) pairs, matching the sibling list/list_search_scripts handlers exactly, and none of the three endpoints paginates, so the post-fetch filter cannot leak row counts. The regression test is minimal and pins the leak. No findings introduced by this diff.

Note (pre-existing, not in this diff): backend/windmill-api/src/path_autocomplete.rs (GET /w/{workspace}/path_autocomplete/list_paths) has the same gap — it lists scripts/flows/apps/raw_apps/variables/resources paths under RLS only, with no token path-scope filter, so a scoped token can still enumerate every path in the workspace. The PR body's "Follow-up" list names list_paths_from_workspace_runnable and flows/list_paths_linking_agent but omits this one. Not a blocker for this PR; worth adding to the follow-up list so it doesn't get lost.

Considered and dismissed

  • Count leak via post-fetch filtering — dismissed: scripts/list_paths and flows/list_paths return JsonResult<Vec<String>> and list_dedicated_with_deps returns JsonResult<Vec<DedicatedScriptDeps>>; none applies LIMIT/OFFSET/cursor, so filtering after the fetch leaks nothing.
  • Wrong domain/action — dismissed: scripts/read (×2) and flows/read match the existing handlers at scripts.rs:173,363 and flows.rs:119,244.
  • Breaking dedicated-worker startup for a scoped token — dismissed: the only caller of list_dedicated_with_deps is DedicatedWorkersSelector.svelte, which swallows errors (catch(() => [])) and is only rendered for devops/unscoped sessions; the cross-workspace list_all_dedicated_with_deps in windmill-api-configs is untouched.
  • Unscoped or whole-domain tokens wrongly filtered — dismissed: build_scope_path_predicate returns true when authed.scopes is None/filter_tags-only, and ScopeDefinition::includes returns (None, _) => true, so a bare scripts:read grant still sees every path.
  • Test fixture correctness — dismissed: the ^[ufg](\/[\w-]+){2,}$ path constraint (updated in 20221219051235_folders_2) accepts f/allowed/a/f/other/b; archived defaults to false; dedicated_worker and lock columns exist; SECRET_TOKEN is the unscoped superadmin control; the paths() helper handles both Vec<String> and {path,…} response shapes.
  • &String → &str coercion in .filter(|p| allowed(p)) — dismissed: identical to the already-compiling pattern at the four existing build_scope_path_predicate call sites.

Test coverage

Backend: the new backend/tests/list_paths_scope.rs integration test exercises all three endpoints with a scoped token and an unscoped control token, and is the smallest setup that pins the leak — appropriate per the "ship only the tests the PR needs" rule. No further automated tests required for this change.

Manual verification is already documented in the PR body and is sufficient: create a token via /users/tokens/create with scripts:read:f/allowed/* and flows:read:f/allowed/* and confirm it receives only f/allowed/a from all three endpoints while an unscoped token still receives both paths. One additional scenario worth a quick look: open the dedicated-workers selector in workspace settings as an unscoped admin and confirm it still lists every dedicated script with its dependency names, since list_dedicated_with_deps is its data source.

@rubenfiszel

Copy link
Copy Markdown
Contributor Author

✅ Review round clean @ fb533a8

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