Skip to content

Fix XMLHttpRequest cancellation before native request creation - #59806

Open
shoutoutuoadi325 wants to merge 1 commit into
react:mainfrom
shoutoutuoadi325:fix/xhr-stale-request-creation
Open

shoutoutuoadi325 wants to merge 1 commit into
react:mainfrom
shoutoutuoadi325:fix/xhr-stale-request-creation

Conversation

@shoutoutuoadi325

Copy link
Copy Markdown

Summary:

An iOS upload can be aborted while native networking is still constructing its body, before its request ID is returned. The delayed creation callback then attaches the cancelled request to the XHR. If the XHR has been reused for a retry, this can replace the new request's ID, deliver the old response, or leave the new request unfinished.

Capture the request generation in send() and invalidate it in reset(). A creation callback from an obsolete generation cancels its native request and returns before changing the XHR or reporting it to the interceptor. Add regression coverage for both callback orders, abort before creation, stale response isolation, and normal cancellation after creation.

Fixes #59805.

Changelog:

[IOS][FIXED] - Cancel XMLHttpRequest requests created after abort without overwriting a reused request's identifier.

Test Plan:

  • Network and Blob Jest suites: 5 suites / 59 tests passed.

    corepack yarn test packages/react-native/Libraries/Network packages/react-native/Libraries/Blob --runInBand
    
  • XHR suite: 18 tests passed. Three new race cases fail on unpatched main and when the latest stable v0.88.1 XHR source is substituted into the same Jest harness.

  • The four new cases also pass with haste.defaultPlatform set to android. A full Android resolution override has two pre-existing failures (custom performance logger and sorted response headers); both were confirmed with the original source and original tests. The repository's default iOS resolution suite passes completely.

  • Static checks passed:

    corepack yarn eslint packages/react-native/Libraries/Network/XMLHttpRequest.js packages/react-native/Libraries/Network/__tests__/XMLHttpRequest-test.js --max-warnings 0
    corepack yarn prettier --check packages/react-native/Libraries/Network/XMLHttpRequest.js packages/react-native/Libraries/Network/__tests__/XMLHttpRequest-test.js
    git diff --check
    
  • RNTester Playground and server provide a native reproducer with a delayed URI upload body. The server endpoints and Playground Babel transformation were verified locally. An iOS simulator build was not run because CocoaPods is unavailable in this environment.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 07:41
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XMLHttpRequest abort before iOS request creation can corrupt a reused request

2 participants