Skip to content

Can't proxy to a server that uses a self-signed certificate #48117

@seyoon20087

Description

@seyoon20087

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022
    Binaries:
      Node: 18.15.0
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: 7.30.0
    Relevant packages:
      next: 13.3.1-canary.2
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://github.com/seyoon20087/next-proxy-self-signed-certificate-error-reproduction

To Reproduce

Note: I tested this on Gitpod but the following steps might work on other systems, as long as the host OS is based on Unix (i.e. not Windows without a WSL environment).

  1. Clone the repo above
  2. Run yarn install
  3. Run yarn dev
  4. Open http://localhost:3000/c to see whether errors are being observed in the /c route
  5. Also run it with NODE_TLS_REJECT_UNAUTHORIZED environment variable to 0

Describe the Bug

Maybe relevant to #45743 ; however that was closed already, so I am recreating an issue with a reproduction.

Some developers want to connect to a server that uses a self-signed certificate (only in dev-mode). However, this doesn't work even if NODE_TLS_REJECT_UNAUTHORIZED is set to 0.

If I attempt to do that, whether NODE_TLS_REJECT_UNAUTHORIZED is set to 0 or not, it ends up with the following:

$ yarn dev
# ... [truncated]
Failed to proxy https://[self-signed-certificate-server]/ Error: self-signed certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1540:34)
    at TLSSocket.emit (node:events:513:28)
    at TLSSocket.emit (node:domain:489:12)
    at TLSSocket._finishInit (node:_tls_wrap:959:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:743:12) {
  code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
}
error - Error: self-signed certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1540:34)
    at TLSSocket.emit (node:events:513:28)
    at TLSSocket.emit (node:domain:489:12)
    at TLSSocket._finishInit (node:_tls_wrap:959:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:743:12) {
  code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
}

I'm not sure if this is the intentional behavior on Next.js itself.

Expected Behavior

I expected the error above to NOT happen (and Node.js would allow to be connected to that server).

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions