Repository navigation
[NEW DATA EXTENSION] http4k request sources and response sinks (Java/Kotlin) #7
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # http4k model limitations | ||
|
|
||
| ## Known limitations | ||
|
|
||
| - `HttpMessage` accessors are modeled as remote sources, so locally constructed responses can also be marked remote. Data extensions cannot restrict these sources to inbound requests or client responses, and they cannot model lambda handler parameters as sources. | ||
| - Response body methods are modeled as HTML sinks without checking the response `Content-Type`. This can report XSS for JSON or plain-text responses; unknown or unset content types also cannot be distinguished from HTML by a data extension. | ||
| - `LensExtractor` methods are modeled as remote sources for every extractor output. This can mark values from local objects or `RequestContextKey` as remote; limiting sources to known lens factories could miss custom lenses. | ||
| - URI update summaries preserve taint on the original `Uri`. They do not distinguish replaced from preserved components, so replacing a tainted component with a constant may still leave the resulting URI tainted. | ||
|
|
||
| Redirect sinks for http4k are handled by the custom Java query in `languages/java/custom/src/http4k/UrlRedirect.ql`, which only treats `Location` header values as redirects. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| # Models for the http4k Kotlin HTTP toolkit core module (`org.http4k:http4k-core`). | ||
| # https://github.com/http4k/http4k | ||
| # | ||
| # Signatures were verified against the compiled http4k-core 5.13.0.0 and 6.58.0.0 jars. | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/java-all | ||
| extensible: sourceModel | ||
| data: | ||
| # Request (and HTTP client response) data. | ||
| - ["org.http4k.core", "HttpMessage", True, "bodyString", "()", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.core", "HttpMessage", True, "getBody", "()", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.core", "HttpMessage", True, "header", "(String)", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.core", "HttpMessage", True, "headerValues", "(String)", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.core", "Request", True, "getUri", "()", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.core", "Request", True, "queries", "(String)", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.core", "Request", True, "query", "(String)", "", "ReturnValue", "remote", "manual"] | ||
| # Kotlin extension functions `Request.form(name)` and `Request.cookie(name)`. | ||
| - ["org.http4k.core.body", "FormBodyKt", False, "form", "(Request,String)", "", "ReturnValue", "remote", "manual"] | ||
| - [ | ||
| "org.http4k.core.cookie", | ||
| "CookieExtensionsKt", | ||
| False, | ||
| "cookie", | ||
| "(Request,String)", | ||
| "", | ||
| "ReturnValue", | ||
| "remote", | ||
| "manual" | ||
| ] | ||
|
|
||
| - addsTo: | ||
| pack: codeql/java-all | ||
| extensible: sinkModel | ||
| data: | ||
| # `Response.body(...)` writes the HTTP response body. http4k responses are not | ||
| # HTML-encoded and the content type cannot be checked by a data extension. | ||
| - ["org.http4k.core", "Response", True, "body", "(Body)", "", "Argument[0]", "html-injection", "manual"] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documented this as a known limitation. Data extensions cannot make the |
||
| - [ | ||
| "org.http4k.core", | ||
| "Response", | ||
| True, | ||
| "body", | ||
| "(InputStream,Long)", | ||
| "", | ||
| "Argument[0]", | ||
| "html-injection", | ||
| "manual" | ||
| ] | ||
| - ["org.http4k.core", "Response", True, "body", "(String)", "", "Argument[0]", "html-injection", "manual"] | ||
| # Response header values. http4k only strips CR/LF from header values from | ||
| # version 6.49.0.0, so `response-splitting` applies to earlier versions. | ||
| # URL redirection is modeled in the custom query because the header name | ||
| # cannot be constrained by a data extension. | ||
| - [ | ||
| "org.http4k.core", | ||
| "Response", | ||
| True, | ||
| "header", | ||
| "(String,String)", | ||
| "", | ||
| "Argument[1]", | ||
| "response-splitting", | ||
| "manual" | ||
| ] | ||
|
felickz marked this conversation as resolved.
Resolved
|
||
| - [ | ||
| "org.http4k.core", | ||
| "Response", | ||
| True, | ||
| "header", | ||
| "(String,String)", | ||
| "", | ||
| "Argument[0]", | ||
| "response-splitting", | ||
| "manual" | ||
| ] | ||
| - [ | ||
| "org.http4k.core", | ||
| "Response", | ||
| True, | ||
| "replaceHeader", | ||
| "(String,String)", | ||
| "", | ||
| "Argument[1]", | ||
| "response-splitting", | ||
| "manual" | ||
| ] | ||
| - [ | ||
| "org.http4k.core", | ||
| "Response", | ||
| True, | ||
| "replaceHeader", | ||
| "(String,String)", | ||
| "", | ||
| "Argument[0]", | ||
| "response-splitting", | ||
| "manual" | ||
| ] | ||
|
|
||
| - addsTo: | ||
| pack: codeql/java-all | ||
| extensible: summaryModel | ||
| data: | ||
| - ["org.http4k.core", "Body", True, "getPayload", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Body", True, "getStream", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Body", True, "getText", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - [ | ||
| "org.http4k.core", | ||
| "Body", | ||
| False, | ||
| "create", | ||
| "(InputStream,Long)", | ||
| "", | ||
| "Argument[0]", | ||
| "ReturnValue", | ||
| "taint", | ||
| "manual" | ||
| ] | ||
| - ["org.http4k.core", "Body", True, "create", "(ByteBuffer)", "", "Argument[0]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Body", False, "create", "(String)", "", "Argument[0]", "ReturnValue", "taint", "manual"] | ||
|
felickz marked this conversation as resolved.
Resolved
|
||
| - [ | ||
| "org.http4k.core", | ||
| "Body$Companion", | ||
| False, | ||
| "create", | ||
| "(InputStream,Long)", | ||
| "", | ||
| "Argument[0]", | ||
| "ReturnValue", | ||
| "taint", | ||
| "manual" | ||
| ] | ||
| - [ | ||
| "org.http4k.core", | ||
| "Body$Companion", | ||
| False, | ||
| "create", | ||
| "(ByteBuffer)", | ||
| "", | ||
| "Argument[0]", | ||
| "ReturnValue", | ||
| "taint", | ||
| "manual" | ||
| ] | ||
| - [ | ||
| "org.http4k.core", | ||
| "Body$Companion", | ||
| False, | ||
| "create", | ||
| "(String)", | ||
| "", | ||
| "Argument[0]", | ||
| "ReturnValue", | ||
| "taint", | ||
| "manual" | ||
| ] | ||
| - ["org.http4k.core", "Uri", False, "getAuthority", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "getFragment", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "getHost", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "getPath", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "getQuery", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
|
felickz marked this conversation as resolved.
Resolved
|
||
| - ["org.http4k.core", "Uri", False, "getScheme", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "getUserInfo", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "toString", "()", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", True, "of", "(String)", "", "Argument[0]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri$Companion", False, "of", "(String)", "", "Argument[0]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "scheme", "(String)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "userInfo", "(String)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "host", "(String)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "port", "(Integer)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "path", "(String)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "query", "(String)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "fragment", "(String)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - ["org.http4k.core", "Uri", False, "authority", "(String)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
| - [ | ||
| "org.http4k.core", | ||
| "UriKt", | ||
| False, | ||
| "queryParametersEncoded", | ||
| "(Uri)", | ||
| "", | ||
| "Argument[0]", | ||
| "ReturnValue", | ||
| "taint", | ||
| "manual" | ||
| ] | ||
| - [ | ||
| "org.http4k.core.cookie", | ||
| "Cookie", | ||
| False, | ||
| "getValue", | ||
| "()", | ||
| "", | ||
| "Argument[this]", | ||
| "ReturnValue", | ||
| "taint", | ||
| "manual" | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Models for the http4k lens API (`org.http4k.lens`, shipped in `org.http4k:http4k-core`). | ||
| # https://www.http4k.org/guide/reference/lens/ | ||
| # | ||
| # Lenses built with `Query`, `Header`, `Path`, `FormField`, `Body`, etc. extract values | ||
| # from an HTTP message via `lens(request)`, `lens.extract(request)` or `lens[request]`. | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/java-all | ||
| extensible: sourceModel | ||
| data: | ||
| - ["org.http4k.lens", "LensExtractor", True, "extract", "(Object)", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.lens", "LensExtractor", True, "get", "(Object)", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.lens", "LensExtractor", True, "invoke", "(Object)", "", "ReturnValue", "remote", "manual"] | ||
|
Comment on lines
+11
to
+13
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documented this as a known limitation. Generic |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Models for the http4k routing extensions (`org.http4k.routing`, shipped in `org.http4k:http4k-core`). | ||
| # | ||
| # `Request.path(name)` returns a path parameter. It is compiled into `RoutingKt` | ||
| # in http4k 5.x and into `ExtensionsKt` in http4k 6.x. | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/java-all | ||
| extensible: sourceModel | ||
| data: | ||
| - ["org.http4k.routing", "ExtensionsKt", False, "path", "(Request,String)", "", "ReturnValue", "remote", "manual"] | ||
| - ["org.http4k.routing", "RoutingKt", False, "path", "(Request,String)", "", "ReturnValue", "remote", "manual"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: languages-java-custom-models | ||
| version: 0.0.1 | ||
| library: true | ||
| extensionTargets: | ||
| codeql/java-all: "*" | ||
| dataExtensions: | ||
| - "**/*.model.yml" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * @name URL redirection from remote source in http4k | ||
| * @description URL redirection based on unvalidated user-input | ||
| * may cause redirection to malicious web sites. | ||
| * @kind path-problem | ||
| * @problem.severity error | ||
| * @security-severity 6.1 | ||
| * @precision high | ||
| * @id java/unvalidated-url-redirection | ||
| * @tags security | ||
| * external/cwe/cwe-601 | ||
| */ | ||
|
|
||
| import java | ||
| import semmle.code.java.dataflow.DataFlow | ||
| import semmle.code.java.dataflow.FlowSources | ||
| import semmle.code.java.dataflow.TaintTracking | ||
| import semmle.code.java.security.UrlRedirect | ||
|
|
||
| private class Http4kResponseLocationSink extends UrlRedirectSink { | ||
| Http4kResponseLocationSink() { | ||
| exists(MethodCall call | | ||
| call.getMethod().getDeclaringType().hasQualifiedName("org.http4k.core", "Response") and | ||
| call.getMethod().hasName(["header", "replaceHeader"]) and | ||
| call.getArgument(0).(CompileTimeConstantExpr).getStringValue().toLowerCase() = "location" and | ||
| this.asExpr() = call.getArgument(1) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| module Http4kUrlRedirectConfig implements DataFlow::ConfigSig { | ||
| predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource } | ||
|
|
||
| predicate isSink(DataFlow::Node sink) { sink instanceof UrlRedirectSink } | ||
|
|
||
| predicate isBarrier(DataFlow::Node node) { node instanceof UrlRedirectSanitizer } | ||
|
|
||
| predicate observeDiffInformedIncrementalMode() { any() } | ||
| } | ||
|
|
||
| module Http4kUrlRedirectFlow = TaintTracking::Global<Http4kUrlRedirectConfig>; | ||
|
|
||
| import Http4kUrlRedirectFlow::PathGraph | ||
|
|
||
| from Http4kUrlRedirectFlow::PathNode source, Http4kUrlRedirectFlow::PathNode sink | ||
| where Http4kUrlRedirectFlow::flowPath(source, sink) | ||
| select sink.getNode(), source, sink, "Untrusted URL redirection depends on a $@.", source.getNode(), | ||
| "user-provided value" |
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.
Documented this as a known limitation in
languages/java/custom/models/README.md. Data extensions cannot narrow theseHttpMessagesources to inbound requests or client responses, and modeling handler parameters requires customized QL.