Skip to content
RCE Disclosed report Advanced CVE-2021-22884CVE-2018-7160

DNS rebinding in --inspect (insufficient fix of CVE-2018-7160)

The Node.js debugger's DNS rebinding protection whitelists the hostname 'localhost6', which is often not defined in the hosts file and therefore resolved via DNS. An attacker who controls DNS responses can rebind that name to [redacted] and reach the debugger, gaining remote code execution.

v6ak Follow

Originally disclosed on HackerOne

Bounty$500 High 7.5 View original
  • Triaged in 13 days
  • Fixed in 54 days
  • Paid in 55 days
  • Disclosed after 54 days

Summary: While the debugger (i.e., the --inspect option) tries to prevent DNS rebinding, the whitelist is excessive.

Description: The whitelist includes “localhost6”, which is not that widespread. When “localhost6” is not present in /etc/hosts, it is just an ordinary domain that is resolved via DNS, i.e., over network. If the attacker controls victim's DNS server or can spoof its responses, the DNS rebinding protection can be bypassed by using the “localhost6” domain. As long as the attacker uses the “localhost6” domain, they can still apply the attack described in CVE-2018-7160.

Reasoning why localhost6 is not so common and Node.js should not rely on its presence in the hosts file:

Steps To Reproduce:

Preconditions: Victim has no entry for localhost6 in hosts and attacker controls DNS responses. (It does not matter if the attacker control the DNS server or the network communication between the DNS server and the victim.)

  1. Victim runs node with --inspect option
  2. Victim visits attacker's webpage
  3. The attacker's webpage opens http://localhost6:9229
  4. Victim finds no “localhost6” entry in hosts file, so it asks the DNS server and gets <attacker's-IP>. (Maybe the response will have a short TTL. There are multiple tricks to make DNS rebinding successful in a short time, but I am not going to be exhaustive.)
  5. Victim loads webpage http://localhost6:9229 from <attacker's-IP>.
  6. The webpage http://localhost6:9229 tries to load http://localhost6:9229/json from attacker's server. (If the IP address of “localhost6” is still cached, attacker needs to retry. There are techniques that can speed it up, like using RST packet.)
  7. Due to a short TTL, the DNS server will be soon asked again about an entry for “localhost6”. This time, the DNS server responds “127.0.0.1”.
  8. The http://localhost6:9229 website (i.e., the one hosted on <attacker's IP>) will retrieve http://localhost6:9229/json from 127.0.0.1, including webSocketDebuggerUrl.
  9. Now, the attacker knows the webSocketDebuggerUrl and can connect to is using WebSocket. Note that WebSocket is not restricted by same-origin-policy. By doing so, they can gain the privileges of the Node.js instance.

Vulnerable code: https://github.com/nodejs/node/blob/fdf0a84e826d3a9ec0ce6f5a3f5adc967fe99408/src/inspector_socket.cc#L584

Impact:

Attacker can gain access to the Node.js debugger, which can result in remote code execution.

Supporting Material/References:

Impact

Attacker can gain access to the Node.js debugger, which can result in remote code execution.

The original report as published on HackerOne, by v6ak. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Node.js ships a debugger that is enabled with the --inspect option. When it is on, the process opens an inspector endpoint that speaks the Chrome DevTools Protocol over HTTP and WebSocket, so a developer can attach a debugger and evaluate code inside the running process. Because that endpoint is powerful, Node.js tries to keep it away from web pages: a browser page that reaches the inspector could otherwise drive the debugger.

CVE-2018-7160 was the earlier DNS rebinding issue against this endpoint. The fix introduced a host whitelist in the inspector socket code, so that only certain hostnames are accepted in the Host header of requests to the inspector. This report is about that whitelist being too broad: it contains localhost6, a name that is not reliably mapped to the loopback address on the victim's machine.

Setup

The preconditions are stated plainly in the report:

  1. The victim has no entry for localhost6 in their hosts file.
  2. The attacker controls DNS responses for the victim. It does not matter whether the attacker controls the DNS server itself or the network communication between the DNS server and the victim.
  3. The victim runs Node.js with the --inspect option.

The report gives three observations for why localhost6 should not be trusted:

  • It is not present in the node:latest Docker image (sha256:[redacted]).
  • The researcher has not seen it in Windows 10.
  • Unlike RFC 6761 for localhost, the researcher found no RFC that mentions localhost6.

Finding it

The debugger's DNS rebinding protection relies on a whitelist of hostnames. That whitelist includes localhost6. On systems where localhost6 is defined in /etc/hosts, the name resolves locally and is harmless. Where it is absent, localhost6 is just an ordinary domain name that is resolved through DNS, over the network. If the attacker can control or spoof those DNS responses, the name can be pointed at an attacker-controlled address first and at [redacted] afterwards, which is exactly the rebinding primitive the whitelist was meant to block. As long as the attacker uses the localhost6 domain, the attack described in CVE-2018-7160 still applies.

The vulnerable code is in src/inspector_socket.cc:

Text
https://github.com/nodejs/node/blob/[redacted]/src/inspector_socket.cc#L584

Exploitation

Step 1: the victim starts the inspector

The victim runs Node.js with the --inspect option, so the inspector endpoint is listening locally.

Step 2: the victim visits the attacker's page

The victim browses to a page controlled by the attacker.

Step 3: the page opens the inspector hostname

The attacker's page opens http://localhost6:9229. The report uses port 9229 in this URL.

Step 4: the name is resolved through DNS

Because the victim has no localhost6 entry in the hosts file, the browser asks the DNS server and receives the attacker's IP address. The response may carry a short TTL. The report notes that there are multiple tricks to make DNS rebinding succeed in a short time, without listing them exhaustively.

Step 5: the attacker's content is served under that name

The victim loads the page http://localhost6:9229 from the attacker's IP address. The origin the browser now associates with the name is the attacker's server.

Step 6: the page requests the inspector's JSON endpoint

The page at http://localhost6:9229 tries to load http://localhost6:9229/json from the attacker's server. If the IP address of localhost6 is still cached, the attacker needs to retry. Techniques such as sending an RST packet can speed this up.

Step 7: the name is rebound to loopback

Because of the short TTL, the DNS server is asked again about localhost6 soon afterwards. This time it answers [redacted].

Step 8: the same origin now reaches the inspector

The page at http://localhost6:9229, still the one hosted on the attacker's IP, retrieves http://localhost6:9229/json from [redacted]. The response includes webSocketDebuggerUrl. The page retrieves the JSON response from [redacted], including webSocketDebuggerUrl.

Step 9: the attacker drives the debugger

With the webSocketDebuggerUrl known, the attacker connects to it over WebSocket. WebSocket is not restricted by the same-origin policy, so the connection succeeds. Through it, the attacker gains the privileges of the Node.js instance.

Root cause

The inspector's DNS rebinding defence is a hostname whitelist, and the whitelist trusts localhost6 as if it were a loopback name. On a host without a localhost6 hosts entry, the name is resolved by DNS like any other domain, so an attacker who controls or spoofs DNS answers can make it point wherever they like, including at [redacted] after an initial attacker-controlled answer. The whitelist therefore does not actually pin the request to the local machine, and the protection added for CVE-2018-7160 can be bypassed. The report frames this as an insufficient fix of that CVE.

Impact

The attacker can gain access to the Node.js debugger, which can result in remote code execution. This depends on the preconditions above: the victim must run Node.js with --inspect, must have no localhost6 hosts entry, and the attacker must control or spoof DNS responses for the victim.

Fix

The report does not describe a specific patch. The direction it argues for is that Node.js should not rely on localhost6 being present in the hosts file, given that it is absent from the node:latest Docker image, was not seen on Windows 10, and is not covered by an RFC comparable to RFC 6761 for localhost. The report argues Node.js should not rely on localhost6 being present in the hosts file.

Variants to test

  • Check other hostnames in the inspector whitelist that are not guaranteed to resolve locally on every platform, and see whether any of them can be resolved through DNS on a default installation. A positive result is a name accepted by the inspector that the victim's resolver sends to the network.
  • Test the same pattern in other developer tools that bind to loopback and validate the Host header against a name list. A positive result is a whitelisted name that resolves externally on a stock image or OS.
  • Reproduce the rebinding flow against a local --inspect instance with a controlled resolver, using a short TTL and a switch from the attacker's address to [redacted]. A positive result is reading /json from the inspector through the rebound name and obtaining webSocketDebuggerUrl.

Hunting notes

This kind of bug hides in hostname and origin allowlists used as a substitute for binding checks, especially in debugging, admin and development servers that listen on loopback. During recon, look for names in such lists that are not standard on the platforms you care about, and check whether they appear in /etc/hosts or resolve through DNS on default images and operating systems. The report made the impact concrete by walking the full chain from a victim visiting an attacker page to obtaining webSocketDebuggerUrl and connecting over WebSocket, and by tying it back to the earlier CVE it bypasses.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

Node.js is a program that lets people run JavaScript code outside a web browser. It is used to build web servers, command-line tools and lots of other software. It comes with a built-in debugging feature that you switch on with an option called --inspect. When that option is on, Node.js opens a small door on your own computer that a developer tool can connect to, so the developer can pause the program, look at what it is doing and even run new code inside it. That door is very powerful: anyone who can reach it can do almost anything the program itself can do.

Because the door is so powerful, Node.js tries to make sure that only the developer's own tools can reach it, and not random web pages that the developer happens to have open in a browser. A few years before this report, someone found a trick to get around that protection, and it was given the name CVE-2018-7160. A CVE is a public catalogue number for a known security flaw, a bit like a case number for a bug. Node.js fixed that first problem by keeping a list of names it would accept, and this report is about that list being too generous. The list included a name, localhost6, that on many computers is not actually tied to the local machine, so an attacker who controls the way names are looked up can abuse it and get back in through the same door.

The background you need

What the debugger does

When you start Node.js with --inspect, the program starts a small web server inside itself. That server speaks two languages. One is ordinary HTTP, the same language your browser uses to fetch web pages. The other is WebSocket, which is a way for a browser and a server to keep a two-way conversation open instead of asking for a page and hanging up. The debugger uses a standard set of messages called the Chrome DevTools Protocol, which is the same protocol the developer tools in Google Chrome use. So the picture is: your Node.js program is running, and next to it there is a little web server that a developer tool can talk to in order to control the program.

An API is simply a defined way for two programs to talk to each other, like a menu of requests one side is allowed to make and the answers it will get back. The inspector's HTTP side is an API: you ask it for a particular address and it gives you back information in a format called JSON, which is just structured text that programs can read easily.

Why a web page must not reach it

Here is the danger. Suppose you are running Node.js with the debugger on, and you open a random website in your browser. If that website could send requests to the debugger on your own machine and read the answers, the website's author could take control of your program. That is why Node.js tries to block it.

DNS, hosts files and loopback

Computers find each other by numbers called IP addresses, but people prefer names. DNS is the system that turns a name into an IP address, like a phone book for the internet. When your computer needs to know the address for a name, it usually asks a DNS server somewhere on the network, and that server answers.

There is a shortcut, though. Every computer has a small local file called the hosts file (on Linux and macOS it lives at /etc/hosts). It is a private list of name-to-address pairs that the computer checks before asking anyone else. If a name is in that file, the computer uses the address written there and never goes to the network.

One special address is [redacted]. It always means "this very computer", and it is called the loopback address. The name localhost is normally set up in the hosts file to point at [redacted], so when you type localhost you are talking to your own machine. There is an official internet document, RFC 6761, that says localhost should always be handled this way. An RFC is a numbered document published by the internet standards community that describes how things should work.

What DNS rebinding is

DNS rebinding is a clever trick that gets around a browser rule called the same-origin policy. That rule says a web page loaded from one place may not read data from a different place. The browser decides what counts as "the same place" by the name in the address, not by the IP address behind it.

The trick works like this. The attacker owns a name, and at first that name points at the attacker's own server. The victim's browser loads a page from that name, so the browser now trusts that name. Then the attacker changes the DNS answer so the same name points at [redacted], the victim's own machine. The browser still thinks it is talking to the same trusted place, because the name has not changed, but the requests now land on the victim's own computer. That is how a web page can reach a service running on the victim's machine.

What the earlier fix did

When the first version of this attack, CVE-2018-7160, was reported, Node.js added a defence. Every HTTP request carries a small piece of information called the Host header, which says which name the request was aimed at. The inspector started checking that header against a list of allowed names, a whitelist. If the name in the request was not on the list, the request was refused. The idea was that only names that mean "this machine" would be on the list, so a rebound name could not get through.

The setup the attack needs

The report states three preconditions plainly:

  1. The victim has no entry for localhost6 in their hosts file.
  2. The attacker controls the DNS answers the victim receives. It does not matter whether the attacker runs the DNS server itself or sits on the network between the DNS server and the victim and alters the replies.
  3. The victim runs Node.js with the --inspect option.

The report gives three observations for why localhost6 should not be trusted:

  • It is not present in the node:latest Docker image (sha256:[redacted]). Docker is a tool for packaging software into ready-made containers, and node:latest is the standard Node.js container image, so this shows that a very common setup does not have the name defined locally.
  • The researcher has not seen it in Windows 10.
  • Unlike RFC 6761 for localhost, the researcher found no RFC that mentions localhost6.

Finding it

The debugger's protection against DNS rebinding is that whitelist of hostnames, and the whitelist includes localhost6. On a system where localhost6 is written in /etc/hosts, the name is answered locally and there is no problem. On a system where it is missing, localhost6 is just an ordinary domain name, and ordinary domain names are looked up through DNS, over the network. If the attacker can control or fake those DNS answers, the name can be made to point at an attacker-controlled address first and at [redacted] afterwards. That is exactly the rebinding trick the whitelist was supposed to stop. As long as the attacker uses the localhost6 domain, the attack from CVE-2018-7160 still works.

The vulnerable code is in src/inspector_socket.cc:

Text
https://github.com/nodejs/node/blob/[redacted]/src/inspector_socket.cc#L584

This is a link to the exact file and line in the Node.js source code where the inspector handles incoming connections. The report points at it so the maintainers can see where the whitelist lives. The link itself is not a request or a command; it is a pointer to the code.

Exploitation, step by step

Step 1: the victim starts the inspector

The victim runs Node.js with the --inspect option, so the inspector endpoint is listening locally. This is the normal way a developer turns the debugger on. The door is now open on the victim's own machine.

Step 2: the victim visits the attacker's page

The victim browses to a page controlled by the attacker. This is the moment the attacker gets code running in the victim's browser. Nothing has gone wrong yet; the browser is just showing a web page.

Step 3: the page opens the inspector hostname

The attacker's page opens http://localhost6:9229. The report uses port 9229 in this URL. A port is like a numbered door on a computer: one machine can run many services, and each listens on its own number. The report uses port 9229 in this URL.

Step 4: the name is resolved through DNS

Because the victim has no localhost6 entry in the hosts file, the browser asks the DNS server and receives the attacker's IP address. The answer may carry a short TTL. TTL stands for time to live: it tells the browser how many seconds it may keep the answer before asking again. A short TTL means the browser will come back for a fresh answer soon, which is what the attacker wants. The report notes that there are multiple tricks to make DNS rebinding succeed in a short time, without listing them exhaustively.

Step 5: the attacker's content is served under that name

The victim loads the page http://localhost6:9229 from the attacker's IP address. The browser now associates that name with the attacker's server. This is the trust-building part of the trick: from now on, the browser treats anything at localhost6 as the same place as this page.

Step 6: the page requests the inspector's JSON endpoint

The page at http://localhost6:9229 tries to load http://localhost6:9229/json from the attacker's server. The page requests the inspector's /json endpoint. The attacker's page asks for it while the name still points at the attacker, so the attacker can see the request and answer it. If the IP address of localhost6 is still cached, the attacker needs to retry. Techniques such as sending an RST packet can speed this up. An RST packet is a network message that abruptly closes a connection, and it can be used to make the browser drop its cached connection sooner.

Step 7: the name is rebound to loopback

Because of the short TTL, the DNS server is asked again about localhost6 soon afterwards. This time it answers [redacted]. The name has not changed, but the address behind it now points at the victim's own machine. This is the rebinding moment.

Step 8: the same origin now reaches the inspector

The page at http://localhost6:9229, still the one hosted on the attacker's IP, retrieves http://localhost6:9229/json from [redacted]. The response includes webSocketDebuggerUrl. That is a field in the JSON answer that gives the address the debugger can be reached on over WebSocket. The page retrieves the JSON response from [redacted], including webSocketDebuggerUrl. The same-origin policy has been defeated without ever breaking it.

Step 9: the attacker drives the debugger

With the webSocketDebuggerUrl known, the attacker connects to it over WebSocket. WebSocket is not restricted by the same-origin policy, so the connection succeeds. Through it, the attacker gains the privileges of the Node.js instance. In plain terms, the attacker's web page is now talking directly to the debugger inside the victim's program, and the debugger will do what it is told.

Why it works

The inspector's defence against DNS rebinding is a list of hostnames, and that list trusts localhost6 as if it were a name for the local machine. On a computer without a localhost6 entry in its hosts file, the name is looked up through DNS like any other domain. So an attacker who controls or fakes DNS answers can make it point wherever they like, including at [redacted] after an initial answer that pointed at the attacker. The list therefore does not actually pin the request to the local machine, and the protection added for CVE-2018-7160 can be bypassed. The report frames this as an insufficient fix of that earlier CVE.

Impact

The attacker can gain access to the Node.js debugger, which can result in remote code execution. Remote code execution means running your own code on someone else's machine, which is about as bad as it gets. This depends on the preconditions above: the victim must run Node.js with --inspect, must have no localhost6 hosts entry, and the attacker must control or fake DNS answers for the victim.

The fix

The report does not describe a specific patch. The direction it argues for is that Node.js should not rely on localhost6 being present in the hosts file, given that it is absent from the node:latest Docker image, was not seen on Windows 10, and is not covered by an RFC comparable to RFC 6761 for localhost. The report argues Node.js should not rely on localhost6 being present in the hosts file.

Variants to test

  • Check other hostnames in the inspector whitelist that are not guaranteed to resolve locally on every platform, and see whether any of them can be resolved through DNS on a default installation. A positive result is a name accepted by the inspector that the victim's resolver sends to the network.
  • Test the same pattern in other developer tools that bind to loopback and validate the Host header against a name list. A positive result is a whitelisted name that resolves externally on a stock image or operating system.
  • Reproduce the rebinding flow against a local --inspect instance with a controlled resolver, using a short TTL and a switch from the attacker's address to [redacted]. A positive result is reading /json from the inspector through the rebound name and obtaining webSocketDebuggerUrl.

Hunting notes

This kind of bug hides in hostname and origin allowlists used as a substitute for binding checks, especially in debugging, admin and development servers that listen on loopback. During recon, look for names in such lists that are not standard on the platforms you care about, and check whether they appear in /etc/hosts or resolve through DNS on default images and operating systems. The report made the impact concrete by walking the full chain from a victim visiting an attacker page to obtaining webSocketDebuggerUrl and connecting over WebSocket, and by tying it back to the earlier CVE it bypasses.

Glossary

  • Node.js: a program that runs JavaScript code outside a web browser, often used to build servers and tools.
  • --inspect: the option that turns on Node.js's built-in debugger.
  • Debugger: a tool that lets a developer pause a running program, inspect it and run code inside it.
  • Inspector endpoint: the small web server Node.js starts when the debugger is on, which developer tools connect to.
  • HTTP: the language browsers and servers use to exchange web pages and data.
  • WebSocket: a way for a browser and a server to keep a two-way conversation open.
  • Chrome DevTools Protocol: the standard set of messages used to control a debugger, the same one Chrome's developer tools use.
  • API: a defined menu of requests one program can make to another and the answers it gets back.
  • JSON: structured text that programs can read easily.
  • CVE: a public catalogue number for a known security flaw.
  • CVE-2018-7160: the earlier DNS rebinding issue against the Node.js inspector, which this report says was fixed insufficiently.
  • DNS: the system that turns a name into an IP address, like a phone book for the internet.
  • DNS server: the computer that answers DNS lookups.
  • IP address: the number that identifies a computer on a network.
  • Hosts file: a small local file of name-to-address pairs that a computer checks before asking DNS.
  • /etc/hosts: the location of the hosts file on Linux and macOS.
  • Loopback address: [redacted], which always means "this very computer".
  • localhost: the standard name for the local machine, normally mapped to [redacted].
  • localhost6: a name the inspector whitelist accepted, which is not reliably mapped to the local machine.
  • RFC: a numbered document from the internet standards community describing how something should work.
  • RFC 6761: the document that says localhost should always be handled locally.
  • Same-origin policy: the browser rule that a page from one place may not read data from a different place.
  • Origin: what the browser considers "the same place", decided by the name in the address.
  • DNS rebinding: a trick where a name first points at the attacker and later at the victim's own machine, so the browser thinks it is still talking to the same place.
  • Host header: a small piece of information in every HTTP request saying which name the request was aimed at.
  • Whitelist: a list of things that are allowed.
  • Port: a numbered door on a computer, so one machine can run many services.
  • 9229: the inspector's default port.
  • TTL: time to live, how many seconds a DNS answer may be kept before asking again.
  • RST packet: a network message that abruptly closes a connection.
  • /json: the inspector's API address that lists what is available to connect to.
  • webSocketDebuggerUrl: the field in that answer giving the address to reach the debugger over WebSocket.
  • Remote code execution: running your own code on someone else's machine.
  • CVSS: a scoring system for how severe a security flaw is.
  • Bounty: money paid to a researcher for reporting a security flaw.
  • Docker: a tool for packaging software into ready-made containers.
  • node:latest: the standard Node.js Docker container image.
  • Recon: the information-gathering phase of security testing.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.