Repository navigation
Conversation
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved taint-modeling gaps cause both false positives and missed vulnerabilities.
8 open issues
Restrict remote sources to inbound requests and client responses · New Limit response-body XSS sinks to HTML-capable responses · New Treat tainted header names as response-splitting sinks · New Restrict redirect sinks to Location header values · New Add Body(ByteBuffer) summaries to preserve XSS taint · New Model taint preservation in immutable URI updates · New Propagate taint through Uri.of factories · New Avoid marking every LensExtractor output as remote · New
What changed in this PR
Adds a Java/Kotlin CodeQL model pack for http4k so existing security queries can trace request data through framework APIs to injection sinks, addressing the coverage gap in issue #1.
Changes:
- Models request sources, response sinks, and taint propagation across core, lens, and routing APIs.
- Adds Kotlin fixtures, API stubs, and expected results for five security queries.
- Connects the test pack to the models and enables Kotlin 2 extraction in CI.
| File | Description |
|---|---|
languages/java/custom/test/qlpack.yml |
Adds query and model pack dependencies. |
languages/java/custom/test/http4k/XSS.qlref |
Configures XSS regression testing. |
languages/java/custom/test/http4k/XSS.expected |
Records expected XSS flows. |
languages/java/custom/test/http4k/UrlRedirect.qlref |
Configures redirect regression testing. |
languages/java/custom/test/http4k/UrlRedirect.expected |
Records expected redirect flows. |
languages/java/custom/test/http4k/TaintedPath.qlref |
Configures path-injection regression testing. |
languages/java/custom/test/http4k/TaintedPath.expected |
Records expected path-injection flows. |
languages/java/custom/test/http4k/stubs/org/http4k/routing/extensions.kt |
Stubs path-parameter extraction. |
languages/java/custom/test/http4k/stubs/org/http4k/lens/query.kt |
Stubs query-lens construction. |
languages/java/custom/test/http4k/stubs/org/http4k/lens/lens.kt |
Stubs lens implementations and inheritance. |
languages/java/custom/test/http4k/stubs/org/http4k/lens/header.kt |
Stubs header-lens construction. |
languages/java/custom/test/http4k/stubs/org/http4k/lens/extractInject.kt |
Defines the generic lens-extraction interface. |
languages/java/custom/test/http4k/stubs/org/http4k/lens/body.kt |
Stubs string body-lens construction. |
languages/java/custom/test/http4k/stubs/org/http4k/core/Uri.kt |
Stubs URI accessors and factories. |
languages/java/custom/test/http4k/stubs/org/http4k/core/http.kt |
Stubs core HTTP message and body APIs. |
languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/CookieExtensions.kt |
Stubs request-cookie extraction. |
languages/java/custom/test/http4k/stubs/org/http4k/core/cookie/Cookie.kt |
Defines cookie test properties. |
languages/java/custom/test/http4k/stubs/org/http4k/core/body/FormBody.kt |
Stubs form-value extraction. |
languages/java/custom/test/http4k/SqlTainted.qlref |
Configures SQL-injection regression testing. |
languages/java/custom/test/http4k/SqlTainted.expected |
Records expected SQL-injection flows. |
languages/java/custom/test/http4k/ResponseSplitting.qlref |
Configures response-splitting regression testing. |
languages/java/custom/test/http4k/ResponseSplitting.expected |
Records expected header-injection flows. |
languages/java/custom/test/http4k/Http4kRoutes.kt |
Adds vulnerable flows and constant-value controls. |
languages/java/custom/models/qlpack.yml |
Declares the Java data-extension pack. |
languages/java/custom/models/http4k-routing.model.yml |
Models path-parameter sources across http4k versions. |
languages/java/custom/models/http4k-lens.model.yml |
Models lens extraction as remote input. |
languages/java/custom/models/http4k-core.model.yml |
Adds core sources, sinks, and taint summaries. |
.github/workflows/codeql-qlt-unit-tests.yml |
Enables Kotlin 2 test extraction in CI. |
Review effort: Balanced
| - ["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"] |
There was a problem hiding this comment.
Documented this as a known limitation in languages/java/custom/models/README.md. Data extensions cannot narrow these HttpMessage sources to inbound requests or client responses, and modeling handler parameters requires customized QL.
| 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"] |
There was a problem hiding this comment.
Documented this as a known limitation. Data extensions cannot make the Response.body sink conditional on Content-Type; distinguishing non-HTML responses while retaining unknown types requires a customized XSS query.
| - ["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"] |
There was a problem hiding this comment.
Documented this as a known limitation. Generic LensExtractor source rows cannot distinguish request-backed lenses from local, context, or custom lenses; narrowing them could omit custom lens values.
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>

