GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Promote SSRF query from experimental by smowton · Pull Request #5587 · github/codeql Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** A sanitizer for request forgery vulnerabilities. */ | ||
| abstract class RequestForgerySanitizer extends DataFlow::Node { } | ||
|
|
||
| private class HostnameSanitzingPrefix extends CompileTimeConstantExpr { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Don't want to taint the PR discussion, but perhaps this is meant to be HostnameSan(i)tizingPrefix?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This sanitizer is very easy to add to a query and is already used in a few places. We might as well add it to the query here in this PR, I guess. (Possibly also |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,2 @@ | |||
| lgtm,codescanning | |||
| * The server-side request forgery (SSRF) query has been promoted from experimental to the main query pack. Its results will now appear by default. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should we credit the original author in the change note? There was some discussion about whether or not to do this in https://github.com/github/codeql-release-notes/pull/10, but I don't know if that reached a conclusion.
I also think that we should include the query id, we tend to reference queries in change notes by name (id).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The C/C++ team seems to do that:
https://github.com/github/codeql/pull/5256/files#diff-6947ef4ef4cef28d3a7a76c1aec757c8695b621922b33c4a5c00ca443c2558cd
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There are a couple of typos in the qhelp, which should be fixed. Also, we should get a doc review. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@aschackmull comments applied. I've simply sanitised PrimitiveType since there are no primitives that serve as a realistic SSRF vector, credited @porcupineyhairs and copyedited the qhelp. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@shati-patel @felicitymay note this is a promoted experimental query, so docs review should look at the whole query not just parts altered in promoting it from experimental to the main query set. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,2 @@ | |||
| lgtm,codescanning | |||
| * The server-side request forgery (SSRF) query has been promoted from experimental to the main query pack. Its results will now appear by default. Thanks to original experimental query author @porcupineyhairs. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| * The server-side request forgery (SSRF) query has been promoted from experimental to the main query pack. Its results will now appear by default. Thanks to original experimental query author @porcupineyhairs. | |
| * The query "Server Side Request Forgery (SSRF)" (`java/ssrf`) has been promoted from experimental to the main query pack. Its results will now appear by default. Thanks to original experimental query author @porcupineyhairs. |
If it's "server-side" rather than "server side" then the query name should be updated in the query meta-data.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Server-side is better grammar (it's a compound noun), but sources on the internet and in our codebase are inconsistent. I've switched to the hyphenated form throughout here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -5,7 +5,12 @@ import semmle.code.java.frameworks.spring.Spring | |||
| import semmle.code.java.frameworks.JaxWS | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We aim to support extensibility in the security queries, by putting a .qll in semmle.code.java.Security that includes a couple of abstract classes for the most common extensions - in this case I think we should expose sinks, additional steps, and sanitizers for customization.
To do this, I think this entire file should be split in two parts. The ad-hoc and very query specific things can move to the .ql whereas the parts that are needed to support this kind of extension should move to the importable dir.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In particular, the abstract class RequestForgerySink and abstract class RequestForgerySanitizer should be importable. (And their private subclasses should likely live in the file next to those definitions).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@aschackmull all changes applied. I didn't move any code from the .qll file as everything is either a default extension point instance, or is used to implement one. However I did move the file as requested. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Most of my comments highlight fairly trivial inconsistencies. Generally the text seems okay to merge.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| /** | ||
| * @name Server-Side Request Forgery (SSRF) | ||
| * @description Making web requests based on unvalidated user-input | ||
| * may cause server to communicate with malicious servers. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| * may cause server to communicate with malicious servers. | |
| * may allow the server to communicate with malicious servers. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| <p>To guard against SSRF attacks, it is advisable to avoid putting user input | ||
| directly into the request URL. Instead, maintain a list of authorized | ||
| directly into a request URL. Instead, maintain a list of authorized | ||
| URLs on the server; then choose from that list based on the user input provided.</p> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It won't allow me to make a suggestion 😞 This may be clearer as:
To guard against SSRF attacks, you should avoid putting user-provided input
directly into a request URL. Instead, maintain a list of authorized
URLs on the server; then choose from that list based on the input provided.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks @felicitymay, all applied. @aschackmull this is up for review again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| HostnameSanitizingPrefix() { | ||
| exists( | ||
| this.getStringValue() | ||
| .regexpFind(".*([?#]|[^?#:/\\\\][/\\\\]).*|[/\\\\][^/\\\\].*|^/$", 0, offset) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a few examples that this regex will find?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: intrigus-lgtm <[email protected]>
(Models now have internal nodes in order to allow field flow through them)
Co-authored-by: Anders Schack-Mulligen <[email protected]>
Also add tests checking the output of the new function
The improvement is in considering (userSupplied + "/") itself a sanitising prefix.
Previously this didn't catch the case of constructors chaining directly into appends, like `StringBuilder sb = new StringBuilder("1").append("2")`
I also drop the previous approach of taint-tracking through various builder objects in favour of assuming that a URI set in a request-builder object is highly likely to end up requested in some way or another. This will cause the `java/non-https-url` query to pick the new sinks up too, and fixes a Spring case that had never worked but went unnoticed until now.
…ess, and add stubs to support them all.
…els revealed by this process.
….ql; adjust test expectations accordingly
Co-authored-by: Anders Schack-Mulligen <[email protected]>
8d5e1ad to
11b7032
Compare
|
@aschackmull rebased to resolve conflicts with just-merged Jax-WS models. Actual changes: Trivial docs fixes: 1176fec |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.