[Bug]: content-length-guardrail policy counts SSE events without content as their whole JSON text

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

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

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

評価

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

調査の方向性

Start by locating the content-length-guardrail policy implementation and its tests for streaming JSONPath extraction. Reproduce the report with an SSE stream containing a content event followed by an empty delta finish event, then check how the policy handles a valid JSON event with no value at the configured path. Done means the event contributes zero bytes and the stream passes when its actual content is within the configured limits.

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

説明

Area/Policies Aspect/AI Severity/Major Type/Bug
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/AI (AI/LLM integration, MCP, AI readiness)

Description

The content-length-guardrail policy counts an SSE event with no content as content. When an event has no value at streamingJsonPath, the policy adds the event's whole JSON text to the response length. It should add zero bytes.

Real providers send such events in every stream. OpenAI ends each stream with a finish event whose delta is empty:

data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

With the default path, $.choices[0].delta.content, this event adds 59 bytes. A stream with usage reporting adds a usage event as well. Some providers also send a first event that holds only the role.

The extra bytes change the policy's decisions:

  • A reply within max is blocked when the extra bytes take it over.
  • A reply shorter than min passes when the extra bytes take it over min.
  • The policy releases a held-back stream earlier than the content alone would.

The doc says the policy uses the JSONPath "to extract the incremental token text" from each event. An event with no token text should add nothing.

A fix could count zero bytes for an event that is valid JSON but has no value at streamingJsonPath. Whether a data line that is not JSON should still count as content is a separate choice.

The integration suite in wso2/gateway-controllers#415 asserts the current behaviour.

Steps to Reproduce
  1. Create a REST API with the content-length-guardrail policy on an operation:
    {"name":"content-length-guardrail","version":"v1","params":{"response":{"enabled":true,"min":1,"max":20}}}
    
  2. Send a request whose upstream replies with this SSE stream. Its only content is abc, 3 bytes:
    data: {"choices":[{"delta":{"content":"abc"}}]}
    
    data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
    
    data: [DONE]
    
  3. The stream ends with the guardrail's SSE error event, and [DONE] never reaches the client. The policy counts 62 bytes: 3 for abc and 59 for the finish event.
  4. Send the same stream without the finish event. It passes with abc and [DONE].
Severity Level of the Issue

Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)

Environment Details (with versions)
  • Policy: content-length-guardrail v1.1.0, wso2/gateway-controllers main (4f1520a8)
  • Gateway versions: 1.1.0 (patched), 1.2.0 and latest (main-59dcd51)
  • macOS 27.0.1 (Apple silicon), Colima 0.10.3, Docker Engine 29.5.2
主要言語
Go
スター
85
フォーク
137
平均マージ
1日 12時間
マージ済み PR(30日)
247

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

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

wso2/api-platform のほかの issue

wso2/api-platform の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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