fix(agentflow): implement regex operation in Condition node#5722
fix(agentflow): implement regex operation in Condition node#5722kaigritun wants to merge 3 commits intoFlowiseAI:mainfrom
Conversation
The Condition node's frontend UI offers a 'Regex' operation for string comparisons, but the backend was missing the corresponding handler in compareOperationFunctions. This caused a runtime error when users selected the Regex operation. This commit adds the regex handler that: - Takes value1 as the string to test - Takes value2 as the regex pattern - Returns true if value1 matches the regex pattern - Returns false for invalid regex patterns (graceful fallback) Fixes FlowiseAI#5650
Summary of ChangesHello @kaigritun, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical runtime error in the Agentflow Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly implements the regex operation for the Condition node, which was missing in the backend. The implementation is straightforward and handles invalid regex patterns gracefully by returning false. However, I've identified a significant security vulnerability (ReDoS) that needs to be addressed before this can be merged. My review includes a detailed comment on this issue.
| try { | ||
| const regex = new RegExp((value2 || '').toString()) | ||
| return regex.test((value1 || '').toString()) | ||
| } catch { | ||
| return false | ||
| } |
There was a problem hiding this comment.
The implementation of the regex operation is vulnerable to Regular Expression Denial of Service (ReDoS). Since the regex pattern is user-configurable, a malicious user could provide a pattern that leads to catastrophic backtracking, causing the service to hang by consuming 100% of CPU.
For example, a pattern like /(a+)+b/ combined with an input string like 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaac' would trigger this vulnerability.
It is highly recommended to validate the regex pattern against ReDoS before using it. You can use a library like safe-regex or re-recheck to check if a regex is safe. The check should be performed before new RegExp() is called.
|
Good catch on the ReDoS concern! I'll add safe-regex validation to protect against catastrophic backtracking. Pushing a fix shortly. |
Reject regex patterns with nested quantifiers that can cause catastrophic backtracking (e.g., (a+)+, (\w+)+). This addresses the security concern raised in code review.
…ex operations - Added safe-regex2 dependency to packages/components - Replaced manual ReDoS pattern check with safe-regex2 library validation - Validates regex pattern safety before executing new RegExp() - Addresses security concern raised in code review
|
✅ ReDoS vulnerability fixed! I've addressed the security concern by adding Changes made:
The Commit: 404b5a1 @gemini-code-assist This should resolve the ReDoS vulnerability you identified. The pattern is now validated using a well-tested library before regex execution. |
|
Thank you for the update, @kaigritun! I appreciate your quick action in addressing the ReDoS vulnerability. The integration of |
Summary
Fixes #5650
The Condition node's frontend UI offers a 'Regex' operation for string comparisons, but the backend was missing the corresponding handler in
compareOperationFunctions. This caused the runtime error:Changes
Added the
regexhandler to thecompareOperationFunctionsmap that:value1as the string to testvalue2as the regex patterntrueifvalue1matches the regex patternfalsefor invalid regex patterns (graceful fallback with try/catch)Testing
To verify the fix:
hello world)^hello)