JS: Detect additional URLs in js/incomplete-url-substring-sanitization when the substring check is an includes check#4054
Merged
codeql-ci merged 5 commits intogithub:mainfrom Aug 17, 2020
Conversation
esbena
requested changes
Aug 13, 2020
| } | ||
| } | ||
|
|
||
| x.startsWith("https://secure.com/foo/bar"); // OK - the trailing slash makes prefix checks safe. |
Contributor
There was a problem hiding this comment.
There is no trailing slash here. Can you reformulate the explanation?
| or | ||
| // target is a HTTP URL to a domain on any TLD with path elements, and the check is an includes check | ||
| check instanceof StringOps::Includes and | ||
| target.regexpMatch("(?i)https?://([a-z0-9-]+\\.)+([a-z]+)(:[0-9]+)?/([a-z0-9-]+/?)*") |
Contributor
There was a problem hiding this comment.
Optional changes (3), pick the ones you want:
- consistency for TLDs
- more permissive paths
- flattening of quantifiers
Suggested change
| target.regexpMatch("(?i)https?://([a-z0-9-]+\\.)+([a-z]+)(:[0-9]+)?/([a-z0-9-]+/?)*") | |
| target.regexpMatch("(?i)https?://([a-z0-9-]+\\.)+" + RegExpPatterns::commonTLD() + "(:[0-9]+)?/[a-z0-9/_-]+") |
Contributor
Author
There was a problem hiding this comment.
I'm going with 2+3.
Co-authored-by: Esben Sparre Andreasen <esbena@github.com>
esbena
approved these changes
Aug 13, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Using an includes check for URLs is just generally bad.
With this PR the
js/incomplete-url-substring-sanitizationis expanded such that URLs that contain path elements are recognized when the substring check is an includes check.I decided to still require that the URL starts with
http://to make very sure that we only match URL checks.