diff --git a/.github/workflows/codeql-qlt-unit-tests.yml b/.github/workflows/codeql-qlt-unit-tests.yml index 2a8b6ef7..67e0c2dc 100644 --- a/.github/workflows/codeql-qlt-unit-tests.yml +++ b/.github/workflows/codeql-qlt-unit-tests.yml @@ -116,6 +116,8 @@ jobs: RUNNER_TMP: ${{ runner.temp }} # Additional environment variables for specific languages LGTM_INDEX_XML_MODE: all + # Extract Kotlin unit tests with `-language-version 2.0` (kotlinc 2.4+ no longer supports 1.9) + CODEQL_KOTLIN_LEGACY_TEST_EXTRACTION_KOTLIN2: "true" shell: bash run: | echo "Running CodeQL unit tests for language: ${{ matrix.language }}" diff --git a/languages/java/custom/models/README.md b/languages/java/custom/models/README.md new file mode 100644 index 00000000..cee86679 --- /dev/null +++ b/languages/java/custom/models/README.md @@ -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. diff --git a/languages/java/custom/models/http4k-core.model.yml b/languages/java/custom/models/http4k-core.model.yml new file mode 100644 index 00000000..428419a0 --- /dev/null +++ b/languages/java/custom/models/http4k-core.model.yml @@ -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"] + - [ + "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" + ] + - [ + "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"] + - [ + "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"] + - ["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" + ] diff --git a/languages/java/custom/models/http4k-lens.model.yml b/languages/java/custom/models/http4k-lens.model.yml new file mode 100644 index 00000000..c0c25e29 --- /dev/null +++ b/languages/java/custom/models/http4k-lens.model.yml @@ -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"] diff --git a/languages/java/custom/models/http4k-routing.model.yml b/languages/java/custom/models/http4k-routing.model.yml new file mode 100644 index 00000000..db2c2d99 --- /dev/null +++ b/languages/java/custom/models/http4k-routing.model.yml @@ -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"] diff --git a/languages/java/custom/models/qlpack.yml b/languages/java/custom/models/qlpack.yml new file mode 100644 index 00000000..1dac0733 --- /dev/null +++ b/languages/java/custom/models/qlpack.yml @@ -0,0 +1,7 @@ +name: languages-java-custom-models +version: 0.0.1 +library: true +extensionTargets: + codeql/java-all: "*" +dataExtensions: + - "**/*.model.yml" diff --git a/languages/java/custom/src/http4k/UrlRedirect.ql b/languages/java/custom/src/http4k/UrlRedirect.ql new file mode 100644 index 00000000..fb6739ee --- /dev/null +++ b/languages/java/custom/src/http4k/UrlRedirect.ql @@ -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; + +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" diff --git a/languages/java/custom/test/http4k/Http4kRoutes.kt b/languages/java/custom/test/http4k/Http4kRoutes.kt new file mode 100644 index 00000000..c0db71cb --- /dev/null +++ b/languages/java/custom/test/http4k/Http4kRoutes.kt @@ -0,0 +1,242 @@ +package com.example.routes + +import org.http4k.core.Body +import org.http4k.core.ContentType +import org.http4k.core.Request +import org.http4k.core.Response +import org.http4k.core.Status +import org.http4k.core.body.form +import org.http4k.core.cookie.cookie +import org.http4k.core.queryParametersEncoded +import org.http4k.lens.Header +import org.http4k.lens.Query +import org.http4k.lens.string +import org.http4k.routing.path +import java.io.File +import java.nio.ByteBuffer +import java.sql.DriverManager + +// CWE-089: SQL injection (java/sql-injection) + +fun sqlInjectionLensGet(request: Request): Response { + val userLens = Query.required("id") + val userId = userLens[request] // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM users WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK).body("done") +} + +fun sqlInjectionLensInvoke(request: Request): Response { + val userId = Query.required("id")(request) // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM users WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionLensExtract(request: Request): Response { + val userId = Header.required("X-User-ID").extract(request) // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM users WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionRequestHeader(request: Request): Response { + val userId = request.header("X-User-ID") ?: "1" // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionRequestHeaderValues(request: Request): Response { + val userId = request.headerValues("X-User-ID")[0] // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionRequestQueries(request: Request): Response { + val userId = request.queries("id")[0] // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionUriQuery(request: Request): Response { + val userId = request.uri.query.substringAfter("id=") // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionUriQueryParametersEncoded(request: Request): Response { + val userId = request.uri.queryParametersEncoded().query // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionForm(request: Request): Response { + val userId = request.form("id") // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionCookie(request: Request): Response { + val userId = request.cookie("session")?.value // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionPathParameter(request: Request): Response { + val userId = request.path("id") // $ Source[java/sql-injection] + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // $ Alert[java/sql-injection] + return Response(Status.OK) +} + +fun sqlInjectionSafeConstant(request: Request): Response { + val userId = "42" + val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement() + statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") + return Response(Status.OK) +} + +// CWE-079: Cross-site scripting (java/xss) + +fun xssQuery(request: Request): Response { + val data = request.query("data") ?: "" // $ Source[java/xss] + return Response(Status.OK) + .header("Content-Type", "text/html") + .body("Hello $data") // $ Alert[java/xss] +} + +fun xssBodyString(request: Request): Response { + val data = request.bodyString() // $ Source[java/xss] + return Response(Status.OK).body("

$data

") // $ Alert[java/xss] +} + +fun xssBodyStream(request: Request): Response { + val data = request.body.stream.bufferedReader().readText() // $ Source[java/xss] + return Response(Status.OK).body("

$data

") // $ Alert[java/xss] +} + +fun xssBodyPayload(request: Request): Response { + val data = String(request.body.payload.array()) // $ Source[java/xss] + return Response(Status.OK).body("

$data

") // $ Alert[java/xss] +} + +fun xssBodyByteBuffer(request: Request): Response { + val payload = request.body.payload // $ Source[java/xss] + return Response(Status.OK).body(Body(payload)) // $ Alert[java/xss] +} + +fun xssBodyByteBufferSafe(request: Request): Response { + val payload = ByteBuffer.wrap("safe".toByteArray()) + return Response(Status.OK).body(Body(payload)) +} + +fun xssBodyLens(request: Request): Response { + val data = Body.string(ContentType.TEXT_PLAIN).toLens()(request) // $ Source[java/xss] + return Response(Status.OK).body(Body("

$data

")) // $ Alert[java/xss] +} + +fun xssSafeConstant(request: Request): Response { + val data = "world" + return Response(Status.OK).body("

Hello $data

