fix(deps): widen json-repair bound (GHSA-xf7x-x43h-rpqh) + adapt parser to new repair semantics#6565
fix(deps): widen json-repair bound (GHSA-xf7x-x43h-rpqh) + adapt parser to new repair semantics#6565thomaschhh wants to merge 2 commits into
Conversation
fix(deps): widen json-repair bound to allow GHSA-xf7x-x43h-rpqh fix json-repair~=0.25.2 caps at <0.26.0, below the 0.60.1 release that fixes GHSA-xf7x-x43h-rpqh (HIGH, CVSS 7.5). CrewAI only uses repair_json(), whose signature is unchanged, so widening is API-safe.
json-repair >=0.60 fabricates output for non-JSON input (e.g. wraps
"{invalid_json" as ["invalid_json"]) instead of returning the empty
sentinel 0.25.x produced. The old UNABLE_TO_REPAIR_JSON_RESULTS check
therefore no longer detects unrepairable input, and the parser returned
garbage for plain-text tool inputs.
Only trust the repaired result when it parses back to a JSON object;
otherwise keep the original string. Restores prior behavior across the
full parser test suite under the widened json-repair bound.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR broadens the ChangesJSON repair validation
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/crewai/src/crewai/agents/parser.py (1)
184-187: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer
json.JSONDecodeErrorfor precise exception handling.While
ValueErrorworks safely (asJSONDecodeErrorinherits from it), catchingjson.JSONDecodeErroris the most precise and idiomatic way to handlejson.loads()failures in Python 3. As per coding guidelines, follow Python best practices and idiomatic patterns in Python source files.♻️ Proposed refactor
try: parsed = json.loads(result) - except ValueError: + except json.JSONDecodeError: return tool_input🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/crewai/src/crewai/agents/parser.py` around lines 184 - 187, Update the exception handler around json.loads(result) in the parser flow to catch json.JSONDecodeError instead of the broader ValueError, while preserving the existing return tool_input behavior for malformed JSON.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/crewai/src/crewai/agents/parser.py`:
- Around line 184-187: Update the exception handler around json.loads(result) in
the parser flow to catch json.JSONDecodeError instead of the broader ValueError,
while preserving the existing return tool_input behavior for malformed JSON.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d9d7b257-7b83-4823-b5f1-41dcbb841e3a
📒 Files selected for processing (2)
lib/crewai/pyproject.tomllib/crewai/src/crewai/agents/parser.py
What
Two commits:
fix(deps)— widenjson-repairinlib/crewai/pyproject.tomlfrom~=0.25.2(>=0.25.2,<0.26.0) to>=0.60.1,<1.0.fix(parser)— adapt_safe_repair_jsonto json-repair's changed repair semantics so the parser test suite stays green under the new bound.Why
The
<0.26.0cap blocks downstream projects from installingjson-repair >= 0.60.1, the release that fixes GHSA-xf7x-x43h-rpqh (CVSS 7.5, HIGH — DoS via unbounded$refresolution inSchemaRepairer.resolve_schema()). Since json-repair reaches downstream projects only transitively through CrewAI, the pin can only be lifted here. Latest json-repair is0.61.5.The bump is not a drop-in — and why the second commit is needed
json-repair
>=0.60changed the behavior ofrepair_json()(the signature is unchanged). For non-JSON input it now fabricates output instead of returning the empty sentinel 0.25.x produced:{invalid_json""["invalid_json"]{temperature in SF}""["temperature in SF}"]_safe_repair_jsonrelied on the empty sentinel (UNABLE_TO_REPAIR_JSON_RESULTS) to detect unrepairable input and fall back to the original string. With a fabricated non-empty result, that check no longer fires and the parser returns garbage — 14 parser tests fail on the bump alone.Fix: only trust the repaired result when it parses back to a JSON object; otherwise keep the original string.
The other
repair_jsoncall site (tools/tool_usage.py) already guards withisinstance(arguments, dict), so it needed no change.Verification
lib/crewai/tests/agents/test_crew_agent_parser.py: 44/44 pass (14 failed on the bump without the parser fix).lib/crewai/tests/agents+lib/crewai/tests/tools: the parser fix removes exactly those 14 failures and introduces zero new ones. Remaining failures in that run are pre-existing and unrelated (native tool calling / a2a / litellm — require API keys/network).ruff checkandruff format --checkpass on the changed file.References
json-repair < 0.60.1· Patched:0.60.1(latest0.61.5)