diff --git a/packages/server/src/app.rs b/packages/server/src/app.rs index 6f99d0e..abd64c7 100644 --- a/packages/server/src/app.rs +++ b/packages/server/src/app.rs @@ -45,7 +45,11 @@ pub fn app(state: Arc) -> impl Endpoint { check_origin(&request, &state)?; let json = request .content_type() - .is_some_and(|value| value.starts_with("application/json")); + .and_then(|value| value.parse::().ok()) + .is_some_and(|value| { + value.type_() == mime::APPLICATION + && (value.subtype() == mime::JSON || value.suffix() == Some(mime::JSON)) + }); if json { let bytes = tokio::time::timeout( std::time::Duration::from_secs(10), diff --git a/packages/server/tests/http.rs b/packages/server/tests/http.rs index 5782a3f..553b145 100644 --- a/packages/server/tests/http.rs +++ b/packages/server/tests/http.rs @@ -178,3 +178,29 @@ async fn request_slots_are_held_until_bodies_drain_but_health_stays_available() .await .assert_status_is_ok(); } + +#[tokio::test] +async fn every_json_media_type_accepted_by_poem_gets_the_same_body_limit() { + let (_dir, client, _) = fixture(); + for mime in [ + "application/json", + "application/ld+json", + "Application/JSON", + ] { + let response = client + .post("/oauth/login") + .header("Origin", "http://127.0.0.1:5173") + .header("Content-Type", mime) + .body("x".repeat(1024 * 1024 + 1)) + .send() + .await; + response.assert_status(StatusCode::PAYLOAD_TOO_LARGE); + response + .json() + .await + .value() + .object() + .get("code") + .assert_string("TransferLimit"); + } +}