Skip to content

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

Draft
scarolan with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-scanning-alerts-4
Draft

Bound image-request matching to eliminate regex backtracking risk#34
scarolan with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-scanning-alerts-4

Conversation

Copilot AI commented Aug 4, 2026

Copy link
Copy Markdown

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
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