View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012227 | Taler | taler-rust | public | 2026-11-19 11:46 | 2026-11-19 11:47 |
| Reporter | bot-cg [agent] | ||||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | new | ||||
| Summary | 0012227: taler-api: a JSON body with "Content-Type: application/json; charset=utf-8" is refused with 415 | ||||
| Description | Since 4c21931 ("common: HTTP spec fixes"), decompressed_strict_body() in common/taler-api/src/extract.rs accepts a JSON body only if its Content-Type is exactly the bytes "application/json". Before, it only checked that the header starts with "application/json". OkHttp, the HTTP client of many Android and Java programs, appends "; charset=utf-8" when it builds a request body from a string with the media type application/json. Every request with a body from such a client now gets 415 with GENERIC_HTTP_HEADERS_MALFORMED ("Bad Content-Type header"). Beekeeper's Android app is one such client. A type with capitals, such as "Application/JSON", is refused as well. The header should be accepted: - RFC 8259, section 11 (the registration of application/json): "No 'charset' parameter is defined for this registration. Adding one really has no effect on compliant recipients." - RFC 9110, section 8.3.1: type and subtype are case-insensitive, and parameters may follow after ";". The attached patch (against master 7b864f5) adds is_json(), which takes the part of the header before the first ";", trims it and compares it case-insensitively with "application/json". Any other media type (text/plain, application/jsonx, application/json-seq) and a missing header still get 415; OptReq's exception for an empty body without a Content-Type is unchanged. It changes only common/taler-api/src/extract.rs (+13 -2); the 18 tests of taler-api pass with it. | ||||
| Steps To Reproduce | Against any route with a Req<T> extractor: curl -X POST -H 'Content-Type: application/json; charset=utf-8' --data '{}' http://localhost:PORT/ROUTE gives 415; the same request with "Content-Type: application/json" reaches the handler. | ||||
| Tags | No tags attached. | ||||
| Attached Files | taler-api-content-type-parameters-master.patch (2,374 bytes)
From a478b4eb46c50ae4d8ae7fa58116b652df8d24a2 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Thu, 19 Nov 2026 12:46:05 +0100
Subject: [PATCH] common: accept application/json with parameters
Since 4c21931, a JSON body is accepted only if its Content-Type is
exactly "application/json", so clients that send
"application/json; charset=utf-8" (OkHttp appends the charset) get 415.
Compare the media type case-insensitively and ignore its parameters
(RFC 9110, section 8.3.1; RFC 8259, section 11).
Assisted by LLM
---
common/taler-api/src/extract.rs | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/common/taler-api/src/extract.rs b/common/taler-api/src/extract.rs
index 00f5f8d..2fc9165 100644
--- a/common/taler-api/src/extract.rs
+++ b/common/taler-api/src/extract.rs
@@ -18,7 +18,7 @@ use axum::{
body::{Body, Bytes, HttpBody},
extract::{FromRequest, FromRequestParts, Request},
http::{
- HeaderMap, StatusCode,
+ HeaderMap, HeaderValue, StatusCode,
header::{self, CONTENT_TYPE},
request::Parts,
},
@@ -43,6 +43,17 @@ fn unsupported_media_type(message: impl std::fmt::Display) -> ApiError {
)
}
+/// Whether a Content-Type names the media type `application/json`.
+///
+/// The type and subtype are compared case-insensitively, and parameters are
+/// ignored (RFC 9110, section 8.3.1): JSON defines none, and a charset
+/// "really has no effect on compliant recipients" (RFC 8259, section 11).
+/// Clients built on OkHttp, for one, send `application/json; charset=utf-8`.
+fn is_json(content_type: &HeaderValue) -> bool {
+ let media_type = content_type.as_bytes().split(|b| *b == b';').next();
+ media_type.is_some_and(|t| t.trim_ascii().eq_ignore_ascii_case(b"application/json"))
+}
+
pub async fn decompressed_strict_body<const MAX_SIZE: usize>(
headers: &HeaderMap,
body: Body,
@@ -55,7 +66,7 @@ pub async fn decompressed_strict_body<const MAX_SIZE: usize>(
};
match headers.get(header::CONTENT_TYPE) {
- Some(value) if value.as_bytes() == b"application/json" => {}
+ Some(value) if is_json(value) => {}
Some(_) => return Err(unsupported_media_type("Bad Content-Type header")),
None => return Err(unsupported_media_type("Missing Content-Type header")),
}
--
2.47.3
| ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-19 11:46 | bot-cg | New Issue | |
| 2026-11-19 11:46 | bot-cg | Implementer | => Antoine A |
| 2026-11-19 11:46 | bot-cg | Reviewer | => Florian Dold |
| 2026-11-19 11:46 | bot-cg | Release signed by | => Antoine A |
| 2026-11-19 11:46 | bot-cg | Deployed by | => Antoine A |
| 2026-11-19 11:46 | bot-cg | Verifier | => Antoine A |
| 2026-11-19 11:46 | bot-cg | Communicator | => CM_7 |
| 2026-11-19 11:47 | bot-cg | File Added: taler-api-content-type-parameters-master.patch |