Skip to content

security(llc): legacy workflow delete/patch has a TOCTOU — a concurrent role assignment lets a member delete a Company OS row (#18444 follow-up) #18446

Description

@mrveiss

Follow-up from the Opus delta review of #18444 (the Company OS model) at 2adf01f.

Race (TOCTOU). The legacy PATCH/DELETE /llc/workflows/{company_id}/{workflow_id} (autobot-backend/llc/api/workflows.py:207-215) load the row without a lock and dispatch on whether it is a Company OS row. The legacy write predicate (llc/services/workflow.py:199-216) is only workflow_id + company_id. An admin can turn a plain workflow into a Company OS one through CompanyOsWorkflowService.update → _move_to_role. If that commits between a member's load and the member's write:

  • the member's legacy DELETE removes the newly role-owned row, and its nodes and transitions cascade away;
  • if the row is referenced, the delete fails on RESTRICT as a 500, not a 409.

The window needs a concurrent admin action, so it is narrow.

Acceptance criteria

  • The legacy DELETE and status UPDATE predicates add Workflow.kind == 'workflow' and Workflow.owner_role_id.is_(None). On rowcount 0 they re-dispatch to CompanyOsWorkflowService (or return 409), never delete a Company OS row.
  • A test interleaves an admin _move_to_role between a member's load and write, and the member's write does not touch the now-owned row.
  • The 403 PATCH test also asserts the status is unchanged (llc/tests/test_company_os_api.py:~425).

Refs #18390

Activity

  1. mrveiss commented on Oct 13, 2026

    @mrveiss
    OwnerAuthor

    Acceptance-criteria evidence against main at 7bbdacf (merge train #18519).

    • Legacy predicates: llc/services/workflow.py _legacy_row (lines 59-69) returns workflow_id, company_id, Workflow.kind == "workflow", Workflow.owner_role_id.is_(None); used by both update_status (sa_update ... .where(*_legacy_row(...)), rowcount == 0 returns None) and delete (sa_delete ... .where(*_legacy_row(...))). On no match the routes re-dispatch: api/workflows.py PATCH falls to _company_os_status(...); DELETE does if not deleted and await _is_company_os(...) then _company_os().delete(...), mapping CompanyOsError/NotAuthorisedError via http_error.
    • Interleaving test: llc/tests/test_company_os_api.py test_a_move_landing_between_the_read_and_the_write_is_still_refused (parametrized delete/patch, ~line 495) wraps the legacy write so an admin _move_to_role commits first, then asserts the member gets 403 and the row still has owner_role_id == sales and status == "planned".
    • 403 PATCH test asserts status unchanged: test_legacy_routes_enforce_the_admin_gate_on_company_os_rows (~line 425-440) ends with rows["sales-wf"]["status"] == rows["meta"]["status"] == "planned", message "a refused PATCH must not write".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions