Repository navigation
fix(security): patch deserialization, SQL injection, and path traversal vulnerabilities [SECT-601] - #8623
Conversation
Strix Security Review✅ No open security findings. All previously reported findings have been resolved. PR summary: Hardens three areas of the framework: checkpoint/tool deserialization now refuses to resolve non-first-party `tool_type` paths without an explicit opt-in and no longer pre-resolves `cache_function` strings, NL2SQL read-only mode now rejects any statement containing SQL comment markers instead of trying to strip them, and the skill-archive extraction fallback used on older Pythons now refuses symlink and hardlink members entirely. Review summaryRe-review of the security patch at One out-of-diff observation worth a separate change: read-only mode still accepts comment-free write statements on PostgreSQL through helpers this PR did not modify — 3 resolved findings
Ruled out (4)
Review history (4)
Review 4 on this PR · Reviewed by Strix |
…al vulnerabilities Fixes three security issues reported in SR-2026-0127 / GHSA-wp6h-6xxh-g8fp: 1. Deserialization bypass: _resolve_tool_dict() now requires CREWAI_DESERIALIZE_CALLBACKS=1 for unregistered tool types, and stops pre-resolving cache_function strings that bypassed the env-var guard. 2. NL2SQL read-only bypass: SQL comment stripping prevents comment-based injection that could hide write commands from the read-only validator. 3. Tar extraction TOCTOU: Member-by-member extraction with post-creation symlink target verification eliminates race conditions in archive unpacking. Linear: SECT-601
The gate on unregistered tool types also refused crewai's own tools when a checkpoint was resumed in a fresh process, refused tools declared as dicts in JSON project files, and, with the cache_function pre-resolution removed, refused the default cache function on every serialized tool. - crewai. and crewai_tools. tool types import without the opt-in. Any import now only registers classes, so a target that is not a BaseTool subclass is refused even with CREWAI_DESERIALIZE_CALLBACKS=1. - The default cache_function path restores without importing anything; any other path still goes through SerializableCallable's gate. - The JSON loader resolves dict tool_type through its trusted class-ref path, as it already does for "module:Class" strings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le comments
Comment stripping ran in three helpers but not in the EXPLAIN resolver or
the CTE matcher, so a comment after EXPLAIN or between AS and "(" still hid
a write. It also deleted MySQL/MariaDB executable comments, whose contents
the server runs, so "/*!50000 DROP TABLE t */ SELECT 1" passed as SELECT.
Each statement is now normalized once, where validation and the commit
decision start, so every check reads the same text. Comments become a
space, since DELETE/**/FROM is a DELETE; executable comments are kept
verbatim and fail closed as an unrecognised command.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The phased extraction still let a dest-relative symlink be followed by a later ".." member, and a hardlink to a dangling symlink member is re-created by tarfile as that symlink at the hardlink's path, after its target was checked against a different directory. The fallback only runs on Pythons without filter="data" (before 3.10.12, 3.11.4, 3.12), so it now refuses symlink and hardlink members outright, with a message naming the versions that handle them, checks every other member's path, and extracts with extractall. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
482fbda to
1edf182
Compare
|
I rebased on main and pushed three commits: 0e14ca7, d082e0e and 1edf182. Besides the review findings, the deserialization change had regressions that no review caught. All of them were reproduced on the previous head:
Verification
Out of scope, needs a ticket: Strix (@strix-security) please re-review. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1edf182. Configure here.
Stripping comments only honoured single-quoted literals, so a comment marker inside a double-quoted or backtick identifier or a dollar quote truncated the statement: WITH "a--" AS (SELECT 1) DELETE FROM users was validated as a lone CTE and executed. Any stripper has to match every database's quoting rules, and each mismatch is a bypass. Read-only mode now refuses statements with -- or /* outside single-quoted literals; the scan can only end a literal early, never late, so it errs toward refusing. With allow_dml=True, commented statements are committed as writes. _strip_sql_comments is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed 9ef3c23 for the NL2SQL re-review finding. Read-only mode now refuses commented statements instead of stripping comments; details are in the thread. Strix (@strix-security) please re-review. |
Skipping single-quoted literals let a quote inside an identifier open a fake literal that swallowed a real comment, and MySQL's # comment was not detected: WITH "q'" AS (SELECT 1 --') SELECT 1 / ) DELETE FROM users and WITH a AS (SELECT 1 #) SELECT 1 / ) DELETE FROM users both passed. Read-only mode now refuses -- and /* anywhere, including inside string literals, and # when db_uri is MySQL or MariaDB (on PostgreSQL # is a JSON operator). allow_dml=True keeps committing commented statements as writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
crewai.skills.cache._safe_extractall is the same fallback the CLI uses, with the link-target validation the CLI copy dropped: a dest-relative symlink can still carry a later member's write outside the cache directory. Apply the same link-refusing version and note that the two copies must change together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest push addresses both Strix re-review findings:
Strix (@strix-security) please re-review. |
alex-clawd
left a comment
There was a problem hiding this comment.
Approving. All three fixes are sound, and in two places the implementation is stronger than what the description claims. Flagging that gap because the PR body is what ends up in the advisory.
1. Deserialization guard — correct, and the registry re-check is the good part
The important detail is that resolution no longer trusts the import:
importlib.import_module(dotted.rpartition(".")[0])
tool_cls = _TOOL_TYPE_REGISTRY.get(dotted)
if tool_cls is None:
raise ValueError(f"Tool type '{dotted}' is not a BaseTool subclass")The old code did getattr(import_module(mod), cls_name) and returned whatever came back, so os.system resolved to a callable. Now the registry is the authority, and it is only populated through BaseTool.__init_subclass__, so a non-tool attribute cannot come out the other end even when the module imports fine.
I checked the _FIRST_PARTY_TOOL_PACKAGES prefix for bypasses:
crewai.tools.base_tool.MyTool allowed (intended)
crewai_tools.tools.foo.FooTool allowed (intended)
crewai_evil.Tool blocked
crewai_tools_evil.Tool blocked
crewaiX.Tool blocked
os.system / subprocess.Popen blocked
The trailing dot in both prefixes is doing real work — without it crewai_evil would match. Worth keeping a comment on that if anyone ever edits the tuple.
One input slips the prefix test: "crewai." on its own passes startswith, imports the crewai package, then fails the registry lookup and raises. Harmless, since importing crewai is already happening, but it is the one case where the gate is passed by something that is not a real first-party path.
Removing the cache_function pre-resolution is the right call — that block existed specifically to hand SerializableCallable a resolved callable so its env-var guard would not fire, which is the definition of a bypass. Keeping the default-path special case means resume still works without the opt-in, and the default needs no import at all.
json_loader.py is the necessary counterpart: project files are trusted, so pre-registering the class there keeps declarative projects working without weakening the checkpoint path. Good separation — the trust boundary is where the data comes from, not what the data says.
2. NL2SQL — the implementation is better than the description
The PR body says a _strip_sql_comments() helper was added that removes comments "while preserving string literals." That is not what shipped, and the thing that shipped is the safer design:
def _has_sql_comment(sql: str, db_uri: str) -> bool:
markers = ["--", "/*"]
if db_uri.split(":", 1)[0].split("+", 1)[0] in ("mysql", "mariadb"):
markers.append("#")
return any(marker in sql for marker in markers)Refuse rather than strip. The docstring explains exactly why, and it is the correct instinct:
that has to agree with every database's quoting rules (identifiers, backticks, dollar quotes, MySQL
/*! */), and any disagreement lets a write hide from the validator
A comment stripper is a parser, and a parser that disagrees with the database by one edge case reintroduces the bug. MySQL's /*! ... */ executable comments alone would make stripping unsafe — content inside them runs. Refusing is coarser and occasionally annoying, but it cannot be out-parsed.
Two details I liked:
#is only a comment marker on MySQL/MariaDB and is a JSON operator on PostgreSQL, so it is gated on the dialect. Getting that backwards would have broken valid Postgres queries._is_write_stmttreats a commented statement as a write, with the reasoning that committing a read is harmless. Failing toward the restrictive side in the transaction path is right.
Please update the PR body before this becomes an advisory. It currently describes a stripping approach and names a function that does not exist.
3. Tar extraction — also not what the description says
The body describes "phased member-by-member extraction: directories first, then regular files, then symlinks created manually via os.symlink() with re-verification." The code does something simpler and stronger: it refuses link members outright.
if member.issym() or member.islnk():
raise ValueError(
f"Blocked link member {member.name!r}: installing skills that "
"contain links needs Python 3.10.12+, 3.11.4+, or 3.12+"
)This is the better fix. Phased extraction with re-verification still has to reason about ordering and about what the filesystem looks like at each step; refusing links removes the TOCTOU window by removing the feature on a fallback path that only runs on old Python. The error message tells the user the exact versions that restore support, which keeps it from being a dead end.
Note this is a real behavior change, not just a hardening: test_allows_benign_relative_symlink became test_refuses_links_with_upgrade_hint. A skill archive containing an entirely benign internal symlink now fails to install on Python < 3.10.12 / < 3.11.4. That is the right trade for a security fallback, but it should be in the release notes rather than discovered by a user.
Both copies — crewai_cli/skills/main.py and crewai/skills/cache.py — were updated identically, and the second now carries a "change both together" comment. Worth considering whether that duplication should collapse into one shared helper at some point, since two copies of a security control will eventually drift.
Summary
All 28 checks green, including CodeQL, Bugbot, Strix, and pip-audit across four Python versions. Test coverage matches the three fixes: 3 deserialization, 7 NL2SQL comment-injection, and the rewritten extraction tests.
Only ask before merge: reconcile the PR description with what the code actually does for #2 and #3. The shipped behavior is better in both cases, and the advisory should say so accurately.
…store A tool cache_function that could not be saved (a lambda or bound method) is now restored as a named never-cache function instead of the BaseTool default, so a guard on a state-changing tool fails closed. A classmethod reached through a subclass is now saved under the class it is bound to, so it rebinds to that class after a restore instead of the parent that defines it. The checkpointing docs (en/ar/ko/pt-BR) say the construction warning fires only when a callback is passed in, not when set as an attribute. A tool cache_function path stays behind CREWAI_DESERIALIZE_CALLBACKS, as #8623 made it; only the default restores without the opt-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…store A tool cache_function that could not be saved (a lambda or bound method) is now restored as a named never-cache function instead of the BaseTool default, so a guard on a state-changing tool fails closed. A classmethod reached through a subclass is now saved under the class it is bound to, so it rebinds to that class after a restore instead of the parent that defines it. The checkpointing docs (en/ar/ko/pt-BR) say the construction warning fires only when a callback is passed in, not when set as an attribute. A tool cache_function path stays behind CREWAI_DESERIALIZE_CALLBACKS, as #8623 made it; only the default restores without the opt-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…store A tool cache_function that could not be saved (a lambda or bound method) is now restored as a named never-cache function instead of the BaseTool default, so a guard on a state-changing tool fails closed. A classmethod reached through a subclass is now saved under the class it is bound to, so it rebinds to that class after a restore instead of the parent that defines it. The checkpointing docs (en/ar/ko/pt-BR) say the construction warning fires only when a callback is passed in, not when set as an attribute. A tool cache_function path stays behind CREWAI_DESERIALIZE_CALLBACKS, as #8623 made it; only the default restores without the opt-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing restore (#8596) * fix(checkpoint): save unrestorable callbacks as null instead of breaking restore A restore builds the crew from the checkpoint file, so callbacks survive only as dotted paths to module-level functions. Bound instance methods were saved as "mod.Class.method", which resolves to the unbound function and crashed the resumed run with a missing-argument TypeError. Partials and callable instances made the serializer raise, so no checkpoint was written at all. callable_to_string now returns None for bound instance methods and for callables without __module__/__qualname__, matching how lambdas and closures were already handled. Classmethods still round-trip. The construction-time warning now uses the same rule and says the callback is dropped and will not run after a restore. The checkpointing docs (en, ar, ko, pt-BR) explain what a restore does not bring back and the CREWAI_DESERIALIZE_CALLBACKS opt-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(checkpoint): restore tools and agents whose callables were saved as null A checkpoint saves a callable it cannot name (a lambda, closure, bound method, partial or callable instance) as null. Restoring then failed with "Expected a callable or dotted-path string, got NoneType" when that null sat in a tool's cache_function or an agent's callbacks list. Those fields now restore without it: a null cache_function falls back to the tool's default, and null entries are dropped from BaseAgent.callbacks, the same way Crew already drops them from its kickoff callback lists. The docs now say that such a tool cache_function falls back to the default, and the pt-BR anchor keeps its accents to match the heading slug. This also reverts an unrelated edit to TestCheckpointReusedExecutor that the previous commit made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(checkpoint): never cache after losing a tool cache_function on restore A tool cache_function that could not be saved (a lambda or bound method) is now restored as a named never-cache function instead of the BaseTool default, so a guard on a state-changing tool fails closed. A classmethod reached through a subclass is now saved under the class it is bound to, so it rebinds to that class after a restore instead of the parent that defines it. The checkpointing docs (en/ar/ko/pt-BR) say the construction warning fires only when a callback is passed in, not when set as an attribute. A tool cache_function path stays behind CREWAI_DESERIALIZE_CALLBACKS, as #8623 made it; only the default restores without the opt-in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(checkpoint): pass the callable-instance class directly to the parametrize list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(checkpoint): restore a saved never-cache function without the opt-in A restored tool whose cache_function was lost is saved by name as _never_cache_function on the next checkpoint. Only the default path was exempt from CREWAI_DESERIALIZE_CALLBACKS, so restoring that second checkpoint raised "Refusing to resolve callback path". Both of crewAI's own cache functions now restore by name, without an import or the opt-in. Any other path still goes through the gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Security Patch — SR-2026-0127 / GHSA-wp6h-6xxh-g8fp
Fixes three security vulnerabilities:
1. Deserialization bypass in tool restoration (
base_tool.py)_resolve_tool_dict()usedimportlib.import_module()on attacker-controlled dotted paths from serialized checkpoint data without checking the_trusted_deserialize()guard. A malicious checkpoint could import and resolve arbitrary Python objects (e.g.,os.system).Additionally,
cache_functionstrings were pre-resolved via_resolve_dotted_path()explicitly to bypassSerializableCallable'senv-var guard.Fix: Unregistered tool types now require
CREWAI_DESERIALIZE_CALLBACKS=1. Thecache_functionpre-resolution block has been removed entirely —SerializableCallable'svalidator handles it with its own_trusted_deserialize()check.2. NL2SQL read-only mode bypass via SQL comment injection (
nl2sql_tool.py)SQL comments (
--and/* */) could hide write commands from the read-only validator:/* SELECT */ DELETE FROM users— block comment before write commandWITH d AS (/* read */ DELETE FROM users) SELECT 1— block comment inside CTE body-- comment\nDELETE FROM users— line comment before write commandThe
_extract_command(),_detect_writable_cte(), and_extract_main_query_after_cte()functions only checked the first token without stripping comments first.Fix: Added
_strip_sql_comments()helper that removes both--line comments and/* */block comments while preserving string literals. Applied to all three extraction points.3. Tar extraction TOCTOU race condition (
skills/main.py)_safe_extractall()validated all archive members upfront but then calledtf.extractall(dest)which extracts everything at once. Since symlinks and files are extracted in archive order, a symlink could be extracted first and a subsequent file could follow it outside the destination directory.Fix: Replaced
extractall()with phased member-by-member extraction: directories first, then regular files, then symlinks created manually viaos.symlink()with re-verification of targets at creation time. This eliminates the TOCTOU window entirely.Tests
_resolve_tool_dictblocks unregistered tool types without the env varNote
High Risk
Changes deserialization gates, SQL execution policy, and archive install paths—regressions could allow arbitrary imports, hidden writes, or path escape on older Python.
Overview
Addresses three security areas: checkpoint/tool deserialization, NL2SQL read-only validation, and skill archive extraction.
Tool restoration (
base_tool.py): Serializedtool_typedicts no longer import arbitrary modules unless the type is undercrewai./crewai_tools.orCREWAI_DESERIALIZE_CALLBACKS=1. Non-BaseTooltargets are rejected after import. Thecache_functionpre-resolution bypass is removed; the default cache path is stripped so restore works without the opt-in. JSON projects eagerly resolvetool_typevia_resolve_tool_classso project-defined tools register before Pydantic hydration.NL2SQL (
nl2sql_tool.py): Read-only mode rejects any statement containing--,/*, or (MySQL/MariaDB only)#, instead of parsing/stripping comments—avoiding bypasses via quoting and dialect quirks. Withallow_dml=True, commented statements are treated as writes for commit detection.Tar fallback (
_safe_extractallin CLI skills + skill cache): On Python withouttarfilefilter="data", symlink and hardlink members are blocked entirely (with a Python upgrade hint); only files and directories pass path checks beforeextractall. Tests cover link chains, hardlink-to-symlink cases, and traversal member names.Reviewed by Cursor Bugbot for commit dfe4f74. Bugbot is set up for automated code reviews on this repo. Configure here.