Skip to content

fix(actions): gate execute_script nodes behind a global trust level (WI-2360) - #564

Closed
stefan-ernst wants to merge 1 commit into
mainfrom
fix/wi-2360-execute-script-trust
Closed

stefan-ernst wants to merge 1 commit into
mainfrom
fix/wi-2360-execute-script-trust

Conversation

@stefan-ernst

Copy link
Copy Markdown
Contributor

Problem

execute_script runs author-supplied JavaScript in Sobek inside the API
process
. CPU is bounded (vm.Interrupt, 30 s cap) and source is capped at
10 KB, but nothing bounds allocation. Any holder of action.manage — and, per
the item's follow-up, every authenticated user in their personal workspace —
could save and trigger an action that allocates without bound and drive the
whole instance into the debug.SetMemoryLimit GC death spiral. Availability
impact across tenants.

Fix (item option 2)

Process isolation (option 1) is a larger worker design. This PR takes the
item's sanctioned interim path: stop treating action.manage as sufficient
for executable nodes.

  • Adds the global action.execute_script permission (system admins hold it
    implicitly; it is not granted to workspace roles).
  • Saving/creating a graph that contains an execute_script node now requires
    it, in addition to action.manage. Metadata-only edits that leave the graph
    untouched stay available to action managers.
  • Manually running an action that contains an execute_script node requires
    it as well.
  • Denials reuse the existing access-denied audit row with
    required_permission = action.execute_script.
  • Compiled-in action templates must not ship execute_script nodes (the
    applier cannot hold a per-user trust level); ApplyToWorkspace refuses them.
  • Surfaces the restriction in the execute_script catalog description (UI and
    the v2 OpenAPI catalog), the script config panel (warning for users without
    the permission), the admin permission list, and the operator-controls README.

Enforcement is centralised in ActionDefinitionService (injected
PermissionService), so v1, v2, and the AI/MCP tool paths are all covered.
Triggered executions of already-saved definitions keep running; the README
tells operators to remove or rewrite them before revoking the permission.

Acceptance criteria

1–3 (isolation, RSS bound, other tenants unaffected, budgets in an isolated
runtime): not addressed — they require option 1, which this item lists as
the preferred but larger design. They remain the follow-up.
4 (denial coverage for save and execute): met and tested.
5 (REST bridge semantics unchanged): met — no bridge, scope, redirect, or path
logic changed; the executor and dispatcher are untouched.

Testing

  • New white-box coverage in the companion core-tests PR
    (Windshiftapp/core-tests-internal#72): create/update denial + audit,
    metadata-only edit allowed, manual-execute denial + audit, template refusal.
  • Existing suites:
./overlay.sh ../core-wi-2360 -- -tags=test -count=1 ./internal/services/ ./internal/aitools/ ./internal/restapi/v2/ ./internal/restapi/v1/handlers/ ./internal/database/

services, aitools, restapi/v2, restapi/v1/handlers, and database all
passed. golangci-lint, make openapi-v2-check, and the frontend
npm run check / svelte-check pass.

Note: the black-box ./tests/ package does not compile on origin/main
because tests/request_type_available_fields_test.go references
StartIsolatedTestServer, which is not defined in the committed tree. That is
pre-existing and unrelated; it was not run.

Schema

Adds 20261204_action_execute_script_permission so existing databases receive
the new permission row; fresh installs get it from permissions.sql.

…WI-2360)

Sobek runs action scripts in-process without a per-script heap bound, so
action.manage alone let any authenticated user (including a self-registered
one in a personal workspace) save and run an unbounded allocation that drove
the whole process into the memory-limit GC death spiral.

Add the global action.execute_script permission and require it, in addition to
action.manage, to persist a graph containing an execute_script node or to
manually run an action that has one. Metadata-only edits that leave the graph
untouched stay available to action managers, and triggered executions keep
running existing definitions. Denials write the existing access-denied audit
row with the required permission.

Compiled-in action templates must not ship execute_script nodes, since an
applier cannot hold the per-user trust level; ApplyToWorkspace now refuses
them.

Surface the restriction in the execute_script catalog description (UI and v2
OpenAPI catalog), the script config panel, the admin permission list, and the
operator-controls README. Process isolation remains the prerequisite before
accepting untrusted authors; this is the interim trust gate from the item.
@github-actions

Copy link
Copy Markdown

Size Change: 0 B 🆕

Total Size: 0 B

compressed-size-action

@stefan-ernst

Copy link
Copy Markdown
Contributor Author

Closing: this implements the item's interim option 2 (global trust gate), which is a product regression rather than the intended fix. Replacing it with option 1: a memory-bounded worker process.

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