[Bug]: json-xml-mediator policy accepts XML with more than one root element

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

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

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

評価

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

調査の方向性

json-xml-mediatorポリシーのXML解析経路から始めます。issueには、xml.Unmarshalが最初の要素を読み取り、後続の内容を無視すると記載されています。ポリシーの不正なXMLに関するテストを確認し、ルート要素が2つあるドキュメントのテストを追加します。そのリクエストが500を返し、バックエンドに転送されなければ完了です。

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

説明

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

Gateway

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

The policy parses XML with xml.Unmarshal, which reads the first element and stops. Anything after that element is ignored.

So a document with two root elements is not well-formed, yet it passes. The policy converts the first element, drops the rest and forwards the result. The backend never learns that part of the request was lost.

Malformed XML that fails inside the first element is rejected with 500, as the policy documentation describes for malformed payloads.

Expected Behaviour

The request is rejected with 500 and does not reach the backend.

Actual Behaviour

The gateway answers 200. The backend receives {"order":{"sku":"W-1"}}, and the second <order> is lost.

Steps to Reproduce
  1. Create a REST API with the policy on a POST operation:
    {"name":"json-xml-mediator","version":"v1","params":{"downsteamPayloadFormat":"xml","upstreamPayloadFormat":"json"}}
    
  2. Send <order><sku>W-1</sku></orders> with Content-Type: application/xml. The gateway answers 500, and the backend is not called.
  3. Send <order><sku>W-1</sku></order><order><sku>G-2</sku></order>. The gateway answers 200, and the backend receives {"order":{"sku":"W-1"}}.
Severity Level of the Issue

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

Environment Details (with versions)
  • Gateway versions: 1.1.0, 1.2.0 and latest
  • Policy: json-xml-mediator v1.1.0, wso2/gateway-controllers main 5b8e3367
  • Upstream: a test service that records the request body
主要言語
Go
スター
85
フォーク
142
平均マージ
1日 6時間
マージ済み PR(30日)
250

環境構築

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

はじめの一歩

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

wso2/api-platform のほかの issue

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

似ている issue

Go の issue をもっと見る

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

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