chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.6k stars 828 forks source link

SSL Error in when Upgrading from node 16 to 18 #979

Closed didiaoshengjianbao closed 3 months ago

didiaoshengjianbao commented 3 months ago

Checks

Describe the bug (be clear and concise)

When I try to upgrade from node 16 to 18, I met the error thrown like belows: Forward api error: write EPROTO C0FACBFD01000000:error:0A000410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1605:SSL alert number 40 All is ok when I use 16 to start my node, any walkround for this?

Step-by-step reproduction instructions

1. using node 18
2. error thrown
3. switch to node 16, all is ok, but I have to use node 18 for some reasons.

Expected behavior (be clear and concise)

No Error throwm

How is http-proxy-middleware used in your project?

"http-proxy-middleware": "^2.0.2",

What http-proxy-middleware configuration are you using?

server.use(context,
      createProxyMiddleware(requestURIConfig + context, {
        logLevel: 'debug',
        // replace target config with router config for dynamic matching
        router: (req) => getTarget(req).url,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          // @see https://github.com/chimurai/http-proxy-middleware#http-proxy-middleware-options
          [`^${requestURIConfig}${context}`]: '',
        },
        onProxyReq(proxyReq, req) {
          const user = getUser(req);

          if (user) {
            proxyReq.setHeader(HEADER_USER_ID, user);
          }
          if (checkNeedToken(req)) {
            proxyReq.setHeader(HEADER_TOKEN, tokenResult[user] || '');
            proxyReq.setHeader(IHUB_TOKEN, vertexLogHeader[user].ihubToken || '');
            proxyReq.setHeader(TNONCE, vertexLogHeader[user].tnonce || '');
          }
          overrideSlackHeader(proxyReq, req);
          overrideDataDogHeader(proxyReq, req);
          addIdentityRoleHeader(proxyReq, req);
          headersHandler(proxyReq, getTarget(req));
          logger.log({ type: 'context', name: 'forward', message: `forward-request: ${req?.path}` }, req);
          logger.log({ type: 'context', name: 'forward', message: `forward_headers_final: ${JSON.stringify(req?.headers)}` }, req);
        },
        onProxyRes(proxyRes, req) {
          const { headers } = proxyRes;
          // disable cache for API forwarding.
          headers['Cache-Control'] = 'no-store';
          logger.log({ type: 'context', name: 'received', message: `forward-received: ${req.path}` }, req);
        },
        onError(err, req, res) {
          logger.error(`Forward api error: ${err.message}.`, req);
          res.writeHead(500, {
            'Content-Type': 'text/plain',
          });
          res.end('Something went wrong. We are reporting a custom error message.');
        },
      }))

What OS/version and node/version are you seeing the problem?

Macos:14.4
Node 18

Additional context (optional)

No response

didiaoshengjianbao commented 3 months ago

More info: I upgrade to the latest version and still got the same ssl error

image
chimurai commented 3 months ago

Looks more like a certificate issue than a proxy issue.

Without minimal reproduction there is little I can do.

Did you try to enable DEBUG?

# show only HPM debug info (only available in HPM v3)
DEBUG=http-proxy-middleware* node server.js
# show all debug info
DEBUG=* node server.js

https://github.com/chimurai/http-proxy-middleware?tab=readme-ov-file#debugging

didiaoshengjianbao commented 3 months ago

It's cert issue, not related to the lib.