Base64-encode binary response bodies in the C++ NetworkingModule#57214
Closed
sathoshik wants to merge 1 commit into
Closed
Base64-encode binary response bodies in the C++ NetworkingModule#57214sathoshik wants to merge 1 commit into
sathoshik wants to merge 1 commit into
Conversation
Summary: The ReactCxxPlatform `NetworkingModule` delivered response bodies to JS verbatim regardless of the requested `responseType`. For binary response types (`responseType` `arraybuffer`, which the JS `XMLHttpRequest` layer maps to the native `base64` type), JS calls `base64.toByteArray()` on the delivered string. Sending the raw bytes therefore caused the payload to be mis-decoded and corrupted — e.g. `JSON.parse` failures on responses fetched as `arraybuffer`. Encode the body with base64 for `base64` responses, matching the existing Android (`NetworkingModule.kt` via `Base64.encodeToString(..., NO_WRAP)`) and iOS (`RCTNetworking.mm` via `base64EncodedStringWithOptions:0`) implementations. The encoding reuses the shared `react/utils` `base64Encode` helper already used by `jsinspector-modern`. All other response types are delivered unchanged. The per-`responseType` decision lives in a file-local (anonymous-namespace) `encodeResponseBody` helper in `NetworkingModule.cpp`, so it adds no surface to the public C++ API. Changelog: [General][Fixed] - Base64-encode binary (arraybuffer/blob) response bodies in the C++ NetworkingModule so they are not corrupted when delivered to JS Differential Revision: D108440201
|
@sathoshik has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108440201. |
|
This pull request has been merged in 1127e54. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
The ReactCxxPlatform
NetworkingModuledelivered response bodies to JS verbatim regardless of the requestedresponseType. For binary response types (responseTypearraybuffer, which the JSXMLHttpRequestlayer maps to the nativebase64type), JS callsbase64.toByteArray()on the delivered string. Sending the raw bytes therefore caused the payload to be mis-decoded and corrupted — e.g.JSON.parsefailures on responses fetched asarraybuffer.Encode the body with base64 for
base64responses, matching the existing Android (NetworkingModule.ktviaBase64.encodeToString(..., NO_WRAP)) and iOS (RCTNetworking.mmviabase64EncodedStringWithOptions:0) implementations. The encoding reuses the sharedreact/utilsbase64Encodehelper already used byjsinspector-modern. All other response types are delivered unchanged. The per-responseTypedecision lives in a file-local (anonymous-namespace)encodeResponseBodyhelper inNetworkingModule.cpp, so it adds no surface to the public C++ API.Changelog:
[General][Fixed] - Base64-encode binary (arraybuffer/blob) response bodies in the C++ NetworkingModule so they are not corrupted when delivered to JS
Differential Revision: D108440201