fix: filter script and flow path listings by token path scope
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_pathsandscripts/list_dedicated_with_deps: filter fetched rows withbuild_scope_path_predicate(&authed, "scripts", "read").flows/list_paths: filter withbuild_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
ScopePathFilterSQL 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_scopepasses; 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/createwith scopesscripts:read:f/allowed/*andflows:read:f/allowed/*now gets onlyf/allowed/afrom all three endpoints (same asscripts/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, andflows/list_pathsnow filter fetched rows throughbuild_scope_path_predicatewith the corresponding resource andreadaction.- Filtering happens after the fetch because none of these endpoints paginate, so no counts leak; this mirrors the existing
listhandlers. - 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_runnableandflows/list_paths_linking_agentstill return importer/linking paths without path-scope filtering, which is a similar but separate gap.