-
Notifications
You must be signed in to change notification settings - Fork 518
SNOW-693548 fixing redos attack #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
So as it turns out the new Regex is now able to find more comments and this has broken this old test. |
2faa971
to
6bc8e9f
Compare
^\s*(?: | ||
/\*[\w\W]*?\*/ | ||
)""", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these new lines and spaces in this regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's easier to read. Here's the doc on re.VERBOSE, it's not a requirement, just wanted it to be readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@sfc-gh-mkeller Looks good overall for the CVE. However, I wonder if there is a potential to exploit this again via some other means. We may want to think about making this robust at a design level. |
Codecov Report
@@ Coverage Diff @@
## main #1327 +/- ##
==========================================
+ Coverage 82.15% 82.22% +0.07%
==========================================
Files 59 60 +1
Lines 8382 8421 +39
Branches 1240 1247 +7
==========================================
+ Hits 6886 6924 +38
Misses 1187 1187
- Partials 309 310 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Please answer these questions before submitting your pull requests. Thanks!
What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-693548
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
This fixes the CVE https://nvd.nist.gov/vuln/detail/CVE-2022-42965
The issue comes from the greediness of the original regex. With this reworked function we have roughly linear performance. This is achieved by starting from the beginning to lazily strip away comments one-by-one instead of matching the whole SQL command with one regex. The new SQL is also better by matching more than multi-line comments.