fix: filter script and flow path listings by token path scope

Draft
RU
4d ago
+104-2

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.