stoplightio / prism

Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.

Home Page:https://stoplight.io/open-source/prism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prism proxy modifying files

Freeshnik opened this issue · comments

Inb4 thank you for great tool!

Issue Description:
When using the Prism proxy to proxy requests to another backend, it has been observed that the library is modifying files during the proxy process.
This behavior is unexpected and can lead to validation errors.

Steps to Reproduce:

Choose a Prism version v5.2.0.
Set up a proxy configuration to forward requests to a target backend server (e.g., http://backend.example.com).
Initiate a request to the proxy server, providing a URL that should be forwarded to the backend.
Monitor the content of the files that are being proxied and compare them to the original content.

Expected Behavior:
The library should act as a transparent proxy, forwarding requests to the target backend without altering the content of the files being proxied.
The files received from the backend should remain unchanged and identical to the original files.

Actual Behavior:
During the proxy process, the library is modifying the content of the files being proxied.
File comparison functions (utilizing PHP's built-in functions) indicate disparate hashes between files. Moreover, methods for retrieving Mime-Type yield distinct outcomes. For instance, the original file, characterized by the Mime-Type 'application/vnd.ms-excel' (denoting an .xls file), undergoes a transformation during proxying, resulting in a Mime-Type alteration to 'application/octet-stream'.
Additionally, there is a discrepancy in file sizes. In the original context, the file has a size of 7680 bytes, whereas after passing through the Prism proxy, its size increases to 10942 bytes.

Impact:

Validation problems: File not pass validation rules based on mime-type.
Data Corruption: The modifications introduced by the library during proxying can lead to data corruption, making the proxied content unusable or inconsistent with the original data.

Additional Information:

Library Version: v5.2.0

Workaround:
At this time, there is no known workaround to prevent the library from modifying files during the proxy process.
Users are advised to avoid using the proxy functionality of the affected library until the issue is resolved.

Proposed Solution:
Investigate the codebase of the library to identify the root cause of the file modifications during the proxy process. Implement a fix that ensures the content of proxied files remains unchanged when passed through the proxy.

Environment:
OS Ubuntu 20.04
PHP programming language to validate hash values and ascertain Mime-Types.

@Freeshnik , thanks for your report. At this time, Prism doesn't support binary data in either mock or proxy mode. However, we agree that it should and welcome PRs, especially for the easier proxy case.