Skip to content

[Bug]: net.fetch fails on manual redirect #43715

Closed as not planned
Closed as not planned

Description

@chrmarti

Preflight Checklist

Electron Version

30.4.0, 32.1.0

What operating system(s) are you using?

macOS

Operating System Version

Sonoma

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

unknown

Expected Behavior

using redirect: 'manual' net.fetch should return with the redirect response.

Actual Behavior

using redirect: 'manual' net.fetch fails with an 'Error: Redirect was cancelled'

Testcase Gist URL

https://gist.github.com/510aba6af66a8bbecf31682d8098cf25

Additional Information

No response

Activity

  1. added
    has-repro-gist
    on Sep 13, 2024
  2. MarshallOfSound commented on Sep 13, 2024

    @MarshallOfSound
    Member

    This is working as documented, the request is cancelled if you don't call followRedirect inside the redirect event when redirect mode is manual.

    Ref: https://www.electronjs.org/docs/latest/api/client-request#event-redirect

  3. chrmarti commented on Sep 13, 2024

    @chrmarti
    Author

    I see ClientRequest being return from net.request, but I don't see how I would get a ClientRequest with net.fetch. It seems the only way for redirect: 'manual' to work with net.fetch, the returned Response would have to hold the redirect status. This is how Node.js' fetch implements redirect: 'manual'.

    I'm trying use net.fetch as a drop-in for the global fetch from Node.js because net.fetch comes with proxy support and loads certificates from the OS.

  4. deepak1556 commented on Sep 14, 2024

    @deepak1556
    Member

    @MarshallOfSound this might be a bug in our net.fetch implementation. The spec mentions if mode is not navigate then an opaqueResponse should be provided. We are missing the handling of redirect event in the implementation today.

    Node.js fetch response also seems different from the spec, ref wpt tests https://github.com/web-platform-tests/wpt/blob/master/fetch/api/redirect/redirect-mode.any.js

    > fetch(`http://localhost:3001/redirect`, { redirect: 'manual' }).then(console.log, console.error)
    Promise {
      <pending>,
      [Symbol(async_id_symbol)]: 140,
      [Symbol(trigger_async_id_symbol)]: 139
    }
    > Response {
      status: 302,
      statusText: 'Found',
      headers: Headers {
        location: '/',
        date: 'Sat, 14 Sep 2024 01:55:46 GMT',
        connection: 'keep-alive',
        'keep-alive': 'timeout=5',
        'transfer-encoding': 'chunked'
      },
      body: ReadableStream { locked: false, state: 'readable', supportsBYOB: true },
      bodyUsed: false,
      ok: false,
      redirected: false,
      type: 'basic',
      url: 'http://localhost:3001/redirect'
    }
    
  5. deepak1556 commented on Sep 16, 2024

    @deepak1556
    Member

    Okay Node.js implementation was initially following the spec but it was later changed per nodejs/undici#1193.

    What should be the behavior we match in our net.Fetch API for this case ?

  6. deepak1556 commented on Sep 16, 2024

    @deepak1556
    Member

    For browsers opaque responses are needed for preventing xss attacks https://fetch.spec.whatwg.org/#atomic-http-redirect-handling. In Electron, users already can use Node.js fetch in these process to get those responses, so if we were to align net.fetch behavior we are not increasing the risk any higher. Also, the api is meant to offer easy migration for users from Node.js fetch to use chromium network stack, so aligning their behaviors would be better in this case.

  7. jaouadeljadiri commented on Sep 24, 2024

    @jaouadeljadiri
  8. jhudson8 commented on Oct 8, 2024

    @jhudson8

    this also prevents (AFAIK) conditionally but completely intercepting http/s protocol by preventing the browser from following redirects.

    Appologies for the dumb question but Is anyone aware of an alternative solution to implement this currently using net.request (the issue here being a complete reproduction of the GlobalRequest to ClientRequest to listen for the 'redirect' event)?

    protocol.handle('http', (request) => {
      if (shouldOverride) {
        // do my own thing
      } else {
        // if I want to leverage Chromium for Kerberos SSO and other benefits but the renderer must follow redirects so orgin is correct on future requests
       return net.fetch(request, {
         bypassCustomProtocolHandlers: true,
         redirect: 'manual'
        });
      }
    }
    
  9. self-assigned this
    on Nov 19, 2024
  10. electron-issue-triage commented on Feb 18, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  11. 7 remaining items

  12. namonakimono commented on Mar 27, 2025

    @namonakimono

    Same issue +1

  13. electron-issue-triage commented on Jun 26, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  14. xiaoshuangLi commented on Jun 26, 2025

    @xiaoshuangLi

    Same issue +1

  15. jhudson8 commented on Aug 29, 2025

    @jhudson8

    Has there been any movement on this or any idea of an ETA?

    Once complete, how would we get a reference to cancel a redirect with net.fetch? I'm looking to NOT follow any redirects.

    Thanks so much.

  16. electron-issue-triage commented on Nov 28, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  17. removed their assignment
    on Nov 28, 2025
  18. electron-issue-triage commented on Feb 27, 2026

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  19. electron-issue-triage commented on Mar 29, 2026

    @electron-issue-triage

    This issue has been closed due to inactivity, and will not be monitored. If this is a bug and you can reproduce this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲component/nethas-repro-gistplatform/macOSstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions