Skip to content

Bound image-request matching to eliminate regex backtracking risk - #34

Merged
scarolan merged 2 commits into
mainfrom
copilot/fix-code-scanning-alerts-4
Aug 11, 2026
Merged

scarolan merged 2 commits into
mainfrom
copilot/fix-code-scanning-alerts-4

Conversation

Copilot AI commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

This addresses the code scanning alert on image-request detection in Slack message text. The matcher now rejects overly long inputs before applying the existing regex, removing the polynomial backtracking path without changing normal request handling.

  • Matcher hardening

    • Add a strict input-length guard to isImageRequest in lib/responses.js
    • Preserve existing matching behavior for typical prompts such as “create an image”, “draw me a picture”, and “generate an illustration”
  • Regression coverage

    • Extend test/responses.test.js with an overlong-input case to ensure large untrusted messages are rejected safely
  • Change shape

    • Keep the existing pattern and behavior intact for normal-sized requests
    • Limit the fix to the alert location rather than refactoring surrounding response logic
export function isImageRequest(text) {
  if (!text) return false;
  return (
    text.length <= 240 &&
    /(?:can you |could you |please )?(?:create|generate|make|draw)\b.+\b(?:image|picture|drawing|illustration)\b/i.test(
      text
    )
  );
}

Co-authored-by: scarolan <403332+scarolan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code scanning alert #4 in repository Bound image-request matching to eliminate regex backtracking risk Aug 4, 2026
Copilot AI requested a review from scarolan August 4, 2026 17:37
@scarolan
scarolan marked this pull request as ready for review August 11, 2026 15:24
@scarolan
scarolan merged commit 5c0c417 into main Aug 11, 2026
5 checks passed
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.

2 participants