REST API ignores JSON bodies sent with `Content-Type: application/json; charset=utf-8`

オープン
#6,139 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
json, next.js, typescript
領域
api, backend

調査の方向性

Start with the Node HTTP adapter in src/adapters/node-http/core.ts and src/adapters/node-http/input.ts, and run the provided curl reproduction against the API route in pages/api/[...trpc].ts. Add a regression test for Content-Type: application/json; charset=utf-8, ensuring the media type is compared separately from its parameters. Done means the body reaches input validation, the regression test passes, and Dokploy bumps @dokploy/trpc-openapi to the fixed fork release.

索引モデルが issue の本文から書いたものです。

説明

bug

Summary

A POST /api/<procedure> request with Content-Type: application/json; charset=utf-8 fails with
400 Input validation failed, and every body field is reported as undefined. The same request with
Content-Type: application/json works. charset is a valid media-type parameter (RFC 9110, section
8.3.1), and several HTTP clients add it by default. One example is .NET's JsonContent.

Versions

  • Seen on a Dokploy v0.30.x instance. We do not know the exact patch version.
  • From reading the code (not tested on each release), affected releases are v0.30.3 through v0.31.4
    (the latest release, 2026-11-17) and canary. #5048 set bodyParser: false on the OpenAPI
    catch-all route, and that change first shipped in v0.30.3. In v0.30.0 to v0.30.2, Next.js parsed the
    body itself, and Next.js reads only the media type.
  • @dokploy/trpc-openapi 0.0.18, which every one of these releases pins. 0.0.19 and the fork's main
    (814c8b4) have the same code.

To reproduce

DOKPLOY=https://dokploy.example.com   # placeholder
# A made-up id keeps this harmless: the only question is whether the body is read.
BODY='{"applicationId":"does-not-exist"}'

# 1) Plain media type: the body is parsed. The request gets past input validation
#    and fails later, on the made-up id.
curl -sS -X POST "$DOKPLOY/api/application.stop" \
  -H "x-api-key: $DOKPLOY_API_KEY" \
  -H "Content-Type: application/json" \
  --data "$BODY"

# 2) Same request with a charset parameter: the body is dropped.
curl -sS -X POST "$DOKPLOY/api/application.stop" \
  -H "x-api-key: $DOKPLOY_API_KEY" \
  -H "Content-Type: application/json; charset=utf-8" \
  --data "$BODY"

Expected vs. actual

  • Expected: both requests behave the same, because the body is parsed as JSON in both cases.

  • Actual: request 2 returns HTTP 400 and the procedure never runs. The response looks like this
    (abbreviated):

    {
      "message": "Input validation failed",
      "code": "BAD_REQUEST",
      "issues": [
        {
          "code": "invalid_type",
          "expected": "string",
          "path": ["applicationId"],
          "message": "Invalid input: expected string, received undefined"
        }
      ]
    }
    

Root cause

pages/api/[...trpc].ts disables the Next.js body parser
(v0.31.4, L68-L72).
As a result, @dokploy/trpc-openapi reads the body itself:

  1. core.ts checks the media type with contentType?.startsWith('application/json'). A header with
    ; charset=utf-8 passes this check
    (core.ts L105-L116).
  2. getBody then compares the whole header with the string 'application/json'. With a parameter,
    that comparison fails, so the body is never read and req.body stays undefined
    (input.ts L44-L45).
  3. The input becomes { ...undefined, ...pathInput }, which is {}, and Zod rejects it with a 400.

The fork inherited this comparison from the original trpc-openapi
(trpc/trpc-openapi#230). That repository is
archived and never changed it. The maintained successor fixed it in
mcampa/trpc-to-openapi#177, released in
trpc-to-openapi 3.4.0: it compares only the media type, case-insensitively. The fetch adapter in the
fork already uses includes('application/json') and is not affected.

Workaround

Send exactly Content-Type: application/json, with no parameters. In .NET, for example, set
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json") after
JsonContent.Create(...).

Existing reports

We searched issues and PRs in Dokploy/dokploy, Dokploy/trpc-openapi and trpc/trpc-openapi for
charset and content-type and found no report of this.

Fix

Fix with a regression test: Dokploy/trpc-openapi#6. After a fork release, Dokploy
needs to bump @dokploy/trpc-openapi.

主要言語
TypeScript
スター
38.8k
フォーク
3.2k
平均マージ
1日 10時間
マージ済み PR(30日)
110

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Dokploy/dokploy のほかの issue

Dokploy/dokploy の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。