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

Open Beginner friendly
#4,468 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, json, xml

Research direction

Start in the json-xml-mediator policy's XML parsing path, where the issue says xml.Unmarshal reads the first element and ignores trailing content. Check the policy's tests for malformed XML and add coverage for a document with two root elements. Done means that request returns 500 and is not forwarded to the backend.

Written by the indexing model from the issue text.

Description

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
Dominant language
Go
Stars
85
Forks
142
Avg merge
1d 6h
Merged PRs (30d)
250

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.