Skip to content

fix: resolve a viewer app's undeclared runnable with the caller's rls - #12877

Draft
rubenfiszel wants to merge 1 commit into
mainfrom
ruben/win-2889-resolve-caller-named-runnables-in-viewer-mode
Draft

rubenfiszel wants to merge 1 commit into
mainfrom
ruben/win-2889-resolve-caller-named-runnables-in-viewer-mode

Conversation

@rubenfiszel

@rubenfiszel rubenfiszel commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In a Viewer-mode app, POST /api/w/{w}/apps_u/execute_component/{app} accepts a script/<path> or flow/<path> that the app's policy does not declare, and runs it as the caller. The runnable was looked up through the root database handle, so row-level security never applied: any member who could open one Viewer app (an operator, or a token scoped to apps:run:<app>) could run, and read the results of, scripts and flows they have no read access to (other users' u/ paths, folders they are not in). /jobs/run/p already refuses these.

The handler now resolves a caller-named path (caller_named_path: an undeclared path in a Viewer app, or any path in editor preview) through the caller's user DB, so a path the caller cannot read is refused exactly as /jobs/run/p refuses it (401 "not authorized to access this script/flow"). Policy-declared runnables keep resolving through the root DB (RunOrigin::Deployed): the publisher vouched for them at deploy time.

Changes

  • windmill-common/src/jobs.rs: new runnable_ref_to_payload_with_rls, which takes an Option<UserDbWithAuthed> and hands it to script_path_to_payload / get_latest_flow_version_info_for_path. runnable_ref_to_payload keeps its signature and delegates with None, so the deployed-handler callers (error/success/recovery handlers, including the EE ones, variable expiration, post-fork script) are untouched and no EE companion PR is needed.
  • windmill-api/src/apps.rs (execute_component): when the caller named the path, build UserDbWithAuthed from the handler's existing user_db and the caller, as the /jobs/run/p handlers do.
  • backend/tests/app_viewer_named_path_rls.rs: an operator calling an undeclared script/f/restricted/x and flow/f/restricted/fl through a Viewer app gets a 401; the same operator still runs a script and a flow in a folder they can read.

Behaviour note: editor preview also takes the caller-named branch, so a non-admin co-editor previewing a component that references a script they cannot read now gets the same refusal they would get from /jobs/run/p. Admins are unaffected (RLS bypass).

Test plan

  • cargo test --features quickjs --test app_viewer_named_path_rls passes; with the user DB dropped (passing None) it fails at the restricted script.
  • Neighbouring suites pass: hub_named_path, app_preview_auth, app_guest_execution_mode, app_anonymous_execution_mode, app_publisher_permit, app_ctx_inputs, app_run_mode_lock_strip, end_user_email, reserved_control_args.
  • Live instance: with an operator token, a Viewer app's undeclared script/f/restricted…/x now returns 401 (same message as /jobs/run/p), a readable f/shared…/x queues a job (200), and an admin still runs the restricted path through the app.

Left in draft: changes an authorization path, wants a human look before ready.

🤖 Generated with Claude Code


Summary by cubic

Fixes a privilege-escalation hole in Viewer-mode apps: an undeclared script/<path> or flow/<path> was resolved through the root database, so row-level security never applied and any operator (or token scoped to apps:run:<app>) could run, and read the results of, scripts and flows they have no read access to. Caller-named paths now resolve through the caller's user DB, so a path the caller cannot read is refused exactly as /jobs/run/p refuses it (401 "not authorized to access this script/flow").

  • Policy-declared runnables keep resolving through the root DB; the publisher vouched for them at deploy time.
  • Editor preview takes the caller-named branch, so a non-admin co-editor previewing an unreadable script gets the same refusal; admins are unaffected.

Written for commit dce4c8e. 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 5, 2026 •

Copy link
Copy Markdown

Deploying windmill with  Cloudflare Pages  Cloudflare Pages

Latest commit: dce4c8e
Status: ✅  Deploy successful!
Preview URL: https://e0bb6414.windmill.pages.dev
Branch Preview URL: https://ruben-win-2889-resolve-calle.windmill.pages.dev

View logs

@rubenfiszel

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

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


Good to merge

Review summary

