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

Abierto Apto para principiantes
#4,468 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go, json, xml

Línea de trabajo

Empieza en la ruta de análisis XML de la política json-xml-mediator, donde el issue indica que xml.Unmarshal lee el primer elemento e ignora el contenido restante. Revisa las pruebas de la política para XML malformado y añade cobertura para un documento con dos elementos raíz. Se considera terminado cuando esa solicitud devuelve 500 y no se reenvía al backend.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Go
Estrellas
85
Forks
142
Merge medio
1 d 6 h
PR fusionados (30 d)
250

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de wso2/api-platform

Todos los issues de wso2/api-platform

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.