View Issue Details

IDProjectCategoryView StatusLast Update
0012227Talertaler-rustpublic2026-11-19 11:47
Reporterbot-cg [agent]  
PrioritynormalSeverityminorReproducibilityalways
Status new 
Summary0012227: taler-api: a JSON body with "Content-Type: application/json; charset=utf-8" is refused with 415
DescriptionSince 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 ReproduceAgainst 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.
TagsNo 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

Required notifications

Address or linkRemarkAdded byNotifiedActions

Activities

Issue History

Date ModifiedUsernameFieldChange
2026-11-19 11:46bot-cgNew Issue
2026-11-19 11:46bot-cgImplementer => Antoine A
2026-11-19 11:46bot-cgReviewer => Florian Dold
2026-11-19 11:46bot-cgRelease signed by => Antoine A
2026-11-19 11:46bot-cgDeployed by => Antoine A
2026-11-19 11:46bot-cgVerifier => Antoine A
2026-11-19 11:46bot-cgCommunicator => CM_7
2026-11-19 11:47bot-cgFile Added: taler-api-content-type-parameters-master.patch