Repository navigation
Fix polynomial regex backtracking in server URL and email format checks - #56
Conversation
|
👋 Hello @glenn-jocher, thank you for submitting a
For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀 |
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review
Made with ❤️ by Ultralytics Actions
Reviewed both regex changes in lib/openapi.ts and their callers. The replacements preserve expected behavior while avoiding the described backtracking paths. LGTM.
|
🎉 Excited to see this PR merged—thanks, @glenn-jocher! The regex updates prevent excessive backtracking on crafted server URLs and email strings, and reject empty email domain labels.
A fitting reminder of the impact of this focused improvement. |
Fixes the two
js/polynomial-redosCodeQL alerts inlib/openapi.ts:expandServerUrl:/{([^}]+)}/grescans to the end of the string from every unmatched{, so O(n²) on URLs with many{. Excluding{from the variable name (/{([^{}]+)}/g) keeps each scan bounded. Server variable names never contain braces.stringFormatMatchesemail:[^@\s]+\.[^@\s]+lets both quantifiers compete for dots in the domain.[^@\s.]+(?:\.[^@\s.]+)+is unambiguous. Real addresses match as before; addresses with empty domain labels (a@b..c) are now rejected, which is also correct.Timing on 100 KB crafted inputs: server URL 5040 ms → 0.1 ms, email 1727 ms → 0.4 ms.
bun run lint,typecheck, andtestpass.🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Updated server URL and email-format regexes in
lib/openapi.tsto avoid excessive backtracking on crafted inputs.📊 Key Changes
b..c.🎯 Purpose & Impact