Skip to content

fix(flow): isolate nested dictionary initial state - #9502

Open
HanYuanLu wants to merge 1 commit into
crewAIInc:mainfrom
HanYuanLu:fix/issue-9383
Open

HanYuanLu wants to merge 1 commit into
crewAIInc:mainfrom
HanYuanLu:fix/issue-9383

Conversation

@HanYuanLu

Copy link
Copy Markdown
Contributor

Related issue

Fixes #9383

Summary

Flow._create_initial_state copied a dict initial state with dict(init_state).
Nested containers stayed shared between Flow instances and the caller.
Deep-copy the dict, and fall back to a shallow copy when deep copy fails.

Verification

  • Tests added or updated for the changed behavior
  • Relevant tests and quality checks pass locally

uv run pytest lib/crewai/tests/test_flow.py::test_flow_initial_dict_state_isolates_nested_values -q --allowed-hosts=127.0.0.1

Additional context

None.

@strix-security

strix-security Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: Flow._create_initial_state now deep-copies a dict initial state instead of taking a shallow dict() copy, falling back to the shallow copy when a nested value cannot be deep-copied, so nested containers are no longer shared between Flow instances and the caller. A regression test covers the isolation.

Review summary

This PR changes how a dict initial_state is copied in Flow._create_initial_state: a copy.deepcopy replaces the previous shallow dict(init_state), with a dict() fallback when a nested value cannot be deep-copied, plus a regression test for nested-container isolation. The change is a correctness/ownership fix. Tracing every route that populates initial_state shows it is developer-supplied — either set on the Flow subclass or passed by the embedding application — while checkpoint and persistence payloads are JSON-serialized and rehydrated from JSON, so no attacker-controlled object reaches the new deepcopy. The narrow exception handler and its shallow-copy fallback were assessed as a reliability property rather than a security weakness, and the sibling declarative-state path (_create_definition_state) that still shallow-copies its default was examined too: its default is author-authored and no in-repo path serves multiple principals from one shared definition. No security vulnerability was confirmed in the changed code.

Suspected issues examined and rejected:

  • Flow construction now failing on deeply nested or non-deep-copyable initial state: input to this path is developer-controlled, and the same narrow handler already exists in _copy_state on the kickoff path, so the change crosses no attacker boundary.
  • The shallow-copy fallback leaving nested containers shared: it only fires for non-deep-copyable values the author placed in the state, pre-PR every nested container was shared, and both Flow instances live in the same trust domain.
  • Declarative state defaults still being shared across instances built from one definition: the default is authored by the flow developer, no in-repo path instantiates flows for distinct principals off a shared definition, and per-caller input enters only through the newly isolated initial_state path.
Ruled out (3)
  • Can deeply nested or non-deep-copyable initial state now make Flow construction fail where it never failed before?
    Everything that reaches this path is developer-supplied and the identical narrow exception handler already exists in _copy_state on the kickoff path, so no attacker controls the input that could raise RecursionError or copy.Error.
  • Does the shallow-copy fallback still share nested state between flows or with the caller?
    The fallback only triggers for non-deep-copyable values the author deliberately placed in the state, pre-PR every nested container was shared unconditionally, and both Flow instances sit in the same process and trust domain.
  • Do declarative state defaults in _create_definition_state still leak nested data across Flow instances built from one definition?
    The nested default is authored by the flow developer rather than a caller, no in-repo path runs flows for distinct principals off a shared definition, and per-caller input enters only through the initial_state path this PR now isolates.

Review 1 on this PR · 6c8ac23 · requested Nov 17 05:30 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@HanYuanLu HanYuanLu closed this Nov 20, 2026
@HanYuanLu HanYuanLu reopened this Nov 20, 2026

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.

[BUG] Independent Flows share nested initial_state and charge another department’s purchases

1 participant