Skip to content

fix(request): reject non-string header values before the bridge - #499

Merged
RonRadtke merged 1 commit into
RonRadtke:masterfrom
cpruijsen:fix/issue-472-4f271cb9
Nov 9, 2026
Merged

RonRadtke merged 1 commit into
RonRadtke:masterfrom
cpruijsen:fix/issue-472-4f271cb9

Conversation

@cpruijsen

Copy link
Copy Markdown

Fixes #472.

invalidHeader in utils/request.js now rejects a header value that is not a string with EINVAL, before any native call or event listener. It used to coerce the value with String() for its CR/LF/NUL check, so an object passed as '[object Object]' and the raw value went to native, where no platform gave JS an error it could catch:

  • Android: ReadableMap.getString throws Value for <key> cannot be cast from ReadableNativeMap to String, which is the crash in the issue.
  • iOS: the current Swift code silently drops a header that is not a string. The issue reports a crash on 0.24.9.
  • Windows: JSValue::AsString() sends a number or boolean as text and an object as "".

null and undefined values are still sent as "", as documented.

Numbers and booleans are rejected too: RequestHeaders already declares values as string | null | undefined, and rejecting them gives the same result on all three platforms. The cost is that a numeric header that works on Windows today now rejects there, and the caller's fix is String(value). If you would rather coerce numbers and booleans and reject only objects and arrays, that is a small change.

The new case in tests/unit/requestHardening.test.js covers object, array, number and boolean values and checks for EINVAL, the header name in the message, no native call and no leaked listener. It fails without the fix (the request resolves) and passes with it.

Native reads every header value as a string, so a value of another type -
an object a caller passed by mistake, a number, an array - could not cross
the bridge: Android died on the ReadableNativeMap cast and iOS crashed
without a visible error, before any JS could catch it.

invalidHeader now refuses non-string values, so the call rejects EINVAL in
JS like the other request-validation failures, before any native call or
event listener is registered. fetch still normalises null and undefined
headers to an empty string.

Fixes #472.
@RonRadtke
RonRadtke merged commit 4a84024 into RonRadtke:master Nov 9, 2026
3 of 11 checks passed
RonRadtke added a commit that referenced this pull request Nov 9, 2026
The pull requests merged since 1.1.0 (#498, #499, #501, #503, #505, #507)
and the fixes from a pass over the open issues (#197, #334, #377, #384,
#390, #411/#256, #425, #486). Migration.md lists each change under 1.1.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fatal native error: ReactNativeBlobUtil request error: Value for <key> cannot be cast from ReadableNativeMap to Stringnull

2 participants