Skip to content

fix(langchain): backport patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340)#35603

Merged
Eugene Yurtsev (eyurtsev) merged 5 commits intov0.3from
eugene/v0.3-cve-2024-58340
Mar 6, 2026
Merged

fix(langchain): backport patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340)#35603
Eugene Yurtsev (eyurtsev) merged 5 commits intov0.3from
eugene/v0.3-cve-2024-58340

Conversation

@eyurtsev
Copy link
Copy Markdown
Collaborator

Backport of #35598 to the v0.3 branch. Patches the ReDoS vulnerability in MRKL and ReAct agent action regex patterns (CVE-2024-58340).

Created with Deep Agents CLI.

@github-actions github-actions bot added langchain-classic `langchain-classic` package issues & PRs internal fix For PRs that implement a fix labels Mar 6, 2026
@eyurtsev Eugene Yurtsev (eyurtsev) marked this pull request as ready for review March 6, 2026 20:39
Copilot AI review requested due to automatic review settings March 6, 2026 20:39
@eyurtsev Eugene Yurtsev (eyurtsev) changed the title fix(langchain): patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340) fix(langchain-classic): patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340) Mar 6, 2026
@github-actions github-actions bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Mar 6, 2026
@eyurtsev Eugene Yurtsev (eyurtsev) changed the title fix(langchain-classic): patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340) fix(langchain): patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340) Mar 6, 2026
@github-actions github-actions bot removed the fix For PRs that implement a fix label Mar 6, 2026
@eyurtsev Eugene Yurtsev (eyurtsev) changed the title fix(langchain): patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340) fix(langchain): backport patch ReDoS vulnerability in MRKL and ReAct action regex (CVE-2024-58340) Mar 6, 2026
@github-actions github-actions bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Mar 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This is a backport of PR #35598 to the v0.3 branch, patching a ReDoS (Regular Expression Denial of Service) vulnerability (CVE-2024-58340) in the MRKL and ReAct agent action regex parsers. The vulnerable pattern (.*?)[\s]*Action allowed catastrophic backtracking on crafted input because (.*?) with re.DOTALL and [\s]* both compete to match whitespace characters, creating exponential ambiguity.

Changes:

  • Remove the redundant [\s]* quantifier between the first capture group and the literal Action keyword in both MRKLOutputParser.parse() and ReActSingleInputOutputParser.parse().
  • Add SIGALRM-based regression tests for both parsers to verify regex completes in bounded time on adversarial input.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
libs/langchain/langchain/agents/mrkl/output_parser.py Remove [\s]* from action-parsing regex to fix ReDoS vulnerability
libs/langchain/langchain/agents/output_parsers/react_single_input.py Same regex fix applied to the ReAct single input parser
libs/langchain/tests/unit_tests/agents/test_mrkl_output_parser.py Add ReDoS regression test for MRKLOutputParser
libs/langchain/tests/unit_tests/agents/output_parsers/test_react_single_input.py Add ReDoS regression test for ReActSingleInputOutputParser

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@github-actions github-actions bot added the langchain `langchain` package issues & PRs label Mar 6, 2026
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file (e.g. `pyproject.toml` or `uv.lock`) label Mar 6, 2026
@eyurtsev Eugene Yurtsev (eyurtsev) merged commit b0add1f into v0.3 Mar 6, 2026
35 checks passed
@eyurtsev Eugene Yurtsev (eyurtsev) deleted the eugene/v0.3-cve-2024-58340 branch March 6, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file (e.g. `pyproject.toml` or `uv.lock`) fix For PRs that implement a fix internal langchain `langchain` package issues & PRs langchain-classic `langchain-classic` package issues & PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants