shouldDownloadAsText corrupts ZIP responses when content-type defined as json or xml is followed by a delimiter (e.g. json-zip)

Aperta Adatta ai principianti
#4,318 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
backend, testing

Direzione di ricerca

Inizia da src/http/serializers/response/index.js, dove l’issue afferma che i tipi di media delle risposte vengono classificati come testo, e verifica come viene effettuata la corrispondenza del tipo di contenuto. Aggiungi casi di regressione per i tipi di media JSON/XML e di archivio elencati, e verifica che una risposta ZIP mantenga i byte originali. Il lavoro è completato quando i documenti JSON/XML restano testo e i tipi ZIP elencati vengono gestiti come dati binari.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

We are experiencing corrupted ZIP downloads when using swagger-client. The issue appears to originate in

https://github.com/swagger-api/swagger-client/blob/841924914d268148f6a3d5c75f9bd4d7ea751708/src/http/serializers/response/index.js#L3

A binary response is treated as text when its media type contains json or xml, even if those strings describe files inside an archive rather than the response body itself.

Minimal reproduction
Return a valid ZIP archive with these headers:

HTTP/1.1 200 OK
Content-Type: application/vnd.sdmx.data+json-zip;version=1.0.0
Content-Disposition: attachment; filename="result.zip"

The response body contains valid ZIP bytes for an archive containing one or more JSON files.
Requesting this endpoint through swagger-client causes the response to be processed as text because the media type contains json.

Expected behavior
The response is handled as binary data, and its bytes remain unchanged.

Actual behavior
The response is decoded as text, resulting in a corrupted ZIP archive.
The same issue can affect other archive media types containing json or xml, for example:

application/vnd.sdmx.genericdata+xml-zip;version=2.1
application/vnd.software602.filler.form-xml-zip

Possible fix
Restrict text detection to media types that actually represent JSON or XML documents, or remove the delimiter as the end of the match.

Suggested regression cases:

application/json -> text
application/problem+json -> text
application/xml -> text
application/atom+xml -> text
application/vnd.sdmx.data+json-zip;version=1.0.0 -> binary
application/vnd.sdmx.genericdata+xml-zip;version=2.1 -> binary
application/vnd.software602.filler.form-xml-zip -> binary
application/zip -> binary

A regression test should also verify that binary response bytes remain unchanged.

Lingua principale
JavaScript
Stelle
2.7k
Fork
764
Merge medio
1g 10h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di swagger-api/swagger-client

Tutte le issue di swagger-api/swagger-client

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.