fix: resolve a viewer app's undeclared runnable with the caller's rls
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: newrunnable_ref_to_payload_with_rls, which takes anOption<UserDbWithAuthed>and hands it toscript_path_to_payload/get_latest_flow_version_info_for_path.runnable_ref_to_payloadkeeps its signature and delegates withNone, 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, buildUserDbWithAuthedfrom the handler's existinguser_dband the caller, as the/jobs/run/phandlers do.backend/tests/app_viewer_named_path_rls.rs: an operator calling an undeclaredscript/f/restricted/xandflow/f/restricted/flthrough 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_rlspasses; with the user DB dropped (passingNone) 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…/xnow returns 401 (same message as/jobs/run/p), a readablef/shared…/xqueues 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.