-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Add SSRF queries #7420
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
Merged
Merged
Python: Add SSRF queries #7420
Conversation
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
Taken from Ruby, except that `getURL` member predicate was changed to `getUrl` to keep consistency with the rest of our concepts, and stick to our naming convention.
For the snippet below, our current query is able to show _why_ we consider `var` to be a falsey value that would disable SSL/TLS verification. I'm not sure we're going to need the part that Ruby did, for being able to specify _where_ the verification was removed, but we'll see. ``` requests.get(url, verify=var) ```
Also adjusts test slightly. Writing `clientRequestDisablesCertValidation=False` to mean that certificate validation was disabled by the `False` expression is just confusing, as it easily reads as _certificate validate was NOT disabled_ :| The new one ties to each request that is being made, which seems like the right setup.
I think `getUrl` is a bit too misleading, since from the name, I would only ever expect ONE result for one request being made. `getAUrlPart` captures that there could be multiple results, and that they might not constitute a whole URl. Which is the same naming I used when I tried to model this a long time ago https://github.com/github/codeql/blob/a80860cdc6b06b363b0d0919600ab383a470b449/python/ql/lib/semmle/python/web/Http.qll#L102-L111
I've added 2 queries: - one that detects full SSRF, where an attacker can control the full URL, which is always bad - and one for partial SSRF, where an attacker can control parts of an URL (such as the path, query parameters, or fragment), which is not a big problem in many cases (but might still be exploitable) full SSRF should run by default, and partial SSRF should not (but makes it easy to see the other results). Some elements of the full SSRF queries needs a bit more polishing, like being able to detect `"https://" + user_input` is in fact controlling the full URL.
yoff
reviewed
Dec 16, 2021
Co-authored-by: yoff <[email protected]>
Since that might not be the same place where the vulnerable URL part is.
Now full-ssrf will only alert if **all** URL parts are fully user-controlled.
They were very misleading before, because a sanitizer that happened early, would remove taint from the rest of the cases by use-use flow :|
Accidentally committed :|
I included examples of both types in the qhelp of both queries, to provide context of what each of them actually are.
yoff
reviewed
Dec 17, 2021
python/ql/test/query-tests/Security/CWE-918-ServerSideRequestForgery/full_partial_test.py
Outdated
Show resolved
Hide resolved
…orgery/full_partial_test.py
yoff
previously approved these changes
Dec 17, 2021
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 - thanks for the offline explanations
That was changed in 9866214
yoff
approved these changes
Dec 17, 2021
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
|
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.
I've added 2 queries:
full SSRF should run by default, and partial SSRF should not (but having the query included makes it easy to run). I got inspired by this setup from Java where they have a precise and imprecise version of the same query.
Current status
Most of the query work/library modeling is done (although we could always add support for more libraries). Still need to do:
"https://" + user_input
is in fact controlling the full URL.Commits
Some of the commits changes the concepts that was added in the very first commit. I've kept things this way so it could help to illustrate why I wanted to diverge from the Ruby code.
What is SSRF even?
See https://portswigger.net/web-security/ssrf if you need a refresher on SSRF 😊