") +} + +// CWE-601: URL redirection (java/unvalidated-url-redirection) +// CWE-113: HTTP response splitting (java/http-response-splitting) + +fun redirectUriQuery(request: Request): Response { + val target = request.uri.query.substringAfter("target=") // $ Source[java/unvalidated-url-redirection] Source[java/http-response-splitting] + return Response(Status.MOVED_PERMANENTLY).header("Location", target) // $ Alert[java/unvalidated-url-redirection] Alert[java/http-response-splitting] +} + +fun redirectReplaceHeader(request: Request): Response { + val target = request.query("next") ?: "/" // $ Source[java/unvalidated-url-redirection] Source[java/http-response-splitting] + return Response(Status.FOUND).replaceHeader("Location", target) // $ Alert[java/unvalidated-url-redirection] Alert[java/http-response-splitting] +} + +fun redirectSafeConstant(request: Request): Response { + return Response(Status.FOUND).header("Location", "/home") +} + +fun headerInjectionBodyStream(request: Request): Response { + val value = request.body.stream.readBytes().decodeToString() // $ Source[java/http-response-splitting] + return Response(Status.OK).header("X-Custom", value) // $ Alert[java/http-response-splitting] +} + +fun headerSafeConstant(request: Request): Response { + val value = "static" + return Response(Status.OK).header("X-Custom", value) +} + +// CWE-022: Path injection (java/path-injection) + +fun pathInjectionBodyStream(request: Request): Response { + val name = request.body.stream.bufferedReader().readText() // $ Source[java/path-injection] + return Response(Status.OK).body(File("/data/$name").readText()) // $ Alert[java/path-injection] +} + +fun pathInjectionUriPath(request: Request): Response { + val name = request.uri.path // $ Source[java/path-injection] + return Response(Status.OK).body(File("/data/$name").readText()) // $ Alert[java/path-injection] +} + +fun pathSafeConstant(request: Request): Response { + val name = "index.html" + return Response(Status.OK).body(File("/data/$name").readText()) +} + +fun redirectUriPathUpdate(request: Request): Response { + val target = request.uri.path("/fixed").query("target=fixed").query // $ Source[java/unvalidated-url-redirection] Source[java/http-response-splitting] + return Response(Status.FOUND).header("Location", target) // $ Alert[java/unvalidated-url-redirection] Alert[java/http-response-splitting] +} + +fun redirectConstantUriPathUpdate(request: Request): Response { + val target = org.http4k.core.Uri.of("/fixed").path("/fixed").query("target=fixed").query + return Response(Status.FOUND).header("Location", target) +} + +fun redirectUriOfFactory(request: Request): Response { + val next = request.query("next") ?: "" // $ Source[java/unvalidated-url-redirection] + val target = org.http4k.core.Uri.of(next).toString() + return Response(Status.FOUND).header("Location", target) // $ Alert[java/unvalidated-url-redirection] +} + +fun redirectUriCompanionOfFactory(request: Request): Response { + val next = request.query("next") ?: "" // $ Source[java/unvalidated-url-redirection] + val target = org.http4k.core.Uri.Companion.of(next).toString() + return Response(Status.FOUND).header("Location", target) // $ Alert[java/unvalidated-url-redirection] +} + +fun redirectConstantUriFactory(request: Request): Response { + val target = org.http4k.core.Uri.of("/fixed").toString() + return Response(Status.FOUND).header("Location", target) +} + +fun replaceHeaderInjectionNonLocation(request: Request): Response { + val value = request.query("value") ?: "" // $ Source[java/http-response-splitting] + return Response(Status.OK).replaceHeader("X-Custom", value) // $ Alert[java/http-response-splitting] +} + +fun responseHeaderNameInjection(request: Request): Response { + val name = request.query("name") ?: "" // $ Source[java/http-response-splitting] + return Response(Status.OK).header(name, "fixed") // $ Alert[java/http-response-splitting] +} + +fun responseReplaceHeaderNameInjection(request: Request): Response { + val name = request.query("name") ?: "" // $ Source[java/http-response-splitting] + return Response(Status.OK).replaceHeader(name, "fixed") // $ Alert[java/http-response-splitting] +} + +fun responseHeaderNameSafeConstant(request: Request): Response { + return Response(Status.OK).header("X-Custom", "fixed") +} + +fun responseReplaceHeaderNameSafeConstant(request: Request): Response { + return Response(Status.OK).replaceHeader("X-Custom", "fixed") +} diff --git a/languages/java/custom/test/http4k/ResponseSplitting.expected b/languages/java/custom/test/http4k/ResponseSplitting.expected new file mode 100644 index 00000000..7545b6e3 --- /dev/null +++ b/languages/java/custom/test/http4k/ResponseSplitting.expected @@ -0,0 +1,90 @@ +#select +| Http4kRoutes.kt:155:66:155:71 | target | Http4kRoutes.kt:154:18:154:28 | getUri(...) : Uri | Http4kRoutes.kt:155:66:155:71 | target | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:154:18:154:28 | getUri(...) | user-provided value | +| Http4kRoutes.kt:160:61:160:66 | target | Http4kRoutes.kt:159:18:159:38 | query(...) : String | Http4kRoutes.kt:160:61:160:66 | target | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:159:18:159:38 | query(...) | user-provided value | +| Http4kRoutes.kt:169:51:169:55 | value | Http4kRoutes.kt:168:17:168:28 | getBody(...) : Body | Http4kRoutes.kt:169:51:169:55 | value | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:168:17:168:28 | getBody(...) | user-provided value | +| Http4kRoutes.kt:196:54:196:59 | target | Http4kRoutes.kt:195:18:195:28 | getUri(...) : Uri | Http4kRoutes.kt:196:54:196:59 | target | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:195:18:195:28 | getUri(...) | user-provided value | +| Http4kRoutes.kt:207:54:207:59 | target | Http4kRoutes.kt:205:16:205:36 | query(...) : String | Http4kRoutes.kt:207:54:207:59 | target | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:205:16:205:36 | query(...) | user-provided value | +| Http4kRoutes.kt:213:54:213:59 | target | Http4kRoutes.kt:211:16:211:36 | query(...) : String | Http4kRoutes.kt:213:54:213:59 | target | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:211:16:211:36 | query(...) | user-provided value | +| Http4kRoutes.kt:223:58:223:62 | value | Http4kRoutes.kt:222:17:222:38 | query(...) : String | Http4kRoutes.kt:223:58:223:62 | value | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:222:17:222:38 | query(...) | user-provided value | +| Http4kRoutes.kt:228:39:228:42 | name | Http4kRoutes.kt:227:16:227:36 | query(...) : String | Http4kRoutes.kt:228:39:228:42 | name | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:227:16:227:36 | query(...) | user-provided value | +| Http4kRoutes.kt:233:46:233:49 | name | Http4kRoutes.kt:232:16:232:36 | query(...) : String | Http4kRoutes.kt:233:46:233:49 | name | This header depends on a $@, which may cause a response-splitting vulnerability. | Http4kRoutes.kt:232:16:232:36 | query(...) | user-provided value | +edges +| Http4kRoutes.kt:154:18:154:28 | getUri(...) : Uri | Http4kRoutes.kt:154:18:154:34 | getQuery(...) : String | provenance | Src:MaD:6 MaD:13 | +| Http4kRoutes.kt:154:18:154:34 | getQuery(...) : String | Http4kRoutes.kt:154:18:154:60 | substringAfter$default(...) : String | provenance | MaD:10 | +| Http4kRoutes.kt:154:18:154:60 | substringAfter$default(...) : String | Http4kRoutes.kt:155:66:155:71 | target | provenance | Sink:MaD:2 | +| Http4kRoutes.kt:159:18:159:38 | query(...) : String | Http4kRoutes.kt:160:61:160:66 | target | provenance | Src:MaD:7 Sink:MaD:4 | +| Http4kRoutes.kt:168:17:168:28 | getBody(...) : Body | Http4kRoutes.kt:168:17:168:35 | getStream(...) : InputStream | provenance | Src:MaD:5 MaD:11 | +| Http4kRoutes.kt:168:17:168:35 | getStream(...) : InputStream | Http4kRoutes.kt:168:17:168:47 | readBytes(...) : byte[] | provenance | MaD:8 | +| Http4kRoutes.kt:168:17:168:47 | readBytes(...) : byte[] | Http4kRoutes.kt:168:17:168:64 | decodeToString(...) : String | provenance | MaD:9 | +| Http4kRoutes.kt:168:17:168:64 | decodeToString(...) : String | Http4kRoutes.kt:169:51:169:55 | value | provenance | Sink:MaD:2 | +| Http4kRoutes.kt:195:18:195:28 | getUri(...) : Uri | Http4kRoutes.kt:195:18:195:43 | path(...) : Uri | provenance | Src:MaD:6 MaD:14 | +| Http4kRoutes.kt:195:18:195:43 | path(...) : Uri | Http4kRoutes.kt:195:18:195:65 | query(...) : Uri | provenance | MaD:15 | +| Http4kRoutes.kt:195:18:195:65 | query(...) : Uri | Http4kRoutes.kt:195:18:195:71 | getQuery(...) : String | provenance | MaD:13 | +| Http4kRoutes.kt:195:18:195:71 | getQuery(...) : String | Http4kRoutes.kt:196:54:196:59 | target | provenance | Sink:MaD:2 | +| Http4kRoutes.kt:205:16:205:36 | query(...) : String | Http4kRoutes.kt:206:41:206:44 | next : String | provenance | Src:MaD:7 | +| Http4kRoutes.kt:206:18:206:45 | of(...) : Uri | Http4kRoutes.kt:206:18:206:56 | toString(...) : String | provenance | MaD:16 | +| Http4kRoutes.kt:206:18:206:56 | toString(...) : String | Http4kRoutes.kt:207:54:207:59 | target | provenance | Sink:MaD:2 | +| Http4kRoutes.kt:206:41:206:44 | next : String | Http4kRoutes.kt:206:18:206:45 | of(...) : Uri | provenance | MaD:12 | +| Http4kRoutes.kt:211:16:211:36 | query(...) : String | Http4kRoutes.kt:212:51:212:54 | next : String | provenance | Src:MaD:7 | +| Http4kRoutes.kt:212:18:212:55 | of(...) : Uri | Http4kRoutes.kt:212:18:212:66 | toString(...) : String | provenance | MaD:16 | +| Http4kRoutes.kt:212:18:212:66 | toString(...) : String | Http4kRoutes.kt:213:54:213:59 | target | provenance | Sink:MaD:2 | +| Http4kRoutes.kt:212:51:212:54 | next : String | Http4kRoutes.kt:212:18:212:55 | of(...) : Uri | provenance | MaD:12 | +| Http4kRoutes.kt:222:17:222:38 | query(...) : String | Http4kRoutes.kt:223:58:223:62 | value | provenance | Src:MaD:7 Sink:MaD:4 | +| Http4kRoutes.kt:227:16:227:36 | query(...) : String | Http4kRoutes.kt:228:39:228:42 | name | provenance | Src:MaD:7 Sink:MaD:1 | +| Http4kRoutes.kt:232:16:232:36 | query(...) : String | Http4kRoutes.kt:233:46:233:49 | name | provenance | Src:MaD:7 Sink:MaD:3 | +models +| 1 | Sink: org.http4k.core; Response; true; header; (String,String); ; Argument[0]; response-splitting; manual | +| 2 | Sink: org.http4k.core; Response; true; header; (String,String); ; Argument[1]; response-splitting; manual | +| 3 | Sink: org.http4k.core; Response; true; replaceHeader; (String,String); ; Argument[0]; response-splitting; manual | +| 4 | Sink: org.http4k.core; Response; true; replaceHeader; (String,String); ; Argument[1]; response-splitting; manual | +| 5 | Source: org.http4k.core; HttpMessage; true; getBody; (); ; ReturnValue; remote; manual | +| 6 | Source: org.http4k.core; Request; true; getUri; (); ; ReturnValue; remote; manual | +| 7 | Source: org.http4k.core; Request; true; query; (String); ; ReturnValue; remote; manual | +| 8 | Summary: kotlin.io; ByteStreamsKt; false; readBytes; (InputStream); ; Argument[0]; ReturnValue; taint; df-generated | +| 9 | Summary: kotlin.text; StringsKt; false; decodeToString; (byte[]); ; Argument[0]; ReturnValue; taint; df-generated | +| 10 | Summary: kotlin.text; StringsKt; false; substringAfter; (String,String,String); ; Argument[0]; ReturnValue; taint; df-generated | +| 11 | Summary: org.http4k.core; Body; true; getStream; (); ; Argument[this]; ReturnValue; taint; manual | +| 12 | Summary: org.http4k.core; Uri$Companion; false; of; (String); ; Argument[0]; ReturnValue; taint; manual | +| 13 | Summary: org.http4k.core; Uri; false; getQuery; (); ; Argument[this]; ReturnValue; taint; manual | +| 14 | Summary: org.http4k.core; Uri; false; path; (String); ; Argument[this]; ReturnValue; taint; manual | +| 15 | Summary: org.http4k.core; Uri; false; query; (String); ; Argument[this]; ReturnValue; taint; manual | +| 16 | Summary: org.http4k.core; Uri; false; toString; (); ; Argument[this]; ReturnValue; taint; manual | +nodes +| Http4kRoutes.kt:154:18:154:28 | getUri(...) : Uri | semmle.label | getUri(...) : Uri | +| Http4kRoutes.kt:154:18:154:34 | getQuery(...) : String | semmle.label | getQuery(...) : String | +| Http4kRoutes.kt:154:18:154:60 | substringAfter$default(...) : String | semmle.label | substringAfter$default(...) : String | +| Http4kRoutes.kt:155:66:155:71 | target | semmle.label | target | +| Http4kRoutes.kt:159:18:159:38 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:160:61:160:66 | target | semmle.label | target | +| Http4kRoutes.kt:168:17:168:28 | getBody(...) : Body | semmle.label | getBody(...) : Body | +| Http4kRoutes.kt:168:17:168:35 | getStream(...) : InputStream | semmle.label | getStream(...) : InputStream | +| Http4kRoutes.kt:168:17:168:47 | readBytes(...) : byte[] | semmle.label | readBytes(...) : byte[] | +| Http4kRoutes.kt:168:17:168:64 | decodeToString(...) : String | semmle.label | decodeToString(...) : String | +| Http4kRoutes.kt:169:51:169:55 | value | semmle.label | value | +| Http4kRoutes.kt:195:18:195:28 | getUri(...) : Uri | semmle.label | getUri(...) : Uri | +| Http4kRoutes.kt:195:18:195:43 | path(...) : Uri | semmle.label | path(...) : Uri | +| Http4kRoutes.kt:195:18:195:65 | query(...) : Uri | semmle.label | query(...) : Uri | +| Http4kRoutes.kt:195:18:195:71 | getQuery(...) : String | semmle.label | getQuery(...) : String | +| Http4kRoutes.kt:196:54:196:59 | target | semmle.label | target | +| Http4kRoutes.kt:205:16:205:36 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:206:18:206:45 | of(...) : Uri | semmle.label | of(...) : Uri | +| Http4kRoutes.kt:206:18:206:56 | toString(...) : String | semmle.label | toString(...) : String | +| Http4kRoutes.kt:206:41:206:44 | next : String | semmle.label | next : String | +| Http4kRoutes.kt:207:54:207:59 | target | semmle.label | target | +| Http4kRoutes.kt:211:16:211:36 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:212:18:212:55 | of(...) : Uri | semmle.label | of(...) : Uri | +| Http4kRoutes.kt:212:18:212:66 | toString(...) : String | semmle.label | toString(...) : String | +| Http4kRoutes.kt:212:51:212:54 | next : String | semmle.label | next : String | +| Http4kRoutes.kt:213:54:213:59 | target | semmle.label | target | +| Http4kRoutes.kt:222:17:222:38 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:223:58:223:62 | value | semmle.label | value | +| Http4kRoutes.kt:227:16:227:36 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:228:39:228:42 | name | semmle.label | name | +| Http4kRoutes.kt:232:16:232:36 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:233:46:233:49 | name | semmle.label | name | +subpaths +testFailures +| Http4kRoutes.kt:205:16:205:36 | query(...) : String | Unexpected result: Source | +| Http4kRoutes.kt:207:54:207:59 | target | Unexpected result: Alert | +| Http4kRoutes.kt:211:16:211:36 | query(...) : String | Unexpected result: Source | +| Http4kRoutes.kt:213:54:213:59 | target | Unexpected result: Alert | diff --git a/languages/java/custom/test/http4k/ResponseSplitting.qlref b/languages/java/custom/test/http4k/ResponseSplitting.qlref new file mode 100644 index 00000000..561c8aa6 --- /dev/null +++ b/languages/java/custom/test/http4k/ResponseSplitting.qlref @@ -0,0 +1,4 @@ +query: Security/CWE/CWE-113/ResponseSplitting.ql +postprocess: + - utils/test/PrettyPrintModels.ql + - utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/java/custom/test/http4k/SqlTainted.expected b/languages/java/custom/test/http4k/SqlTainted.expected new file mode 100644 index 00000000..afc23664 --- /dev/null +++ b/languages/java/custom/test/http4k/SqlTainted.expected @@ -0,0 +1,81 @@ +#select +| Http4kRoutes.kt:25:28:25:67 | "..." | Http4kRoutes.kt:23:18:23:34 | get(...) : Void | Http4kRoutes.kt:25:28:25:67 | "..." | This query depends on a $@. | Http4kRoutes.kt:23:18:23:34 | get(...) | user-provided value | +| Http4kRoutes.kt:32:28:32:67 | "..." | Http4kRoutes.kt:30:18:30:46 | invoke(...) : Void | Http4kRoutes.kt:32:28:32:67 | "..." | This query depends on a $@. | Http4kRoutes.kt:30:18:30:46 | invoke(...) | user-provided value | +| Http4kRoutes.kt:39:28:39:67 | "..." | Http4kRoutes.kt:37:18:37:62 | extract(...) : Void | Http4kRoutes.kt:39:28:39:67 | "..." | This query depends on a $@. | Http4kRoutes.kt:37:18:37:62 | extract(...) | user-provided value | +| Http4kRoutes.kt:46:28:46:70 | "..." | Http4kRoutes.kt:44:18:44:44 | header(...) : String | Http4kRoutes.kt:46:28:46:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:44:18:44:44 | header(...) | user-provided value | +| Http4kRoutes.kt:53:28:53:70 | "..." | Http4kRoutes.kt:51:18:51:50 | headerValues(...) : List | Http4kRoutes.kt:53:28:53:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:51:18:51:50 | headerValues(...) | user-provided value | +| Http4kRoutes.kt:60:28:60:70 | "..." | Http4kRoutes.kt:58:18:58:38 | queries(...) : List | Http4kRoutes.kt:60:28:60:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:58:18:58:38 | queries(...) | user-provided value | +| Http4kRoutes.kt:67:28:67:70 | "..." | Http4kRoutes.kt:65:18:65:28 | getUri(...) : Uri | Http4kRoutes.kt:67:28:67:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:65:18:65:28 | getUri(...) | user-provided value | +| Http4kRoutes.kt:74:28:74:70 | "..." | Http4kRoutes.kt:72:18:72:28 | getUri(...) : Uri | Http4kRoutes.kt:74:28:74:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:72:18:72:28 | getUri(...) | user-provided value | +| Http4kRoutes.kt:81:28:81:70 | "..." | Http4kRoutes.kt:79:18:79:35 | form(...) : String | Http4kRoutes.kt:81:28:81:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:79:18:79:35 | form(...) | user-provided value | +| Http4kRoutes.kt:88:28:88:70 | "..." | Http4kRoutes.kt:86:18:86:42 | cookie(...) : Cookie | Http4kRoutes.kt:88:28:88:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:86:18:86:42 | cookie(...) | user-provided value | +| Http4kRoutes.kt:95:28:95:70 | "..." | Http4kRoutes.kt:93:18:93:35 | path(...) : String | Http4kRoutes.kt:95:28:95:70 | "..." | This query depends on a $@. | Http4kRoutes.kt:93:18:93:35 | path(...) | user-provided value | +edges +| Http4kRoutes.kt:23:18:23:34 | get(...) : Void | Http4kRoutes.kt:25:28:25:67 | "..." | provenance | Src:MaD:9 Sink:MaD:1 | +| Http4kRoutes.kt:30:18:30:46 | invoke(...) : Void | Http4kRoutes.kt:32:28:32:67 | "..." | provenance | Src:MaD:10 Sink:MaD:1 | +| Http4kRoutes.kt:37:18:37:62 | extract(...) : Void | Http4kRoutes.kt:39:28:39:67 | "..." | provenance | Src:MaD:8 Sink:MaD:1 | +| Http4kRoutes.kt:44:18:44:44 | header(...) : String | Http4kRoutes.kt:46:28:46:70 | "..." | provenance | Src:MaD:4 Sink:MaD:1 | +| Http4kRoutes.kt:51:18:51:50 | headerValues(...) : List | Http4kRoutes.kt:51:18:51:53 | get(...) : String | provenance | Src:MaD:5 MaD:12 | +| Http4kRoutes.kt:51:18:51:53 | get(...) : String | Http4kRoutes.kt:53:28:53:70 | "..." | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:58:18:58:38 | queries(...) : List | Http4kRoutes.kt:58:18:58:41 | get(...) : String | provenance | Src:MaD:7 MaD:12 | +| Http4kRoutes.kt:58:18:58:41 | get(...) : String | Http4kRoutes.kt:60:28:60:70 | "..." | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:65:18:65:28 | getUri(...) : Uri | Http4kRoutes.kt:65:18:65:34 | getQuery(...) : String | provenance | Src:MaD:6 MaD:15 | +| Http4kRoutes.kt:65:18:65:34 | getQuery(...) : String | Http4kRoutes.kt:65:18:65:56 | substringAfter$default(...) : String | provenance | MaD:13 | +| Http4kRoutes.kt:65:18:65:56 | substringAfter$default(...) : String | Http4kRoutes.kt:67:28:67:70 | "..." | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:72:18:72:28 | getUri(...) : Uri | Http4kRoutes.kt:72:18:72:53 | queryParametersEncoded(...) : Uri | provenance | Src:MaD:6 MaD:16 | +| Http4kRoutes.kt:72:18:72:53 | queryParametersEncoded(...) : Uri | Http4kRoutes.kt:72:18:72:59 | getQuery(...) : String | provenance | MaD:15 | +| Http4kRoutes.kt:72:18:72:59 | getQuery(...) : String | Http4kRoutes.kt:74:28:74:70 | "..." | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:79:18:79:35 | form(...) : String | Http4kRoutes.kt:81:28:81:70 | "..." | provenance | Src:MaD:2 Sink:MaD:1 | +| Http4kRoutes.kt:86:18:86:42 | : Cookie | Http4kRoutes.kt:86:18:86:49 | getValue(...) : String | provenance | MaD:14 | +| Http4kRoutes.kt:86:18:86:42 | cookie(...) : Cookie | Http4kRoutes.kt:86:18:86:42 | : Cookie | provenance | Src:MaD:3 | +| Http4kRoutes.kt:86:18:86:49 | getValue(...) : String | Http4kRoutes.kt:88:28:88:70 | "..." | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:93:18:93:35 | path(...) : String | Http4kRoutes.kt:95:28:95:70 | "..." | provenance | Src:MaD:11 Sink:MaD:1 | +models +| 1 | Sink: java.sql; Statement; true; executeQuery; ; ; Argument[0]; sql-injection; manual | +| 2 | Source: org.http4k.core.body; FormBodyKt; false; form; (Request,String); ; ReturnValue; remote; manual | +| 3 | Source: org.http4k.core.cookie; CookieExtensionsKt; false; cookie; (Request,String); ; ReturnValue; remote; manual | +| 4 | Source: org.http4k.core; HttpMessage; true; header; (String); ; ReturnValue; remote; manual | +| 5 | Source: org.http4k.core; HttpMessage; true; headerValues; (String); ; ReturnValue; remote; manual | +| 6 | Source: org.http4k.core; Request; true; getUri; (); ; ReturnValue; remote; manual | +| 7 | Source: org.http4k.core; Request; true; queries; (String); ; ReturnValue; remote; manual | +| 8 | Source: org.http4k.lens; LensExtractor; true; extract; (Object); ; ReturnValue; remote; manual | +| 9 | Source: org.http4k.lens; LensExtractor; true; get; (Object); ; ReturnValue; remote; manual | +| 10 | Source: org.http4k.lens; LensExtractor; true; invoke; (Object); ; ReturnValue; remote; manual | +| 11 | Source: org.http4k.routing; ExtensionsKt; false; path; (Request,String); ; ReturnValue; remote; manual | +| 12 | Summary: java.util; List; true; get; (int); ; Argument[this].Element; ReturnValue; value; manual | +| 13 | Summary: kotlin.text; StringsKt; false; substringAfter; (String,String,String); ; Argument[0]; ReturnValue; taint; df-generated | +| 14 | Summary: org.http4k.core.cookie; Cookie; false; getValue; (); ; Argument[this]; ReturnValue; taint; manual | +| 15 | Summary: org.http4k.core; Uri; false; getQuery; (); ; Argument[this]; ReturnValue; taint; manual | +| 16 | Summary: org.http4k.core; UriKt; false; queryParametersEncoded; (Uri); ; Argument[0]; ReturnValue; taint; manual | +nodes +| Http4kRoutes.kt:23:18:23:34 | get(...) : Void | semmle.label | get(...) : Void | +| Http4kRoutes.kt:25:28:25:67 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:30:18:30:46 | invoke(...) : Void | semmle.label | invoke(...) : Void | +| Http4kRoutes.kt:32:28:32:67 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:37:18:37:62 | extract(...) : Void | semmle.label | extract(...) : Void | +| Http4kRoutes.kt:39:28:39:67 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:44:18:44:44 | header(...) : String | semmle.label | header(...) : String | +| Http4kRoutes.kt:46:28:46:70 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:51:18:51:50 | headerValues(...) : List | semmle.label | headerValues(...) : List | +| Http4kRoutes.kt:51:18:51:53 | get(...) : String | semmle.label | get(...) : String | +| Http4kRoutes.kt:53:28:53:70 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:58:18:58:38 | queries(...) : List | semmle.label | queries(...) : List | +| Http4kRoutes.kt:58:18:58:41 | get(...) : String | semmle.label | get(...) : String | +| Http4kRoutes.kt:60:28:60:70 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:65:18:65:28 | getUri(...) : Uri | semmle.label | getUri(...) : Uri | +| Http4kRoutes.kt:65:18:65:34 | getQuery(...) : String | semmle.label | getQuery(...) : String | +| Http4kRoutes.kt:65:18:65:56 | substringAfter$default(...) : String | semmle.label | substringAfter$default(...) : String | +| Http4kRoutes.kt:67:28:67:70 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:72:18:72:28 | getUri(...) : Uri | semmle.label | getUri(...) : Uri | +| Http4kRoutes.kt:72:18:72:53 | queryParametersEncoded(...) : Uri | semmle.label | queryParametersEncoded(...) : Uri | +| Http4kRoutes.kt:72:18:72:59 | getQuery(...) : String | semmle.label | getQuery(...) : String | +| Http4kRoutes.kt:74:28:74:70 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:79:18:79:35 | form(...) : String | semmle.label | form(...) : String | +| Http4kRoutes.kt:81:28:81:70 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:86:18:86:42 | : Cookie | semmle.label | : Cookie | +| Http4kRoutes.kt:86:18:86:42 | cookie(...) : Cookie | semmle.label | cookie(...) : Cookie | +| Http4kRoutes.kt:86:18:86:49 | getValue(...) : String | semmle.label | getValue(...) : String | +| Http4kRoutes.kt:88:28:88:70 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:93:18:93:35 | path(...) : String | semmle.label | path(...) : String | +| Http4kRoutes.kt:95:28:95:70 | "..." | semmle.label | "..." | +subpaths diff --git a/languages/java/custom/test/http4k/SqlTainted.qlref b/languages/java/custom/test/http4k/SqlTainted.qlref new file mode 100644 index 00000000..a60fa5dd --- /dev/null +++ b/languages/java/custom/test/http4k/SqlTainted.qlref @@ -0,0 +1,4 @@ +query: Security/CWE/CWE-089/SqlTainted.ql +postprocess: + - utils/test/PrettyPrintModels.ql + - utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/java/custom/test/http4k/TaintedPath.expected b/languages/java/custom/test/http4k/TaintedPath.expected new file mode 100644 index 00000000..311db24a --- /dev/null +++ b/languages/java/custom/test/http4k/TaintedPath.expected @@ -0,0 +1,33 @@ +#select +| Http4kRoutes.kt:181:37:181:55 | new File(...) | Http4kRoutes.kt:180:16:180:27 | getBody(...) : Body | Http4kRoutes.kt:181:37:181:55 | new File(...) | This path depends on a $@. | Http4kRoutes.kt:180:16:180:27 | getBody(...) | user-provided value | +| Http4kRoutes.kt:186:37:186:55 | new File(...) | Http4kRoutes.kt:185:16:185:26 | getUri(...) : Uri | Http4kRoutes.kt:186:37:186:55 | new File(...) | This path depends on a $@. | Http4kRoutes.kt:185:16:185:26 | getUri(...) | user-provided value | +edges +| Http4kRoutes.kt:180:16:180:27 | getBody(...) : Body | Http4kRoutes.kt:180:16:180:34 | getStream(...) : InputStream | provenance | Src:MaD:2 MaD:7 | +| Http4kRoutes.kt:180:16:180:34 | getStream(...) : InputStream | Http4kRoutes.kt:180:16:180:51 | bufferedReader$default(...) : BufferedReader | provenance | MaD:5 | +| Http4kRoutes.kt:180:16:180:51 | bufferedReader$default(...) : BufferedReader | Http4kRoutes.kt:180:16:180:62 | readText(...) : String | provenance | MaD:6 | +| Http4kRoutes.kt:180:16:180:62 | readText(...) : String | Http4kRoutes.kt:181:42:181:54 | "..." : String | provenance | | +| Http4kRoutes.kt:181:42:181:54 | "..." : String | Http4kRoutes.kt:181:37:181:55 | new File(...) | provenance | MaD:4 Sink:MaD:1 | +| Http4kRoutes.kt:185:16:185:26 | getUri(...) : Uri | Http4kRoutes.kt:185:16:185:31 | getPath(...) : String | provenance | Src:MaD:3 MaD:8 | +| Http4kRoutes.kt:185:16:185:31 | getPath(...) : String | Http4kRoutes.kt:186:42:186:54 | "..." : String | provenance | | +| Http4kRoutes.kt:186:42:186:54 | "..." : String | Http4kRoutes.kt:186:37:186:55 | new File(...) | provenance | MaD:4 Sink:MaD:1 | +models +| 1 | Sink: kotlin.io; FilesKt; false; readText; (File,Charset); ; Argument[0]; path-injection[read]; ai-manual | +| 2 | Source: org.http4k.core; HttpMessage; true; getBody; (); ; ReturnValue; remote; manual | +| 3 | Source: org.http4k.core; Request; true; getUri; (); ; ReturnValue; remote; manual | +| 4 | Summary: java.io; File; false; File; ; ; Argument[0]; Argument[this]; taint; manual | +| 5 | Summary: kotlin.io; ByteStreamsKt; false; bufferedReader; (InputStream,Charset); ; Argument[0]; ReturnValue; taint; df-generated | +| 6 | Summary: kotlin.io; TextStreamsKt; false; readText; (Reader); ; Argument[0]; ReturnValue; taint; df-generated | +| 7 | Summary: org.http4k.core; Body; true; getStream; (); ; Argument[this]; ReturnValue; taint; manual | +| 8 | Summary: org.http4k.core; Uri; false; getPath; (); ; Argument[this]; ReturnValue; taint; manual | +nodes +| Http4kRoutes.kt:180:16:180:27 | getBody(...) : Body | semmle.label | getBody(...) : Body | +| Http4kRoutes.kt:180:16:180:34 | getStream(...) : InputStream | semmle.label | getStream(...) : InputStream | +| Http4kRoutes.kt:180:16:180:51 | bufferedReader$default(...) : BufferedReader | semmle.label | bufferedReader$default(...) : BufferedReader | +| Http4kRoutes.kt:180:16:180:62 | readText(...) : String | semmle.label | readText(...) : String | +| Http4kRoutes.kt:181:37:181:55 | new File(...) | semmle.label | new File(...) | +| Http4kRoutes.kt:181:42:181:54 | "..." : String | semmle.label | "..." : String | +| Http4kRoutes.kt:185:16:185:26 | getUri(...) : Uri | semmle.label | getUri(...) : Uri | +| Http4kRoutes.kt:185:16:185:31 | getPath(...) : String | semmle.label | getPath(...) : String | +| Http4kRoutes.kt:186:37:186:55 | new File(...) | semmle.label | new File(...) | +| Http4kRoutes.kt:186:42:186:54 | "..." : String | semmle.label | "..." : String | +subpaths diff --git a/languages/java/custom/test/http4k/TaintedPath.qlref b/languages/java/custom/test/http4k/TaintedPath.qlref new file mode 100644 index 00000000..574c8395 --- /dev/null +++ b/languages/java/custom/test/http4k/TaintedPath.qlref @@ -0,0 +1,4 @@ +query: Security/CWE/CWE-022/TaintedPath.ql +postprocess: + - utils/test/PrettyPrintModels.ql + - utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/java/custom/test/http4k/UrlRedirect.expected b/languages/java/custom/test/http4k/UrlRedirect.expected new file mode 100644 index 00000000..8f9634aa --- /dev/null +++ b/languages/java/custom/test/http4k/UrlRedirect.expected @@ -0,0 +1,57 @@ +#select +| Http4kRoutes.kt:155:66:155:71 | target | Http4kRoutes.kt:154:18:154:28 | getUri(...) : Uri | Http4kRoutes.kt:155:66:155:71 | target | Untrusted URL redirection depends on a $@. | Http4kRoutes.kt:154:18:154:28 | getUri(...) | user-provided value | +| Http4kRoutes.kt:160:61:160:66 | target | Http4kRoutes.kt:159:18:159:38 | query(...) : String | Http4kRoutes.kt:160:61:160:66 | target | Untrusted URL redirection depends on a $@. | Http4kRoutes.kt:159:18:159:38 | query(...) | user-provided value | +| Http4kRoutes.kt:196:54:196:59 | target | Http4kRoutes.kt:195:18:195:28 | getUri(...) : Uri | Http4kRoutes.kt:196:54:196:59 | target | Untrusted URL redirection depends on a $@. | Http4kRoutes.kt:195:18:195:28 | getUri(...) | user-provided value | +| Http4kRoutes.kt:207:54:207:59 | target | Http4kRoutes.kt:205:16:205:36 | query(...) : String | Http4kRoutes.kt:207:54:207:59 | target | Untrusted URL redirection depends on a $@. | Http4kRoutes.kt:205:16:205:36 | query(...) | user-provided value | +| Http4kRoutes.kt:213:54:213:59 | target | Http4kRoutes.kt:211:16:211:36 | query(...) : String | Http4kRoutes.kt:213:54:213:59 | target | Untrusted URL redirection depends on a $@. | Http4kRoutes.kt:211:16:211:36 | query(...) | user-provided value | +edges +| Http4kRoutes.kt:154:18:154:28 | getUri(...) : Uri | Http4kRoutes.kt:154:18:154:34 | getQuery(...) : String | provenance | Src:MaD:3 MaD:7 | +| Http4kRoutes.kt:154:18:154:34 | getQuery(...) : String | Http4kRoutes.kt:154:18:154:60 | substringAfter$default(...) : String | provenance | MaD:5 | +| Http4kRoutes.kt:154:18:154:60 | substringAfter$default(...) : String | Http4kRoutes.kt:155:66:155:71 | target | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:159:18:159:38 | query(...) : String | Http4kRoutes.kt:160:61:160:66 | target | provenance | Src:MaD:4 Sink:MaD:2 | +| Http4kRoutes.kt:195:18:195:28 | getUri(...) : Uri | Http4kRoutes.kt:195:18:195:43 | path(...) : Uri | provenance | Src:MaD:3 MaD:8 | +| Http4kRoutes.kt:195:18:195:43 | path(...) : Uri | Http4kRoutes.kt:195:18:195:65 | query(...) : Uri | provenance | MaD:9 | +| Http4kRoutes.kt:195:18:195:65 | query(...) : Uri | Http4kRoutes.kt:195:18:195:71 | getQuery(...) : String | provenance | MaD:7 | +| Http4kRoutes.kt:195:18:195:71 | getQuery(...) : String | Http4kRoutes.kt:196:54:196:59 | target | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:205:16:205:36 | query(...) : String | Http4kRoutes.kt:206:41:206:44 | next : String | provenance | Src:MaD:4 | +| Http4kRoutes.kt:206:18:206:45 | of(...) : Uri | Http4kRoutes.kt:206:18:206:56 | toString(...) : String | provenance | MaD:10 | +| Http4kRoutes.kt:206:18:206:56 | toString(...) : String | Http4kRoutes.kt:207:54:207:59 | target | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:206:41:206:44 | next : String | Http4kRoutes.kt:206:18:206:45 | of(...) : Uri | provenance | MaD:6 | +| Http4kRoutes.kt:211:16:211:36 | query(...) : String | Http4kRoutes.kt:212:51:212:54 | next : String | provenance | Src:MaD:4 | +| Http4kRoutes.kt:212:18:212:55 | of(...) : Uri | Http4kRoutes.kt:212:18:212:66 | toString(...) : String | provenance | MaD:10 | +| Http4kRoutes.kt:212:18:212:66 | toString(...) : String | Http4kRoutes.kt:213:54:213:59 | target | provenance | Sink:MaD:1 | +| Http4kRoutes.kt:212:51:212:54 | next : String | Http4kRoutes.kt:212:18:212:55 | of(...) : Uri | provenance | MaD:6 | +models +| 1 | Sink: org.http4k.core; Response; true; header; (String,String); ; Argument[1]; response-splitting; manual | +| 2 | Sink: org.http4k.core; Response; true; replaceHeader; (String,String); ; Argument[1]; response-splitting; manual | +| 3 | Source: org.http4k.core; Request; true; getUri; (); ; ReturnValue; remote; manual | +| 4 | Source: org.http4k.core; Request; true; query; (String); ; ReturnValue; remote; manual | +| 5 | Summary: kotlin.text; StringsKt; false; substringAfter; (String,String,String); ; Argument[0]; ReturnValue; taint; df-generated | +| 6 | Summary: org.http4k.core; Uri$Companion; false; of; (String); ; Argument[0]; ReturnValue; taint; manual | +| 7 | Summary: org.http4k.core; Uri; false; getQuery; (); ; Argument[this]; ReturnValue; taint; manual | +| 8 | Summary: org.http4k.core; Uri; false; path; (String); ; Argument[this]; ReturnValue; taint; manual | +| 9 | Summary: org.http4k.core; Uri; false; query; (String); ; Argument[this]; ReturnValue; taint; manual | +| 10 | Summary: org.http4k.core; Uri; false; toString; (); ; Argument[this]; ReturnValue; taint; manual | +nodes +| Http4kRoutes.kt:154:18:154:28 | getUri(...) : Uri | semmle.label | getUri(...) : Uri | +| Http4kRoutes.kt:154:18:154:34 | getQuery(...) : String | semmle.label | getQuery(...) : String | +| Http4kRoutes.kt:154:18:154:60 | substringAfter$default(...) : String | semmle.label | substringAfter$default(...) : String | +| Http4kRoutes.kt:155:66:155:71 | target | semmle.label | target | +| Http4kRoutes.kt:159:18:159:38 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:160:61:160:66 | target | semmle.label | target | +| Http4kRoutes.kt:195:18:195:28 | getUri(...) : Uri | semmle.label | getUri(...) : Uri | +| Http4kRoutes.kt:195:18:195:43 | path(...) : Uri | semmle.label | path(...) : Uri | +| Http4kRoutes.kt:195:18:195:65 | query(...) : Uri | semmle.label | query(...) : Uri | +| Http4kRoutes.kt:195:18:195:71 | getQuery(...) : String | semmle.label | getQuery(...) : String | +| Http4kRoutes.kt:196:54:196:59 | target | semmle.label | target | +| Http4kRoutes.kt:205:16:205:36 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:206:18:206:45 | of(...) : Uri | semmle.label | of(...) : Uri | +| Http4kRoutes.kt:206:18:206:56 | toString(...) : String | semmle.label | toString(...) : String | +| Http4kRoutes.kt:206:41:206:44 | next : String | semmle.label | next : String | +| Http4kRoutes.kt:207:54:207:59 | target | semmle.label | target | +| Http4kRoutes.kt:211:16:211:36 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:212:18:212:55 | of(...) : Uri | semmle.label | of(...) : Uri | +| Http4kRoutes.kt:212:18:212:66 | toString(...) : String | semmle.label | toString(...) : String | +| Http4kRoutes.kt:212:51:212:54 | next : String | semmle.label | next : String | +| Http4kRoutes.kt:213:54:213:59 | target | semmle.label | target | +subpaths diff --git a/languages/java/custom/test/http4k/UrlRedirect.qlref b/languages/java/custom/test/http4k/UrlRedirect.qlref new file mode 100644 index 00000000..032492b9 --- /dev/null +++ b/languages/java/custom/test/http4k/UrlRedirect.qlref @@ -0,0 +1,4 @@ +query: http4k/UrlRedirect.ql +postprocess: + - utils/test/PrettyPrintModels.ql + - utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/java/custom/test/http4k/XSS.expected b/languages/java/custom/test/http4k/XSS.expected new file mode 100644 index 00000000..5485bf4c --- /dev/null +++ b/languages/java/custom/test/http4k/XSS.expected @@ -0,0 +1,63 @@ +#select +| Http4kRoutes.kt:112:15:112:53 | "..." | Http4kRoutes.kt:109:16:109:36 | query(...) : String | Http4kRoutes.kt:112:15:112:53 | "..." | Cross-site scripting vulnerability due to a $@. | Http4kRoutes.kt:109:16:109:36 | query(...) | user-provided value | +| Http4kRoutes.kt:117:37:117:50 | "..." | Http4kRoutes.kt:116:16:116:35 | bodyString(...) : String | Http4kRoutes.kt:117:37:117:50 | "..." | Cross-site scripting vulnerability due to a $@. | Http4kRoutes.kt:116:16:116:35 | bodyString(...) | user-provided value | +| Http4kRoutes.kt:122:37:122:50 | "..." | Http4kRoutes.kt:121:16:121:27 | getBody(...) : Body | Http4kRoutes.kt:122:37:122:50 | "..." | Cross-site scripting vulnerability due to a $@. | Http4kRoutes.kt:121:16:121:27 | getBody(...) | user-provided value | +| Http4kRoutes.kt:127:37:127:50 | "..." | Http4kRoutes.kt:126:23:126:34 | getBody(...) : Body | Http4kRoutes.kt:127:37:127:50 | "..." | Cross-site scripting vulnerability due to a $@. | Http4kRoutes.kt:126:23:126:34 | getBody(...) | user-provided value | +| Http4kRoutes.kt:132:37:132:49 | create(...) | Http4kRoutes.kt:131:19:131:30 | getBody(...) : Body | Http4kRoutes.kt:132:37:132:49 | create(...) | Cross-site scripting vulnerability due to a $@. | Http4kRoutes.kt:131:19:131:30 | getBody(...) | user-provided value | +| Http4kRoutes.kt:142:37:142:56 | create(...) | Http4kRoutes.kt:141:16:141:68 | invoke(...) : Void | Http4kRoutes.kt:142:37:142:56 | create(...) | Cross-site scripting vulnerability due to a $@. | Http4kRoutes.kt:141:16:141:68 | invoke(...) | user-provided value | +edges +| Http4kRoutes.kt:109:16:109:36 | query(...) : String | Http4kRoutes.kt:112:15:112:53 | "..." | provenance | Src:MaD:5 Sink:MaD:2 | +| Http4kRoutes.kt:116:16:116:35 | bodyString(...) : String | Http4kRoutes.kt:117:37:117:50 | "..." | provenance | Src:MaD:3 Sink:MaD:2 | +| Http4kRoutes.kt:121:16:121:27 | getBody(...) : Body | Http4kRoutes.kt:121:16:121:34 | getStream(...) : InputStream | provenance | Src:MaD:4 MaD:14 | +| Http4kRoutes.kt:121:16:121:34 | getStream(...) : InputStream | Http4kRoutes.kt:121:16:121:51 | bufferedReader$default(...) : BufferedReader | provenance | MaD:8 | +| Http4kRoutes.kt:121:16:121:51 | bufferedReader$default(...) : BufferedReader | Http4kRoutes.kt:121:16:121:62 | readText(...) : String | provenance | MaD:9 | +| Http4kRoutes.kt:121:16:121:62 | readText(...) : String | Http4kRoutes.kt:122:37:122:50 | "..." | provenance | Sink:MaD:2 | +| Http4kRoutes.kt:126:16:126:51 | String(...) : String | Http4kRoutes.kt:127:37:127:50 | "..." | provenance | Sink:MaD:2 | +| Http4kRoutes.kt:126:23:126:34 | getBody(...) : Body | Http4kRoutes.kt:126:23:126:42 | getPayload(...) : ByteBuffer | provenance | Src:MaD:4 MaD:13 | +| Http4kRoutes.kt:126:23:126:42 | getPayload(...) : ByteBuffer | Http4kRoutes.kt:126:23:126:50 | array(...) : byte[] | provenance | MaD:7 | +| Http4kRoutes.kt:126:23:126:50 | array(...) : byte[] | Http4kRoutes.kt:126:44:126:50 | : byte[] | provenance | | +| Http4kRoutes.kt:126:44:126:50 | : byte[] | Http4kRoutes.kt:126:16:126:51 | String(...) : String | provenance | MaD:10 | +| Http4kRoutes.kt:131:19:131:30 | getBody(...) : Body | Http4kRoutes.kt:131:19:131:38 | getPayload(...) : ByteBuffer | provenance | Src:MaD:4 MaD:13 | +| Http4kRoutes.kt:131:19:131:38 | getPayload(...) : ByteBuffer | Http4kRoutes.kt:132:42:132:48 | payload : ByteBuffer | provenance | | +| Http4kRoutes.kt:132:42:132:48 | payload : ByteBuffer | Http4kRoutes.kt:132:37:132:49 | create(...) | provenance | MaD:11 Sink:MaD:1 | +| Http4kRoutes.kt:141:16:141:68 | invoke(...) : Void | Http4kRoutes.kt:142:42:142:55 | "..." : String | provenance | Src:MaD:6 | +| Http4kRoutes.kt:142:42:142:55 | "..." : String | Http4kRoutes.kt:142:37:142:56 | create(...) | provenance | MaD:12 Sink:MaD:1 | +models +| 1 | Sink: org.http4k.core; Response; true; body; (Body); ; Argument[0]; html-injection; manual | +| 2 | Sink: org.http4k.core; Response; true; body; (String); ; Argument[0]; html-injection; manual | +| 3 | Source: org.http4k.core; HttpMessage; true; bodyString; (); ; ReturnValue; remote; manual | +| 4 | Source: org.http4k.core; HttpMessage; true; getBody; (); ; ReturnValue; remote; manual | +| 5 | Source: org.http4k.core; Request; true; query; (String); ; ReturnValue; remote; manual | +| 6 | Source: org.http4k.lens; LensExtractor; true; invoke; (Object); ; ReturnValue; remote; manual | +| 7 | Summary: java.nio; ByteBuffer; false; array; (); ; Argument[this]; ReturnValue; taint; manual | +| 8 | Summary: kotlin.io; ByteStreamsKt; false; bufferedReader; (InputStream,Charset); ; Argument[0]; ReturnValue; taint; df-generated | +| 9 | Summary: kotlin.io; TextStreamsKt; false; readText; (Reader); ; Argument[0]; ReturnValue; taint; df-generated | +| 10 | Summary: kotlin.text; StringsKt; false; String; (byte[]); ; Argument[0]; ReturnValue; taint; df-generated | +| 11 | Summary: org.http4k.core; Body$Companion; false; create; (ByteBuffer); ; Argument[0]; ReturnValue; taint; manual | +| 12 | Summary: org.http4k.core; Body$Companion; false; create; (String); ; Argument[0]; ReturnValue; taint; manual | +| 13 | Summary: org.http4k.core; Body; true; getPayload; (); ; Argument[this]; ReturnValue; taint; manual | +| 14 | Summary: org.http4k.core; Body; true; getStream; (); ; Argument[this]; ReturnValue; taint; manual | +nodes +| Http4kRoutes.kt:109:16:109:36 | query(...) : String | semmle.label | query(...) : String | +| Http4kRoutes.kt:112:15:112:53 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:116:16:116:35 | bodyString(...) : String | semmle.label | bodyString(...) : String | +| Http4kRoutes.kt:117:37:117:50 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:121:16:121:27 | getBody(...) : Body | semmle.label | getBody(...) : Body | +| Http4kRoutes.kt:121:16:121:34 | getStream(...) : InputStream | semmle.label | getStream(...) : InputStream | +| Http4kRoutes.kt:121:16:121:51 | bufferedReader$default(...) : BufferedReader | semmle.label | bufferedReader$default(...) : BufferedReader | +| Http4kRoutes.kt:121:16:121:62 | readText(...) : String | semmle.label | readText(...) : String | +| Http4kRoutes.kt:122:37:122:50 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:126:16:126:51 | String(...) : String | semmle.label | String(...) : String | +| Http4kRoutes.kt:126:23:126:34 | getBody(...) : Body | semmle.label | getBody(...) : Body | +| Http4kRoutes.kt:126:23:126:42 | getPayload(...) : ByteBuffer | semmle.label | getPayload(...) : ByteBuffer | +| Http4kRoutes.kt:126:23:126:50 | array(...) : byte[] | semmle.label | array(...) : byte[] | +| Http4kRoutes.kt:126:44:126:50 | : byte[] | semmle.label | : byte[] | +| Http4kRoutes.kt:127:37:127:50 | "..." | semmle.label | "..." | +| Http4kRoutes.kt:131:19:131:30 | getBody(...) : Body | semmle.label | getBody(...) : Body | +| Http4kRoutes.kt:131:19:131:38 | getPayload(...) : ByteBuffer | semmle.label | getPayload(...) : ByteBuffer | +| Http4kRoutes.kt:132:37:132:49 | create(...) | semmle.label | create(...) | +| Http4kRoutes.kt:132:42:132:48 | payload : ByteBuffer | semmle.label | payload : ByteBuffer | +| Http4kRoutes.kt:141:16:141:68 | invoke(...) : Void | semmle.label | invoke(...) : Void | +| Http4kRoutes.kt:142:37:142:56 | create(...) | semmle.label | create(...) | +| Http4kRoutes.kt:142:42:142:55 | "..." : String | semmle.label | "..." : String | +subpaths diff --git a/languages/java/custom/test/http4k/XSS.qlref b/languages/java/custom/test/http4k/XSS.qlref new file mode 100644 index 00000000..bff2f253 --- /dev/null +++ b/languages/java/custom/test/http4k/XSS.qlref @@ -0,0 +1,4 @@ +query: Security/CWE/CWE-079/XSS.ql +postprocess: + - utils/test/PrettyPrintModels.ql + - utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/java/custom/test/http4k/options b/languages/java/custom/test/http4k/options new file mode 100644 index 00000000..3492bf52 --- /dev/null +++ b/languages/java/custom/test/http4k/options @@ -0,0 +1 @@ +codeql-extractor-kotlin-options: -language-version 2.0 diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/core/Uri.kt b/languages/java/custom/test/http4k/stubs/org/http4k/core/Uri.kt new file mode 100644 index 00000000..fb1f83db --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/core/Uri.kt @@ -0,0 +1,17 @@ +package org.http4k.core + +class Uri { + val path: String get() = TODO() + val query: String get() = TODO() + + fun path(path: String): Uri = TODO() + fun query(query: String): Uri = TODO() + override fun toString(): String = TODO() + + companion object { + @JvmStatic + fun of(value: String): Uri = TODO() + } +} + +fun Uri.queryParametersEncoded(): Uri = TODO() diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/core/body/FormBody.kt b/languages/java/custom/test/http4k/stubs/org/http4k/core/body/FormBody.kt new file mode 100644 index 00000000..6adf4c80 --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/core/body/FormBody.kt @@ -0,0 +1,5 @@ +package org.http4k.core.body + +import org.http4k.core.Request + +fun Request.form(name: String): String? = TODO() diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/Cookie.kt b/languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/Cookie.kt new file mode 100644 index 00000000..51c5df77 --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/Cookie.kt @@ -0,0 +1,3 @@ +package org.http4k.core.cookie + +class Cookie(val name: String, val value: String) diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/CookieExtensions.kt b/languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/CookieExtensions.kt new file mode 100644 index 00000000..8b8b4305 --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/CookieExtensions.kt @@ -0,0 +1,5 @@ +package org.http4k.core.cookie + +import org.http4k.core.Request + +fun Request.cookie(name: String): Cookie? = TODO() diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/core/http.kt b/languages/java/custom/test/http4k/stubs/org/http4k/core/http.kt new file mode 100644 index 00000000..0617ff50 --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/core/http.kt @@ -0,0 +1,87 @@ +// Minimal stubs of the http4k-core API (https://github.com/http4k/http4k) with the +// same JVM signatures as the real library. Bodies are intentionally empty so that +// data flow only comes from the data extension models under test. +package org.http4k.core + +import java.io.Closeable +import java.io.InputStream +import java.nio.ByteBuffer + +interface Body : Closeable { + val stream: InputStream + val payload: ByteBuffer + + companion object { + @JvmStatic + @JvmName("create") + operator fun invoke(body: String): Body = TODO() + + @JvmStatic + @JvmName("create") + operator fun invoke(body: InputStream, length: Long? = null): Body = TODO() + + @JvmStatic + @JvmName("create") + operator fun invoke(body: ByteBuffer): Body = TODO() + } +} + +interface HttpMessage : Closeable { + val body: Body + + fun header(name: String): String? + + fun header(name: String, value: String?): HttpMessage + + fun headerValues(name: String): List + + fun bodyString(): String + + fun body(body: Body): HttpMessage + + fun body(body: String): HttpMessage +} + +interface Request : HttpMessage { + val uri: Uri + + fun query(name: String): String? + + fun queries(name: String): List + + override fun header(name: String, value: String?): Request + + override fun body(body: Body): Request + + override fun body(body: String): Request +} + +interface Response : HttpMessage { + override fun header(name: String, value: String?): Response + + fun replaceHeader(name: String, value: String?): Response + + override fun body(body: Body): Response + + override fun body(body: String): Response + + companion object { + @JvmStatic + @JvmName("create") + operator fun invoke(status: Status): Response = TODO() + } +} + +class Status { + companion object { + val OK: Status = TODO() + val FOUND: Status = TODO() + val MOVED_PERMANENTLY: Status = TODO() + } +} + +class ContentType { + companion object { + val TEXT_PLAIN: ContentType = TODO() + } +} diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/lens/body.kt b/languages/java/custom/test/http4k/stubs/org/http4k/lens/body.kt new file mode 100644 index 00000000..d0b555c8 --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/lens/body.kt @@ -0,0 +1,10 @@ +package org.http4k.lens + +import org.http4k.core.Body +import org.http4k.core.ContentType + +class BiDiBodyLensSpec { + fun toLens(): BiDiBodyLens = TODO() +} + +fun Body.Companion.string(contentType: ContentType): BiDiBodyLensSpec = TODO() diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/lens/extractInject.kt b/languages/java/custom/test/http4k/stubs/org/http4k/lens/extractInject.kt new file mode 100644 index 00000000..1e4b9874 --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/lens/extractInject.kt @@ -0,0 +1,9 @@ +package org.http4k.lens + +interface LensExtractor : (IN) -> OUT { + override operator fun invoke(target: IN): OUT + + fun extract(target: IN): OUT + + operator fun get(target: R): OUT +} diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/lens/header.kt b/languages/java/custom/test/http4k/stubs/org/http4k/lens/header.kt new file mode 100644 index 00000000..efb8f40e --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/lens/header.kt @@ -0,0 +1,7 @@ +package org.http4k.lens + +import org.http4k.core.HttpMessage + +object Header { + fun required(name: String): BiDiLens = TODO() +} diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/lens/lens.kt b/languages/java/custom/test/http4k/stubs/org/http4k/lens/lens.kt new file mode 100644 index 00000000..a362c25a --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/lens/lens.kt @@ -0,0 +1,23 @@ +package org.http4k.lens + +import org.http4k.core.HttpMessage + +open class Lens : LensExtractor { + override operator fun invoke(target: IN): FINAL = TODO() + + override fun extract(target: IN): FINAL = TODO() + + override operator fun get(target: R): FINAL = TODO() +} + +open class BiDiLens : Lens() + +open class BodyLens : LensExtractor { + override operator fun invoke(target: HttpMessage): FINAL = TODO() + + override fun extract(target: HttpMessage): FINAL = TODO() + + override operator fun get(target: R): FINAL = TODO() +} + +open class BiDiBodyLens : BodyLens() diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/lens/query.kt b/languages/java/custom/test/http4k/stubs/org/http4k/lens/query.kt new file mode 100644 index 00000000..956ec0cf --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/lens/query.kt @@ -0,0 +1,7 @@ +package org.http4k.lens + +import org.http4k.core.Request + +object Query { + fun required(name: String): BiDiLens = TODO() +} diff --git a/languages/java/custom/test/http4k/stubs/org/http4k/routing/extensions.kt b/languages/java/custom/test/http4k/stubs/org/http4k/routing/extensions.kt new file mode 100644 index 00000000..a91027f5 --- /dev/null +++ b/languages/java/custom/test/http4k/stubs/org/http4k/routing/extensions.kt @@ -0,0 +1,5 @@ +package org.http4k.routing + +import org.http4k.core.Request + +fun Request.path(name: String): String? = TODO() diff --git a/languages/java/custom/test/qlpack.yml b/languages/java/custom/test/qlpack.yml index 1e98673e..74ad651a 100644 --- a/languages/java/custom/test/qlpack.yml +++ b/languages/java/custom/test/qlpack.yml @@ -1,5 +1,7 @@ name: languages-java-custom-test version: 0.0.2 dependencies: + codeql/java-queries: "*" + languages-java-custom-models: ${workspace} languages-java-custom-src: ${workspace} extractor: java