Skip to content

fix(deps): widen json-repair bound (GHSA-xf7x-x43h-rpqh) + adapt parser to new repair semantics#6565

Open
thomaschhh wants to merge 2 commits into
crewAIInc:mainfrom
thomaschhh:patch-1
Open

fix(deps): widen json-repair bound (GHSA-xf7x-x43h-rpqh) + adapt parser to new repair semantics#6565
thomaschhh wants to merge 2 commits into
crewAIInc:mainfrom
thomaschhh:patch-1

Conversation

@thomaschhh

Copy link
Copy Markdown

What

Two commits:

  1. fix(deps) — widen json-repair in lib/crewai/pyproject.toml from ~=0.25.2 (>=0.25.2,<0.26.0) to >=0.60.1,<1.0.
  2. fix(parser) — adapt _safe_repair_json to json-repair's changed repair semantics so the parser test suite stays green under the new bound.

Why

The <0.26.0 cap blocks downstream projects from installing json-repair >= 0.60.1, the release that fixes GHSA-xf7x-x43h-rpqh (CVSS 7.5, HIGH — DoS via unbounded $ref resolution in SchemaRepairer.resolve_schema()). Since json-repair reaches downstream projects only transitively through CrewAI, the pin can only be lifted here. Latest json-repair is 0.61.5.

The bump is not a drop-in — and why the second commit is needed

json-repair >=0.60 changed the behavior of repair_json() (the signature is unchanged). For non-JSON input it now fabricates output instead of returning the empty sentinel 0.25.x produced:

Input 0.25.x 0.61.x
{invalid_json "" ["invalid_json"]
{temperature in SF} "" ["temperature in SF}"]

_safe_repair_json relied 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.

try:
    parsed = json.loads(result)
except ValueError:
    return tool_input
if not isinstance(parsed, dict):
    return tool_input

The other repair_json call site (tools/tool_usage.py) already guards with isinstance(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).
  • Full 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 check and ruff format --check pass on the changed file.

References

  • Advisory: GHSA-xf7x-x43h-rpqh
  • Affected: json-repair < 0.60.1 · Patched: 0.60.1 (latest 0.61.5)

thomaschhh and others added 2 commits July 16, 2026 16:53
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>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR broadens the json-repair dependency range and updates _safe_repair_json to accept repaired output only when it parses into a JSON object.

Changes

JSON repair validation

Layer / File(s) Summary
Repair dependency and parser validation
lib/crewai/pyproject.toml, lib/crewai/src/crewai/agents/parser.py
The json-repair constraint now allows versions from 0.60.1 below 1.0; _safe_repair_json parses repaired output and returns the original input when parsing fails or produces a non-object value.

Suggested reviewers: lorenzejay

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main changes: widening json-repair and updating the parser for its new behavior.
Description check ✅ Passed The description directly explains the dependency bump, parser adaptation, and verification results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thomaschhh
thomaschhh marked this pull request as ready for review July 16, 2026 15:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/crewai/src/crewai/agents/parser.py (1)

184-187: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer json.JSONDecodeError for precise exception handling.

While ValueError works safely (as JSONDecodeError inherits from it), catching json.JSONDecodeError is the most precise and idiomatic way to handle json.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

📥 Commits

Reviewing files that changed from the base of the PR and between 999bee8 and 9cc0f79.

📒 Files selected for processing (2)
  • lib/crewai/pyproject.toml
  • lib/crewai/src/crewai/agents/parser.py

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.

1 participant