I found no blocking issues and no nits worth raising. The fix is small and does what the description says: when the caller named the runnable, execute_component now looks it up through the caller's RLS, and declared runnables still go through the root DB as before.

What I checked

  • Script path: script_path_to_payload → get_latest_deployed_hash_for_path (windmill-common/src/lib.rs:2980-2999). With db_authed set, it runs a SELECT EXISTS … FROM script WHERE hash = $1 through the caller's user DB, and refuses with the same NotAuthorized "not authorized to access this script" error /jobs/run/p gives. The DEPLOYED_SCRIPT_HASH_CACHE short-circuit does not skip this check, because the check runs after the hash is resolved. HASH_PERMS_CACHE is keyed on the authed hash, so one caller's grant does not carry over to another caller.
  • Flow path: get_latest_flow_version_id_for_path (lib.rs:3346-3383). It only uses FLOW_VERSION_CACHE when FLOW_PERMS_CACHE already holds a grant for this caller. Otherwise it reads through the user DB and returns the same 401 when the row exists but the caller can't see it.
  • Hub paths: no change. They still go through check_can_name_runnable with RunOrigin::NamedBy, and db_authed is never used on the hub branches.
  • Branch selection (apps.rs:5428-5446): db_authed is only Some when caller_named_path is true and the caller is authenticated (anonymous callers were already refused there). The Deployed origin always gets None. caller_named_path is set in exactly two places: is_preview (:4911) and the Viewer fallback in .or_else (:5190). Inline raw_code is excluded from the fallback, so this change can't reach it.
  • Identity: opt_authed here comes after guest_caller_for_mode, so RLS applies to the same identity the job later runs as. That matches RunOrigin::NamedBy(viewer).
  • API shape: runnable_ref_to_payload keeps its signature and delegates with None, so the deployed-handler and EE callers don't change. The new pub fn documents its RLS contract, it's placed in jobs.rs next to its siblings, and it isn't half-finished.

Behaviour change worth knowing (not a defect)

A Viewer app that calls a script//flow/ path missing from triggerables_v2, where the viewer has no read access, will now fail with a 401 instead of running. Usually such paths come from an app edited after deploy, or from a hand-crafted request. That is the intended fix, but anyone who sees a new 401 on a Viewer app after upgrading should look here first. The editor-preview change for non-admin co-editors is already called out in the PR body.

AGENTS.md compliance

I found no violations. The change stays inside the touched modules, the comments explain why the branch exists rather than restating the code, and no EE companion change is needed.

Test coverage

This is a backend change, and the new integration test backend/tests/app_viewer_named_path_rls.rs covers the handler change in both directions:

  • An operator naming an undeclared script/f/restricted/x or flow/f/restricted/fl gets a 401 with "not authorized to access".
  • The same operator can still run the script and the flow under f/shared (read via extra_perms).

The test doesn't cover the editor-preview path or the declared-runnable path (which should still resolve with the root DB). Existing suites (app_preview_auth, app_publisher_permit, etc.) cover those, and the PR says they pass. I did not re-run any tests here.

Manual check: the author already ran it on a live instance. One more check worth doing before merge: open an existing Viewer app as a non-admin member, where every component references a runnable declared in its deployed policy, including some the member can't read directly. Every component should still run. A 401 there would mean the declared path wrongly went through caller_named_path.

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Codex Review

Good to merge

Test coverage

The new API integration test covers denied and permitted undeclared paths for both scripts and flows as an operator. It does not cover editor preview, app-scoped tokens, or preservation of policy-declared access.

I did not rerun the Rust tests or live checks because the configured Postgres was unavailable. The passing suites and live results in the PR description are author-reported.

Manually preview a component as a non-admin co-editor: unreadable script and flow paths should return 401, while readable paths should queue successfully. Also confirm a deployed app can still run a policy-declared runnable the viewer cannot read directly.

@rubenfiszel

Copy link
Copy Markdown
Contributor Author

/pi

@rubenfiszel

Copy link
Copy Markdown
Contributor Author

/review

@rubenfiszel

Copy link
Copy Markdown
Contributor Author

✅ Review round clean @ dce4c8e — Codex and Claude: Good to merge; Pi ran twice but produced an empty final message (no verdict). Left in draft: changes an authorization path, wants a human look before ready.

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