Skip to content

[Data Extension Create]: CWE-89, CWE-79, CWE-601, CWE-113, CWE-22 HIGH - http4k request sources and response sinks (Java/Kotlin) #1

Open

Description

@felickz

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, kind remote)
    • 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() and Uri.queryParametersEncoded()
    • org.http4k.lens.LensExtractor.get(Object) and LensExtractor.extract(Object) (return value is request-controlled when applied to a Request), including the Query.required/optional(...), Header.required(...) and Body.string(...) lens builders
  • Summaries (summaryModel)
    • Request.uri(...), Uri.query(...), Uri.path and similar accessors: taint flows from receiver to return value
    • Lens get/extract: taint from the Request argument to the return value
    • Body.stream / Body.payload to InputStream / ByteBuffer
  • Sinks (sinkModel)
    • org.http4k.core.Response.body(String) and Response.body(Body) with HTML content type: html-injection / xss sink (CWE-79)
    • org.http4k.core.Response.header(String, String) value argument: header-splitting sink (CWE-113)
    • org.http4k.core.Response.header("Location", ...) / Response(Status.FOUND/MOVED_PERMANENTLY).header("Location", ...) value: url-redirection sink (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):

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

  1. changed the title [-][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)[/+] on Oct 8, 2026
  2. added
    CWE-89
    CWE-79
    CWE-601
    CWE-113
    CWE-22
    on Oct 8, 2026
  3. changed the title [-][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)[/+] on Oct 8, 2026
  4. added
    severity:high
    on Oct 9, 2026
  5. changed the title [-][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)[/+] on Oct 9, 2026
  6. added
    precision:medium
    tags:experimental
    on Nov 3, 2026
  7. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:medium Relies 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 labeled tags:experimental for this.

    Separable piece. Request source rows and Uri/Body summaries, once narrowed. This part could be proposed to github/codeql on 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.

    Change Data extension (model) addition
    Target http4k-core request sources, Response.body/header sinks, Uri/Body summaries; Location redirect via custom query
    Precision assessed medium (declared high in 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.
    Real-world basis partial. Public org.http4k:http4k-core (Request.query/header/form/cookie/path, lenses, Response.body/header, Uri, Body); model header says signatures were checked against 5.13 and 6.58 jars. No synthetic identifiers, but http4k is a niche toolkit.
    Stock overlap none. No http4k models in java-all 9.3.0 (grep); gh code search of github/codeql and CodeQL-Community-Packs for 'http4k' returned no hits.
    Concerns, overlap and next steps

    False-positive concerns

    • Response.body(String) is an HTML sink for any content type, so JSON or plain-text responses built from request data are reported as XSS.
    • HttpMessage getters are sources on locally built Responses and client responses, not only inbound requests.
    • Every LensExtractor output is remote, including server-side RequestContextKey lenses.
    • Header response-splitting sinks are not exploitable on http4k 6.49+, which strips CR/LF from header names and values.

    Heuristics used

    • No Content-Type check on XSS sinks (cannot be expressed in MaD)
    • Location header found by constant string in UrlRedirect.ql

    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

    • Narrow sources to Request accessors and client Response bodies; limit lens sources to Query, Header, Path, FormField and Body lens factories.
    • Drop or gate the Response.body html-injection sink, since MaD cannot check Content-Type.
    • Decide whether the response-splitting rows should stay given http4k 6.49+ strips CR/LF.
    • Show a true positive on a real http4k project; the tests use hand-written stubs only.

    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/codeql or the Community Packs repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CWE-113CWE-22CWE-601CWE-79CWE-89data-extension-createenhancementprecision:mediumseverity:hightags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions