Skip to content

Getting TypeError: info.replace is not a function when using https.request #58509

@kevgeoleo

Description

@kevgeoleo

Version

v24.1.0

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

No response

What steps will reproduce the bug?

Hi,

You can reproduce the bug using the following code snippet:

const https = require("https");

"use strict";

(function TestDeleteStringRelace() {
  delete String.prototype.replace;
})();
{
  (async function () {
    const options = {
      hostname: "example.com",
      port: 443,
      path: "/",
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
    };
    const req = https.request(options, (res) => {
      let data = "";
      res.on("data", (chunk) => {
        data += chunk;
      });
      res.on("end", () => {
        console.log("Response:", data);
      });
    });
    req.end();
  })();
}

How often does it reproduce? Is there a required condition?

No specific condition

What is the expected behavior? Why is that the expected behavior?

Response: <HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>

You don't have permission to access "http&#58;&#47;&#47;example&#46;com&#47;" on this server.<P>
Reference&#32;&#35;18&#46;8df6d517&#46;1748608252&#46;adec739b
<P>https&#58;&#47;&#47;errors&#46;edgesuite&#46;net&#47;18&#46;8df6d517&#46;1748608252&#46;adec739b</P>
</BODY>
</HTML>

What do you see instead?

node:_tls_common:133
    info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g,
         ^

TypeError: info.replace is not a function
    at translatePeerCertificate (node:_tls_common:133:10)
    at Object.translatePeerCertificate (node:_tls_common:126:27)
    at TLSSocket.getPeerCertificate (node:_tls_wrap:1119:19)
    at TLSSocket.onConnectSecure (node:_tls_wrap:1640:23)
    at TLSSocket.emit (node:events:507:28)
    at TLSSocket._finishInit (node:_tls_wrap:1077:8)
    at ssl.onhandshakedone (node:_tls_wrap:863:12)

Node.js v24.1.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpsIssues or PRs related to the https subsystem.invalidIssues and PRs that are invalid.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions