-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Swift: New query for Missing Regular Expression Anchor #14639
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
QHelp previews: swift/ql/src/queries/Security/CWE-020/MissingRegexAnchor.qhelpMissing regular expression anchorSanitizing untrusted input with regular expressions is a common technique, but malicious actors may be able to embed one of the allowed patterns in an unexpected location. To prevent this, you should use anchors in your regular expressions, such as Even if the matching is not done in a security-critical context, it may still cause undesirable behavior when the regular expression accidentally matches. RecommendationUse anchors to ensure that regular expressions match at the expected locations. ExampleThe following example code attempts to check that a URL redirection will reach the
However, this regular expression check can be easily bypassed, and a malicious actor could embed
If you need to write a regular expression to match multiple hosts, you should include an anchor for all of the alternatives. For example, the regular expression References
|
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.
The code LGTM!
Thanks for the quick review. I've added the docs review tag. |
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.
Hey @geoffw0 👋 I've just left some minor suggestions that I think may help the reader—do please let me know what you think and whether you have any questions. My apologies if the suggestions mess up the formatting and you apply them/need to adjust the indentation.
Many thanks!
Co-authored-by: Ben Ahmady <[email protected]>
Co-authored-by: Ben Ahmady <[email protected]>
Hi @subatoi, thank you for your review and suggestions. I've accepted three, the other two I think I'm going to adapt a little... |
Co-authored-by: Ben Ahmady <[email protected]>
Thanks @geoffw0, no problem! Just let me know when you want me to approve again 👍 |
Hi, sorry for the delay on this. I've accepted the other two suggestions and only made one edit in the end - deleting the word "only" where it was incorrect to say that. Thanks again for the review and changes! Ready for approval. |
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.
Thanks again!
DCA run LGTM. I'll merge this when green. |
New Swift query for missing regular expression anchors. This is a port of the existing query from JS (it also exists for Ruby and Go), with most of the query logic residing in the shared and Swift regular expressions libraries. I suggest that reviewers focus on results (e.g. in the tests, which I have also adapted from JS), or compare to other language versions of the query.
The PR also contains qhelp and examples, adapted from JS as well.
TODO: