From 1f1a1ea138b76c016225d2db4f1e8701ad23410c Mon Sep 17 00:00:00 2001 From: "Abdullah." <125115953+mabdullahabaid@users.noreply.github.com> Date: Wed, 17 Dec 2025 21:13:55 +0500 Subject: [PATCH] fix(workflows): align variable regex with validation and prevent ReDoS (#16607) **What this fixes:** - Addresses a CodeQL security finding: the regex used to find variables in workflow strings could be slow on malicious inputs (ReDoS). - Two alerts: [Code Scanning 181](https://github.com/twentyhq/twenty/security/code-scanning/181) and [Code Scanning 182](https://github.com/twentyhq/twenty/security/code-scanning/182) **Context:** - Our workflow system lets users insert variables like `{{user.name}}` or `{{trigger.properties.after.name}}` into strings and JSON (HTTP request bodies, record field values, etc.). - The `variable-resolver.ts` module scans these strings and replaces variables with actual values. - Our validation (`isValidVariable`) already enforces that variables contain no `{` or `}` inside them (only simple property paths like `user.name`). **The change:** - Updated the regex from `/\{\{(.*?)\}\}/g` to `/\{\{([^{}]+)\}\}/g` to match our validation pattern. - This removes the ReDoS risk and aligns the resolver with the validation contract. **Why this is safe:** - All supported workflow usage (simple variable paths) continues to work. - Both `match` and `replace` behave the same for valid variables. - Only unsupported patterns with nested braces (e.g., `{{foo {bar}}}`) would stop matching, which isn't part of our supported syntax anyway. --- packages/twenty-shared/src/utils/variable-resolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/twenty-shared/src/utils/variable-resolver.ts b/packages/twenty-shared/src/utils/variable-resolver.ts index 92e5bcb208..7e7b1a8fde 100644 --- a/packages/twenty-shared/src/utils/variable-resolver.ts +++ b/packages/twenty-shared/src/utils/variable-resolver.ts @@ -8,7 +8,7 @@ const isString = (value: any): value is string => { return typeof value === 'string'; }; -const VARIABLE_PATTERN = RegExp('\\{\\{(.*?)\\}\\}', 'g'); +const VARIABLE_PATTERN = RegExp('\\{\\{([^{}]+)\\}\\}', 'g'); export const resolveInput = ( unresolvedInput: unknown,