Skip to content

Commit 0e6ada4

Browse files
authored
fix(security): resolve ReDoS vulnerability in function execute tag pattern (#4149)
* fix(security): resolve ReDoS vulnerability in function execute tag pattern Simplified regex to eliminate overlapping quantifiers that caused exponential backtracking on malformed input without closing delimiter. * fix(security): exclude trailing-dot refs and hoist tag pattern to module level * fix(security): align tag pattern with codebase standard [^<>]+ pattern Matches createReferencePattern() from reference-validation.ts used by the core executor. Invalid refs handled gracefully by resolveBlockReference. * refactor(security): use createReferencePattern() instead of inline regex
1 parent 85fda99 commit 0e6ada4

File tree

1 file changed

+4
-5
lines changed
  • apps/sim/app/api/function/execute

1 file changed

+4
-5
lines changed

apps/sim/app/api/function/execute/route.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { type OutputSchema, resolveBlockReference } from '@/executor/utils/block
1818
import { formatLiteralForCode } from '@/executor/utils/code-formatting'
1919
import {
2020
createEnvVarPattern,
21+
createReferencePattern,
2122
createWorkflowVariablePattern,
2223
} from '@/executor/utils/reference-validation'
2324
export const dynamic = 'force-dynamic'
@@ -27,6 +28,8 @@ export const MAX_DURATION = 210
2728

2829
const logger = createLogger('FunctionExecuteAPI')
2930

31+
const TAG_PATTERN = createReferencePattern()
32+
3033
const E2B_JS_WRAPPER_LINES = 3
3134
const E2B_PYTHON_WRAPPER_LINES = 1
3235

@@ -493,11 +496,7 @@ function resolveTagVariables(
493496
let resolvedCode = code
494497
const undefinedLiteral = language === 'python' ? 'None' : 'undefined'
495498

496-
const tagPattern = new RegExp(
497-
`${REFERENCE.START}([a-zA-Z_](?:[a-zA-Z0-9_${REFERENCE.PATH_DELIMITER}]*[a-zA-Z0-9_])?)${REFERENCE.END}`,
498-
'g'
499-
)
500-
const tagMatches = resolvedCode.match(tagPattern) || []
499+
const tagMatches = resolvedCode.match(TAG_PATTERN) || []
501500

502501
for (const match of tagMatches) {
503502
const tagName = match.slice(REFERENCE.START.length, -REFERENCE.END.length).trim()

0 commit comments

Comments
 (0)