📝 Data Extension Information
http4k-core.model.yml,http4k-lens.model.yml,http4k-routing.model.ymlorg.http4k.core(pluscore.body,core.cookie),org.http4k.lens,org.http4k.routing🎯 Description
What This Data Extension Models
CodeQL has no http4k models. As a result, request data is never treated as remote input, and response bodies and headers are not sinks. These models let the existing
java/sql-injection,java/xss,java/unvalidated-url-redirection,java/http-response-splittingandjava/path-injectionqueries detect http4k flows.remote)HttpMessage:bodyString(),getBody(),header(String),headerValues(String)Request:query,queries,getUriform(Request,String),cookie(Request,String)LensExtractor.invoke/get/extract(Object), including subtypes. This coversQuery.required(...),Header.*andBody.string(...)lenses.Request.path(String), bothrouting.ExtensionsKt(6.x) andRoutingKt(5.x). This goes beyond the issue's list.Body:getPayload,getStream,getText, andBody(...)/Body.createUri:getQuery,getPath,getHostand the other component getters, plustoStringandqueryParametersEncodedCookie.getValueResponse.body(String | Body | InputStream,Long),Argument[0]:html-injectionResponse.header/replaceHeader(String,String),Argument[1]:response-splittingandurl-redirectionDesign notes and known limitations:
Uri.getQuery()as a source. Modeling it as a summary avoids flagging constantUri.of("...").request.uriis the source, sorequest.uri.queryflows are still caught.Response.bodycannot check the response content type, so JSON responses that echo input will also be reported.Locationcheck for url-redirection. The url-redirection sink cannot restrict to theLocationheader name, so any tainted response-header value is reported.sanitizeHeader), soresponse-splittingresults are false positives there. Versions ≤ 6.48 are not protected, including 5.13.0.0 used by the reference app. The sink is kept because MaD cannot tell versions apart.$defaultmethods. For example,Response.body(stream)without a length is not matched. ModelingHttpMessage.body$defaultwould also matchRequest, so it is left out.RequestContextKeylenses and on lenses applied to client-sideResponses.Threat Model
remoteExample Vulnerable Code
Example Safe Code
📦 Extension Details
Extension YAML
The models are in a new pack,
languages/java/custom/models/(languages-java-custom-models,library: true,extensionTargets: codeql/java-all). Excerpt:Access Path Explanation
Signatures are the JVM signatures of the compiled Kotlin, checked with
javapagainst http4k-core 5.13.0.0 and 6.58.0.0. They match across both versions.request.uriisgetUri().<File>Ktwith the receiver asArgument[0], for exampleFormBodyKt.form(Request,String).Body(...)resolves toBody$Companion.create.(Object).Related changes:
library: truewith no dependencies. The query pack incustom/srccannot host them, and the data-extension prompt that points there should be updated in a follow-up.languages/java/custom/test/qlpack.ymlnow depends oncodeql/java-queriesand the models pack.codeql-qlt-unit-tests.ymlnow setsCODEQL_KOTLIN_LEGACY_TEST_EXTRACTION_KOTLIN2=true. Without it,codeql test runpasses-language-version 1.9to kotlinc, which kotlinc 2.4+ rejects.languages/*/custom/**, so these tests do not run in CI yet. Extending the filters is a suggested follow-up.🧪 Testing
codeql database createorcodeql test extract)codeql query run --additional-packs=<model-pack-dir>)codeql test run --additional-packs=<model-pack-dir>)The five queries were run against Kotlin databases built with the real 5.13.0.0 and 6.58.0.0 jars. With no models there were 0 results. With the models, every positive case was detected and no constant case was flagged.
Unit tests are in
languages/java/custom/test/http4k/. They use Kotlin stubs, inline expectations and one qlref per query, and cover each source and sink shape plus constant-value negatives. With the models removed, the tests report 48 missing results.📋 Checklist
languages/[language]/custom/src/). Placed inlanguages/java/custom/models/instead, because an extension pack cannot be a query pack (see above).qlpack.ymlincludesdataExtensionsconfigurationjavapand real-jar databases instead.🔗 References
Note: This data extension was developed following CodeQL Models as Data best practices.