Update HTTP.qll#95
Conversation
Add more fields to `UserControlledRequestField()`, and more methods to `UserControlledRequestMethod()` on `"net/http".Request`.
|
@sauyon, could you take a look at this? You've most recently been working in these parts. |
|
I'm going to add all Golang web frameworks, one at a time; best starting point is net/http |
| fieldName = "URL" | ||
| fieldName = "URL" or | ||
| fieldName = "Host" or | ||
| fieldName = "Method" or |
There was a problem hiding this comment.
While this one is technically under the attacker's control, it'll have to be a valid HTTP verb, so not too interesting from a taint-tracking perspective.
There was a problem hiding this comment.
HTTP verb validation is kind of out of net/http package scope; the verb will be validated only if the developer will add the validation (third party code).
Catch-all endpoints are not uncommon.
There was a problem hiding this comment.
(again, see example)
There was a problem hiding this comment.
When you say "see example", what are you referring to?
There was a problem hiding this comment.
I'm referring to my first comment in this PR.
There was a problem hiding this comment.
Oh, you mean the PR description. Could you turn that into a test, please?
There was a problem hiding this comment.
Sure. Shall I put the new fields/method inside here: https://github.com/github/codeql-go/blob/master/ql/test/library-tests/semmle/go/frameworks/HTTP/main.go ?
There was a problem hiding this comment.
Or you had another kind of test in mind?
sauyon
left a comment
There was a problem hiding this comment.
Hey! Sorry about the delay, I've been running some tests because I'm somewhat worried about this causing false positives: while catch-all endpoints may be relatively common, we have no way of knowing whether the source is actually from a catch-all endpoint or not with the way the library is structured. That said, perhaps the pattern of using the host or request path in some sensitive way is rare enough that this is a non-issue.
Specifically for our open redirect query, though, an evaluation (internal link) shows a false positive on uber/cockroach, which represents a class of false positives I would like for you to fix; here's the result on LGTM (it's the one in pprofui/server.go).
That should just be a matter of modifying the UntrustedFlowAsSource class in (ql/src/semmle/go/https://github.com/github/codeql-go/blob/master/ql/src/semmle/go/security/OpenUrlRedirectCustomizations.qll)[https://github.com/github/codeql-go/blob/master/ql/src/semmle/go/security/OpenUrlRedirectCustomizations.qll].
| methName = "Referer" or | ||
| methName = "UserAgent" | ||
| methName = "UserAgent" or | ||
| methName = "BasicAuth" |
There was a problem hiding this comment.
| methName = "BasicAuth" | |
| methName = "BasicAuth" |
|
Re: tests, copying your example server into the tests directory should work (you might have to tweak the name of the main function to get it to build). Also, I'd like to see a test for the open URL redirect query as well. |
|
Sorry for the delay!
You are right. While not creating much noise for flows to sinks such as command execution, It's probably better to leave it out.
Do you mean adding codeql-go/ql/src/semmle/go/security/OpenUrlRedirectCustomizations.qll Lines 43 to 52 in 3a39085
You mean adding field read examples here https://github.com/github/codeql-go/blob/master/ql/test/query-tests/Security/CWE-601/OpenUrlRedirect/OpenUrlRedirect.go ? |
ghost
left a comment
There was a problem hiding this comment.
I think the Method,URI and Host fields should not be included by default. See my comment below.
| @@ -0,0 +1,22 @@ | |||
| package main | |||
There was a problem hiding this comment.
The fields here can be merged with main.go There's no need really to write the same boilerplate code here again.
Yep 👍
Would like it here, specifically for the fields that you add to the above. |
|
@gagliardetto, are you still working on this? |
|
I'll reopen this in the future. |
|
Sounds good. |
Add more fields to
UserControlledRequestField(), and more methods toUserControlledRequestMethod()on"net/http".Request.Example server
Example request
Server log of this request: