Skip to content

How to use fetch() from utility process with self-signed certs / custom proxy settings? #44727

Description

@thomas-jakemeyn

Preflight Checklist

Problem Description

Context

It is possible to use net.fetch() from a utility process. As stated here in the documentation:

This method will issue requests from the default session. To send a fetch request from another session, use ses.fetch().

So using net.fetch() in a utility process basically comes down to using session.defaultSession.fetch().

Requirement

I need to use session.setCertificateVerifyProc() in order to accept self-signed certificates from a given certificate authority. However, I want that logic to be limited to the task performed by a utility process. So I would like to do the following in a utility process:

  • create a session that is specific to that utility process (using session.fromPartition())
  • call setCertificateVerifyProc() on that specific session
  • to then call fetch() on that specific session

Problem

session is undefined in the context of a utility process.

Proposed Solution

Make session available in the context of a utility process.

Note that this could maybe help reconcile the 2 different ways of setting proxy configuration (see below, this is error-prone).

const config = { proxyRules };

// Set proxy settings for main process and renderer processes
session.defaultSession.setProxy(config);

// Set proxy settings for utility process
app.setProxy(config);

Alternatives Considered

NA

Additional Information

No response

Activity

  1. deepak1556 commented on Nov 19, 2024

    @deepak1556
    Member

    So using net.fetch() in a utility process basically comes down to using session.defaultSession.fetch()

    Actually that is not what happens today, the doc needs improvement. Requests from utility process do not use the default session, rather they use a hidden network context that is scoped to the app which is not exposed. Hence the proxy settings for this process also get applied via app.setProxy.

    In the current implementation, we would need a app.setCertificateVerifyProc(). However, I don't want to go down the path of duplicating every session specific api for the app network context. It is possible to support a session for the utility process, but it has to happen at the time of creating the process similar to how we do it for webContents, something like

    utilityProcess.fork(.., {
      session?: Session 
    })
    

    Also for design reasons, the session object cannot be accessed inside the utility process which means net.request({session: ...}) will still remain a no-op.

  2. thomas-jakemeyn commented on Nov 19, 2024

    @thomas-jakemeyn
    Author

    Actually that is not what happens today, the doc needs improvement. Requests from utility process do not use the default session, rather they use a hidden network context that is scoped to the app which is not exposed. Hence the proxy settings for this process also get applied via app.setProxy.

    This is probably what explains the issue #44264...

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions