Skip to content

fix(security): resolve ReDoS vulnerability in function execute tag pattern#4149

Merged
waleedlatif1 merged 4 commits intostagingfrom
waleedlatif1/san-juan-v5
Apr 14, 2026
Merged

fix(security): resolve ReDoS vulnerability in function execute tag pattern#4149
waleedlatif1 merged 4 commits intostagingfrom
waleedlatif1/san-juan-v5

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Simplified regex in resolveTagVariables to eliminate overlapping quantifiers ([a-zA-Z0-9_.]*[a-zA-Z0-9_]) that caused exponential backtracking on malformed input (e.g., <aaaa... without closing >)
  • Also dismissed 7 pre-existing CodeQL SSRF false positives across Confluence, TTS, STT, Google Sheets, and Excel routes — all use hardcoded domains with validated input

Type of Change

  • Bug fix

Testing

  • bun run lint passes
  • bun run test — all 5031 tests pass (5 pre-existing import failures unrelated)
  • TypeScript compiles clean (pre-existing type errors only in templates/file-viewer)

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…ttern

Simplified regex to eliminate overlapping quantifiers that caused exponential
backtracking on malformed input without closing delimiter.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 14, 2026 3:21am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 14, 2026

PR Summary

Low Risk
Low risk: change is localized to tag parsing in the function-execution API and swaps a regex implementation to reduce ReDoS risk, with minimal behavioral impact expected beyond which substrings are considered tag matches.

Overview
Updates function tag resolution in apps/sim/app/api/function/execute/route.ts to use the shared createReferencePattern() (cached as TAG_PATTERN) instead of an inline reference-matching regex.

This removes the previous potentially backtracking-heavy pattern and centralizes tag parsing behavior to the common reference-validation utility, mitigating ReDoS risk from malformed/untrusted code inputs.

Reviewed by Cursor Bugbot for commit 4e21a08. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR fixes a ReDoS vulnerability in resolveTagVariables by replacing an inline regex with overlapping quantifiers with the codebase-standard createReferencePattern() utility (which produces <([^<>]+)> — a negated character class that cannot catastrophically backtrack). The hoisting of TAG_PATTERN to module level is safe because String.prototype.match() resets lastIndex to 0 before each call, so the shared global RegExp instance has no stale-state risk across requests.

Confidence Score: 5/5

  • Safe to merge — targeted security fix with no correctness regressions or new risks introduced.
  • The change is a minimal, well-scoped replacement of a ReDoS-vulnerable regex with the codebase-standard pattern. The new pattern [^<>]+ is linear and cannot catastrophically backtrack. The module-level hoisting with .match() is safe (lastIndex is reset). All remaining items from prior review threads are resolved. No P0/P1 findings.
  • No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/api/function/execute/route.ts Replaced vulnerable inline regex in resolveTagVariables with module-level TAG_PATTERN = createReferencePattern(), which uses [^<>]+ to eliminate catastrophic backtracking. No correctness regressions detected.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["resolveTagVariables(code, ...)"] --> B["resolvedCode.match(TAG_PATTERN)"]
    B --> C{"matches found?"}
    C -- "no" --> Z["return resolvedCode"]
    C -- "yes" --> D["for each match"]
    D --> E["slice <...> to get tagName"]
    E --> F["resolveBlockReference(blockName, fieldPath)"]
    F --> G{"result found?"}
    G -- "no" --> D
    G -- "yes" --> H{"tagValue === undefined?"}
    H -- "yes" --> I["replace match with 'undefined'/'None'"]
    H -- "no" --> J["build safeVarName\n__tag_..."]
    J --> K["contextVariables[safeVarName] = tagValue"]
    K --> L["replace match with safeVarName in code"]
    I --> D
    L --> D
    D --> Z

    style B fill:#d4edda,stroke:#28a745
    note1["TAG_PATTERN = createReferencePattern()\n= /&lt;([^&lt;&gt;]+)&gt;/g\n(no ReDoS risk)"]
Loading

Reviews (3): Last reviewed commit: "refactor(security): use createReferenceP..." | Re-trigger Greptile

Matches createReferencePattern() from reference-validation.ts used by the
core executor. Invalid refs handled gracefully by resolveBlockReference.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4e21a08. Configure here.

@waleedlatif1 waleedlatif1 merged commit 0e6ada4 into staging Apr 14, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/san-juan-v5 branch April 14, 2026 03:34
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