You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
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
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).
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.pytest_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".
Activity
fix(company-os): legacy writes carry the plain-workflow predicate and…
mrveiss commentedon Oct 13, 2026
Acceptance-criteria evidence against
mainat 7bbdacf (merge train #18519).llc/services/workflow.py_legacy_row(lines 59-69) returnsworkflow_id,company_id,Workflow.kind == "workflow",Workflow.owner_role_id.is_(None); used by bothupdate_status(sa_update ... .where(*_legacy_row(...)),rowcount == 0returns None) anddelete(sa_delete ... .where(*_legacy_row(...))). On no match the routes re-dispatch:api/workflows.pyPATCH falls to_company_os_status(...); DELETE doesif not deleted and await _is_company_os(...)then_company_os().delete(...), mappingCompanyOsError/NotAuthorisedErrorviahttp_error.llc/tests/test_company_os_api.pytest_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_rolecommits first, then asserts the member gets 403 and the row still hasowner_role_id == salesandstatus == "planned".test_legacy_routes_enforce_the_admin_gate_on_company_os_rows(~line 425-440) ends withrows["sales-wf"]["status"] == rows["meta"]["status"] == "planned", message "a refused PATCH must not write".