-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Swift: Query for regular expression injection #13660
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
QHelp previews: swift/ql/src/queries/Security/CWE-730/RegexInjection.qhelpRegular expression injectionConstructing a regular expression with unsanitized user input is dangerous, since a malicious user may be able to modify the meaning of the expression. They may be able to cause unexpected program behaviour, or perform a denial-of-service attack. For example, they may provide a regular expression fragment that takes exponential time to evaluate in the worst case. RecommendationBefore embedding user input into a regular expression, use a sanitization function such as ExampleThe following examples construct regular expressions from user input without sanitizing it first:
If user input is used to construct a regular expression it should be sanitized first. This ensures that the user cannot insert characters that have special meanings in regular expressions.
References
|
DCA run LGTM. |
Co-authored-by: Matt Pollard <mattpollard@users.noreply.github.com>
Thanks for the review @mattpollard. I've accepted both of your suggestions. @rdmarsh2 I did your recommended change as well, are you happy to approve this now? |
Adds a query for regular expression injection, that is, constructing a regular expression from unsanitized user input. This is fairly straightforward as the vulnerability is a simple injection issue and we already have a regular expressions library that identifies points where regular expressions are evaluated. It turns out we also want to identify points where regular expressions are constructed in advance of evaluation, so as to get clean and reliable alerts, so we do that as well.
There are a handful of test results that are false positives or not detected. We have follow-up issues to address all of these, and in the case of the false positives I do not believe they will be noisy in real world projects before we address them.
TODO: