Repository navigation
Description
Target Language
java
Library Repository / Documentation URL
https://github.com/http4k/http4k
Data Extension Name (Optional)
http4k-core.model.yml
Library Modules / Components
- org.http4k.core (Request, Response, Uri, HttpMessage: request accessors and response body builders)
- org.http4k.lens (Query, Header, Body lens extractors:
LensExtractor.get,LensExtractor.extract) - org.http4k.core.Uri (
getQuery,queryParametersEncoded)
The http4k framework is written in Kotlin and compiled to JVM bytecode, so it is analyzed with the Java/Kotlin extractor and the model should live under the java language extensions.
Data Extension Description
Library: http4k (Kotlin HTTP toolkit, org.http4k.*).
CodeQL's Java/Kotlin libraries have no models for http4k. In a public synthetic test application that exercises http4k handlers, an AI-based scanner reported a series of real injection flows that java/sql-injection, java/xss, java/path-injection, java/http-response-splitting and java/unvalidated-url-redirection did not report because http4k request data is never treated as remote input and http4k response bodies are not modeled as HTML sinks. Only a small number of endpoints were reported by CodeQL (via generic Kotlin/Java source shapes); most of the other endpoints were missed.
Proposed models:
- Sources (
sourceModel, kindremote)org.http4k.core.HttpMessage.bodyString(),HttpMessage.body(Body.payload/Body.stream),HttpMessage.header(String),HttpMessage.headerValues(String)org.http4k.core.Request.query(String),Request.queries(String),Request.uri,Request.form(String),Request.cookie(String)org.http4k.core.Uri.getQuery()andUri.queryParametersEncoded()org.http4k.lens.LensExtractor.get(Object)andLensExtractor.extract(Object)(return value is request-controlled when applied to aRequest), including theQuery.required/optional(...),Header.required(...)andBody.string(...)lens builders
- Summaries (
summaryModel)Request.uri(...),Uri.query(...),Uri.pathand similar accessors: taint flows from receiver to return value- Lens
get/extract: taint from theRequestargument to the return value Body.stream/Body.payloadtoInputStream/ByteBuffer
- Sinks (
sinkModel)org.http4k.core.Response.body(String)andResponse.body(Body)with HTML content type:html-injection/xsssink (CWE-79)org.http4k.core.Response.header(String, String)value argument:header-splittingsink (CWE-113)org.http4k.core.Response.header("Location", ...)/Response(Status.FOUND/MOVED_PERMANENTLY).header("Location", ...)value:url-redirectionsink (CWE-601)
- Barriers / barrier guards: none identified; http4k does not ship a general HTML or SQL escaper in
http4k-core.
Evidence that this is a coverage gap (public synthetic app, forked for evaluation): https://github.com/codeql-forks-felickz/vulnerable-http4k-app
AI scan alerts for the same application, one per unmodeled source/sink shape (each is a separate http4k route):
- SQL injection, Uri query parsing: https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/53
- Open redirect, Uri query parsing to
Locationheader: https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/73 - Header injection, request body stream to response header: https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/70
- XSS, query parameter reflected through
Response.body: https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/60
Related gap analysis classification: missing-source and missing-sink; the existing queries named above are the right queries, they are only missing http4k source/sink/summary models, so a data extension (no new query) is the appropriate fix.
Code Examples
package com.example.routes
import org.http4k.core.*
import org.http4k.lens.*
import java.sql.DriverManager
// SQL injection: LensExtractor.get() is the SOURCE, Statement.executeQuery() the SINK (java/sql-injection)
fun sqlInjectionLensGetEndpoint(request: Request): Response {
val userLens = Query.required("id")
val userId = userLens.get(request) // SOURCE
val connection = DriverManager.getConnection("jdbc:h2:mem:testdb")
val statement = connection.createStatement()
val query = "SELECT * FROM users WHERE id = $userId"
val resultSet = statement.executeQuery(query) // SINK: SQL injection
connection.close()
return Response(Status.OK).body("done")
}
// SQL injection via Request.header()
fun sqlInjectionRequestHeaderEndpoint(request: Request): Response {
val userId = request.header("X-User-ID") ?: "1" // SOURCE
val statement = DriverManager.getConnection("jdbc:h2:mem:testdb").createStatement()
statement.executeQuery("SELECT * FROM accounts WHERE id = $userId") // SINK
return Response(Status.OK)
}
// Reflected XSS: request data is written to an HTML Response body
fun xssEndpoint(request: Request): Response {
val data = request.query("data") ?: "" // SOURCE
return Response(Status.OK)
.header("Content-Type", "text/html")
.body("<html><body>Hello $data</body></html>") // SINK: XSS (java/xss)
}
// Open redirect: manually parsed URI query value placed in Location header
fun redirectEndpoint(request: Request): Response {
val target = request.uri.query.substringAfter("target=") // SOURCE
return Response(Status.MOVED_PERMANENTLY).header("Location", target) // SINK (java/unvalidated-url-redirection)
}Expected after the extension: each of the flows above should be reported by the corresponding existing query (java/sql-injection, java/xss, java/unvalidated-url-redirection, java/http-response-splitting, java/path-injection). Add a test project under languages/java/test with one positive case per source/sink above and a negative case that uses a constant value.
Additional References (Optional)
https://www.http4k.org/guide/reference/lens/ , https://cwe.mitre.org/data/definitions/89.html , https://cwe.mitre.org/data/definitions/79.html , https://cwe.mitre.org/data/definitions/601.html , https://cwe.mitre.org/data/definitions/113.html
Code of Conduct
- I agree to follow this project's Code of Conduct
Linked findings (gap-key: java/data-extension/http4k)
All AI-scan findings below share this gap and are tracked by this single issue. When more findings with the same gap-key are found, append them here instead of opening a new issue.
| Repo | CWE | AI scan alert(s) | Summary |
|---|---|---|---|
| vulnerable-http4k-app | CWE-601 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/73 | The /api/v2/redirect/uri-query endpoint manually extracts a target value from the request URI and places it in a permanent redirect Location header without validating the destination. |
| vulnerable-http4k-app | CWE-113 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/70 | The /api/v2/header/body-stream endpoint reads an arbitrary request body and uses it as a response-header value without validating or stripping CR/LF characters. |
| vulnerable-http4k-app | CWE-113 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/68 | The /api/v2/header/uri-query endpoint manually extracts a client-controlled query value and writes it directly to a response header without CR/LF validation. |
| vulnerable-http4k-app | CWE-22 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/66 | The /api/v2/path/body-stream endpoint treats request-body content as a filename and appends it to /data before reading it, permitting traversal outside the intended directory. |
| vulnerable-http4k-app | CWE-79 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/60 | The /api/v2/xss/to-message endpoint reflects the data query parameter in an HTML response without encoding it for the HTML body context. |
| vulnerable-http4k-app | CWE-79 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/59 | The /api/v2/xss/body-stream endpoint reads client content from the request body stream and emits it unescaped in a text/html response. |
| vulnerable-http4k-app | CWE-79 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/58 | The /api/v2/xss/httpmessage-body endpoint embeds request-body text directly inside HTML and labels the response text/html, allowing markup or script supplied by a client to execute in a browser. |
| vulnerable-http4k-app | CWE-79 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/57 | The /api/v2/xss/lens-injector endpoint interpolates the attacker-controlled msg parameter into an HTML document that is injected as the response body without escaping. |
| vulnerable-http4k-app | CWE-79 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/56 | The /api/search endpoint reflects the request-controlled q lens value into an HTML response without HTML encoding. |
| vulnerable-http4k-app | CWE-79 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/55 | The /api/echo endpoint places raw request-body content into HTML and returns it with a text/html content type without context-appropriate HTML encoding. |
| vulnerable-http4k-app | CWE-89 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/53 | The /api/v2/sql/uri-query endpoint manually extracts id from the request query string and interpolates it into SQL executed with Statement.executeQuery. |
| vulnerable-http4k-app | CWE-89 | https://github.com/codeql-forks-felickz/vulnerable-http4k-app/security/code-scanning/49 | The /api/profile endpoint obtains an HTTP query value through a required lens and concatenates it into SQL before executing it with Statement.executeQuery. |
Activity
[-][Data Extension Create]: http4k request sources and response sinks (Java/Kotlin)[/-][+][Data Extension Create]: CWE-89, CWE-79, CWE-601, CWE-113 http4k request sources and response sinks (Java/Kotlin)[/+][-][Data Extension Create]: CWE-89, CWE-79, CWE-601, CWE-113 http4k request sources and response sinks (Java/Kotlin)[/-][+][Data Extension Create]: CWE-89, CWE-79, CWE-601, CWE-113, CWE-22 http4k request sources and response sinks (Java/Kotlin)[/+][-][Data Extension Create]: CWE-89, CWE-79, CWE-601, CWE-113, CWE-22 http4k request sources and response sinks (Java/Kotlin)[/-][+][Data Extension Create]: CWE-89, CWE-79, CWE-601, CWE-113, CWE-22 HIGH - http4k request sources and response sinks (Java/Kotlin)[/+]felickz commentedon Nov 3, 2026
Upstream triage
precision:mediumRelies on heuristics or accepted over-approximation. Community Packs, always tags:experimental.
tags:experimental
Goes to Community Packs: performance, false-positive or synthetic-only concerns.
Community Packs, experimental. Recommended for the Community Packs repository, not
github/codeql. The issue is labeledtags:experimentalfor this.Separable piece. Request source rows and Uri/Body summaries, once narrowed. This part could be proposed to
github/codeqlon its own, see the split note below.Linked pull request: #7
Why. The http4k models are exact-signature MaD rows for a public Kotlin toolkit and the stub-based tests pass. Precision is medium, not high: Response.body(String) is an HTML sink regardless of content type, HttpMessage and every lens output are remote sources even for locally built responses, and header sinks do not apply on http4k 6.49+. Recommend Community Packs ext/manual (experimental); revisit github/codeql once sources are narrowed.
highin the pull request). Rows use exact names, but sources cover all HttpMessage getters (locally built Responses too) and every LensExtractor output, Response.body(String) is an HTML sink for any content type, and header sinks do not apply on http4k 6.49+. Review kept these as accepted limitations.Concerns, overlap and next steps
False-positive concerns
Heuristics used
What an upstream change would look like. Community Packs java/ext/manual/http4k.model.yml (core, lens, routing rows) plus a java/src redirect query or library sink, tests under java/test with minimal http4k stubs. Narrowed Request-only source rows could later go to github/codeql java/ql/lib/ext/org.http4k.model.yml.
Before opening an upstream pull request
Split note. Request source rows and the Uri/Body summaries are exact and could be a github/codeql MaD PR on their own once narrowed; the XSS and header sinks and the Location redirect query are heuristic, so the whole PR stays in Community Packs.
Change from the initial guess. When this issue was opened the coarse destination guess was
github/codeql. Reading the actual pull request changed it to Community Packs.This is a recommendation only. A human reviews it before any pull request is opened against
github/codeqlor the Community Packs repository.