Keep flow files from reaching installed code and values when reading signatures #119
<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"e93bd1ba56259c379b6849105ef4eab55c811e4a","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->
<details>
<summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-24T20:20:37.847597Z">2026-11-24T20:20:37.847597Z</relative-time> | e93bd1b | Draft marked ready |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
</details>
</details>
Approved these changes.
<!-- codex-review-receipt:v1 -->
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e93bd1ba56
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
</details>
<sub><sub>!P1 Badge</sub></sub> Bound constructed path values before returning
Path and PurePath are allowed variadic constructors, but this bound treats their results as atomic and returns them unchecked. An untrusted flow can repeatedly construct P1 = Path(P0, P0, ...), then repeat P1 in later paths; each argument passes _check_argument, while pathlib exponentially expands the stored parts and eventually exhausts memory or creates an enormous schema when stringified. Bound path length/parts and aggregate constructor arguments rather than only str and bytes results.
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
Valid: paths weren't covered by the string length bound. Fixed in https://github.com/PrefectHQ/prefect-cloud/commit/100500aca9506e8f926b9ed28fc7530b746ef656: paths now count toward that bound, and the combined length of string and path arguments is checked before a value constructor runs.
---
Posted by Claude Opus 5.5 on behalf of @chrisguidry.
<!-- monitor-pr -->
My Claude reviewed this for schema output only, so please don't count it as a security review. Two changes from main, both reproduced at 100500a:
1. source_signature.py:495: a model field like i: I = Field(default_factory=I), with I a model in the same file, now gets {"$ref": "#/definitions/I", "default": null}. On main it has no default. Null isn't valid for I. Leaving the default out when the factory is refused would keep main's schema.
2. def f(x: M = M(a='bad')), where a is an int, now uploads {"a": "bad"} as the default. On main it's null. The description says defaults aren't coerced anymore, but not that invalid ones get through.
@bunchesofdonald Thanks, both reproduced and fixed in 9e3b16a. A refused default_factory now leaves the field with no default, as on main. Rebuilt models whose fields use only builtin and standard value types, annotated_types constraints, and enums and models from the same file are now validated, so M(a='bad') is null again and M(a='5') becomes 5. Models with other field types, like ImportString, FilePath, or a BaseSettings model, still skip validation, because their validators can import modules, check files, or read the environment, so an invalid default can still get through for those.
---
Posted by Claude Opus 5.5 on behalf of @chrisguidry.
<!-- monitor-pr -->
gaker
chrisguidry
After #117,
signature_from_sourcestill let a flow file reach code and data on the deploying machine. Enum hooks like_missing_, non-enum mixin bases, andField(default_factory=...)could call installed functions with arguments from the file. Pydantic evaluated strings the file built, likeX = "..."indef f(x: X)orRootModel["..."], as forward references. Installed values such asos.environ, aBaseSettingsmodel, anImportStringfield validated through adefault_factory, or a module's install path could end up in the uploaded parameter schema. Small files could also take tens of seconds or gigabytes of memory, through huge integers,str()growth, self-repeating tuples and type aliases, long|chains, and model subclass chains.From installed modules, the file can now only reach modules, classes, typing constructs, enum members, time zones, and the fixed list of value constructors. Enums are rebuilt only from the standard enum bases, with
str,int, orfloatmixins, or from a member-less enum in the same file. Models are rebuilt only fromBaseModelor a model in the same file. Underscored enum members and model fields are skipped. Callable arguments must be value constructors, and calling a rebuilt model usesmodel_construct, so no installed field type is ever instantiated. Annotations that still hold a string outsideLiteralvalues orAnnotatedmetadata are unknown, and subscript keys on installed types are checked before the subscript runs. Strings, integers, decimals, collections, unions, and the number of rebuilt fields are all bounded. The reader also gainedenum.auto(), arithmetic on numbers, and enum.name/.value. A file that will not parse now gets "Could not parse" from the CLI instead of "Could not find function".As before, anything the reader won't evaluate makes that parameter untyped, or its default
None, without failing the deploy. Lost fidelity compared withmain: installed constants used as defaults (likeos.sep), quoted forward references nested in generics,BaseSettingsandRootModelparameter types, integers over 128 bits, strings over 10,000 characters, and defaults or annotations over 1,000 items. Rebuilt model defaults are no longer coerced to their field types. Importing an installed module still runs its top-level code; the module docstring now says so.callables.pynow treats a pydanticSchemaErrorlike the other schema failures, anddeployments.pyannotates withbuiltins.listbecause a newer pyright readlist[...]there as that module's ownlistfunction.<details>
<summary>Session context</summary>
A late review of #117 listed ways a flow file could still run code or read the environment through
signature_from_source. I reproduced them first: marker files appeared through an enum_missing_hook, asubprocess.Popenmixin, and adefault_factory, andos.environandBaseSettingsvalues appeared in defaults. The first commit restricted what installed objects the file can reach and fixed the smaller items. Two rounds of independent adversarial reviewers (three, then two) then attacked the branch for code execution, data leaks, and resource use. Each round found real problems: forward-referenceevalthrough built strings andRootModel[...], a fullos.environdump throughImportStringwithvalidate_defaultbehind adefault_factory, install paths throughstr(module)andstr-mixin enums, and several quadratic or exponential slowdowns. Each one has a regression test that failed before its fix. Tests pass on Python 3.10, 3.12, and 3.14.</details>
🤖 Generated with Claude Code
https://claude.ai/code/session_01KgFwscCHoKkVwXCDDKXMdt