Summary During a security review of crewAI (v1.15.30), we identified three security boundary bypasses in previously hardened components: --- 1
Description
During a security review of crewAI (v1.15.30), we identified three security boundary bypasses in previously hardened components:
---
1. CREWAI_DESERIALIZE_CALLBACKS Guard Bypass & Arbitrary Module Import in BaseTool Deserialization (lib/crewai/src/crewai/tools/base_tool.py:59-78)
CrewAI introduced the CREWAI_DESERIALIZE_CALLBACKS environment variable guard (_trusted_deserialize() in lib/crewai/src/crewai/types/callback.py:25-29, 88-94) to prevent untrusted checkpoints or serialized payloads from importing arbitrary Python modules and resolving dotted-path callables.
However, _resolve_tool_dict() in lib/crewai/src/crewai/tools/base_tool.py (lines 59–78) bypasses this guard:
def _resolve_tool_dict(value: dict[str, Any]) -> Any:
"""Validate a dict with ``tool_type`` into the concrete BaseTool subclass."""
dotted = value.get("tool_type", "")
tool_cls = _TOOL_TYPE_REGISTRY.get(dotted)
if tool_cls is None:
mod_path, cls_name = dotted.rsplit(".", 1)
tool_cls = getattr(importlib.import_module(mod_path), cls_name)
# Pre-resolve serialized callback strings so SerializableCallable's
# BeforeValidator sees a callable and skips the env-var guard.
data = dict(value)
for key in ("cache_function",):
val = data.get(key)
if isinstance(val, str):
try:
data[key] = _resolve_dotted_path(val)
except (ValueError, ImportError):
data.pop(key)
return tool_cls.model_validate(data) # type: ignore[union-attr]- Unconditional
_resolve_dotted_path(val)oncache_function: Even whenCREWAI_DESERIALIZE_CALLBACKSis unset/disabled,_resolve_tool_dict()resolves any dotted path string incache_functioninto a live callable beforeSerializableCallable'sBeforeValidatorruns (which is invoked ascache_function(args, result)during tool execution). - Unchecked
importlib.import_module(mod_path)ontool_type: Whendottedis not in_TOOL_TYPE_REGISTRY,_resolve_tool_dict()imports arbitrary modules viaimportlib.import_module(mod_path)without checking_trusted_deserialize()or verifyingissubclass(tool_cls, BaseTool)before callingtool_cls.model_validate(data).
---
2. NL2SQLTool Read-Only Mode (allow_dml=False) SQL Validation Bypasses (lib/crewai-tools/src/crewai_tools/tools/nl2sql/nl2sql_tool.py:78-202, 325-370)
NL2SQLTool defaults to read-only mode (allow_dml=False) and blocks write statements in CTEs (WITH) and EXPLAIN ANALYZE. Three parser bypasses allow DML/DDL execution when allow_dml=False:
WITH ... AS MATERIALIZED (/AS NOT MATERIALIZED (Fail-Open Bypass (lines 78, 348–370):
_AS_PAREN_RE = re.compile(r"\bAS\s*\(", re.IGNORECASE)only matchesASfollowed immediately by whitespace and(.- Standard PostgreSQL / SQLite CTE syntax
WITH cte AS MATERIALIZED (SELECT 1) DELETE FROM usersorWITH d AS NOT MATERIALIZED (DELETE FROM users RETURNING *) SELECT * FROM dcauses_iter_as_paren_matches(stmt)to return an empty list. Both_detect_writable_cte(stmt)and_extract_main_query_after_cte(stmt)returnNone, and_validate_statement()reachesreturnat line 370 without raisingValueError(failing open).
- Leading SQL Comment Inside Writable CTE Body (lines 100–115):
_detect_writable_cte()slicesbody = stmt[open_idx + 1 : close_idx].strip()from the raw statement without calling_strip_sql_comments(body). A leading block comment inside the CTE parentheses (WITH d AS (/*comment*/ DELETE FROM users RETURNING *) SELECT * FROM d) setsfirst_wordto"/*COMMENT*/", bypassing_CTE_WRITE_INDICATORS.
EXPLAIN (ANALYZE true)Option Parsing Bypass (lines 182–201):
- In
_resolve_explain_command(),opt in ("ANALYZE", "ANALYSE")requires an exact string match on the option token, so valid PostgreSQL syntaxEXPLAIN (ANALYZE true) DELETE FROM usersorEXPLAIN (ANALYZE on) DELETE FROM users(opt == "ANALYZE TRUE") evaluatesanalyze_foundtoFalseand returnsNone, allowing theDELETEstatement to execute.
---
3. Symlink Sibling-Directory Prefix & Parent-Symlink Bypass in FilePath._validate_file_exists (lib/crewai-files/src/crewai_files/core/sources.py:218-236)
In lib/crewai-files/src/crewai_files/core/sources.py (lines 227–231):
if self.path.is_symlink():
resolved = self.path.resolve()
cwd = Path.cwd().resolve()
if not str(resolved).startswith(str(cwd)):
raise ValueError(f"Symlink escapes allowed directory: {self.path}")not str(resolved).startswith(str(cwd))is vulnerable to sibling-directory prefix matching (e.g., ifcwdis/app/work, a symlink to/app/work_secrets/key.pempassesstartswith("/app/work")).self.path.is_symlink()only checks the final path component; if an intermediate directory is a symlink pointing outsidecwd(e.g.linked_dir/secret.txt),self.path.is_symlink()isFalseand containment is never checked.
---
Suggested Remediation
- In
lib/crewai/src/crewai/tools/base_tool.py:
- Only pre-resolve
cache_functionwithout_trusted_deserialize()when it matches the built-increwai.tools.base_tool._default_cache_function, and require_trusted_deserialize()(plusissubclass(tool_cls, BaseTool)) when importing arbitrary modules viatool_type.
- In
lib/crewai-tools/src/crewai_tools/tools/nl2sql/nl2sql_tool.py:
- Run
_strip_sql_comments()before CTE matching, update_AS_PAREN_REto match\bAS\b(?:\s+(?:NOT\s+)?MATERIALIZED\b)?\s*\(, raiseValueErrorin read-only mode if_extract_main_query_after_cte()returnsNone, and matchopt.split()[0] in ("ANALYZE", "ANALYSE")in_resolve_explain_command().
- In
lib/crewai-files/src/crewai_files/core/sources.py:
- Always check
self.path.resolve().is_relative_to(Path.cwd().resolve()).
---
Patches
- Issues 1 and 2 (
crewai,crewai-tools) are fixed in 1.15.31. - Issue 3 (
crewai-files) is fixed in 1.15.44:FilePathnow resolves the path on every validation and checks working-directory containment withPath.is_relative_to, closing the parent-directory symlink and sibling-directory prefix bypasses. Plain absolute paths outside the working directory remain allowed; this release addresses symlink containment only.
Upgrade to the patched versions above. There is no workaround other than avoiding untrusted paths and symlinks under the working directory.