ai-proxy forwards client `Transfer-Encoding: chunked` but sends an unchunked body (upstream 400)

オープン 初心者向け
#14,152 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@locker95 がすでに取り組んでいます。

2026年11月7日 から。

  • #14172 @locker95 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
lua, nginx

調査の方向性

apisix/plugins/ai-transport/http.lua の86~91行付近にあるブラックリストから始め、construct_forward_headers がクライアントヘッダーをどのように処理するかを追ってください。転送されたヘッダーに関するトランスポートテストを確認し、チャンク化されたクライアントリクエストのテストを追加してください。upstream が正しく再フレーミングされたボディヘッダーを受信し、回帰テストが成功すれば完了です。

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

説明

Summary

ai-proxy forwards the client's Transfer-Encoding: chunked header to the upstream, but the body it
sends is not chunked. content-length is explicitly stripped by the same blacklist, so the
upstream receives a framing contradiction and a real HTTP/1.1 server rejects it with 400.

Where (pin b6deb41; identical in release 3.19.0)

apisix/plugins/ai-transport/http.lua:86-91 — the blacklist that is supposed to remove hop-by-hop
framing headers:

local blacklist = {
    "host",
    "content-length",
    "accept-encoding",
}

transfer-encoding is missing. Every other client header is copied
(apisix/plugins/ai-proxy/base.lua:291 → extra_opts.client_headers = core.request.headers(ctx),
merged at apisix/plugins/ai-providers/base.lua:237). The body is then a known Lua string, so the
transport sends it unchunked.

Repro (hard)

# transport client using the real construct_forward_headers, rawdump upstream on :8889
curl -s -X POST 'http://127.0.0.1:9083/poc?port=8889' -H 'Transfer-Encoding: chunked' -H 'X-Foo: a' -d 'xxxxxxxx'
# against a real nginx upstream that reads the body (:9082/echo)
curl -s -X POST 'http://127.0.0.1:9083/poc?port=9082' -H 'Transfer-Encoding: chunked' -d 'xxxxxxxx'

Observed on the rawdump:

POST /echo HTTP/1.1
transfer-encoding: chunked          <-- and no Content-Length
...
<raw JSON body, not chunked>

→ real nginx upstream: status=400. Without the client header: Content-Length: 62 + raw body →
status=200.

Impact

Any client that legitimately uses chunked upload against an ai-proxy route can get a 400 from the
upstream, i.e. the request never reaches the model. CVSS 3.1
AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L = 6.5.

CWE-436 / CWE-444.

Suggestion

Either add transfer-encoding to the blacklist (the body is re-framed anyway, so it should not be
forwarded verbatim), or actually chunk the body when the header is passed through. Adding it to the
blacklist matches the existing intent, since content-length is treated the same way.

Notes

Found while auditing b6deb41; apisix/plugins/ai-transport/http.lua is byte-identical to the
3.19.0 release commit and unchanged on main today. Introduced by be45f233 (three-layer AI proxy
refactor, #13170). A sibling report about the same forwarded-header path (ai-cache fingerprint)
is filed separately.

主要言語
Lua
スター
17.3k
フォーク
3k
平均マージ
3日 2時間
マージ済み PR(30日)
63

環境構築

Codespaces で開く

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

はじめの一歩

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

apache/apisix のほかの issue

apache/apisix の issue をすべて見る

似ている issue

Lua の issue をもっと見る

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

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