@@ -47,6 +47,47 @@ OS X). As of Node 7 this activates the legacy Debugger API; in Node 8 and later
47
47
it will activate the Inspector API.
48
48
49
49
---
50
+ ## Security Implications
51
+
52
+ Since the debugger has full access to the Node.js execution environment, a
53
+ malicious actor able to connect to this port may be able to execute arbitrary
54
+ code on behalf of the Node process. It is important to understand the security
55
+ implications of exposing the debugger port on public and private networks.
56
+
57
+ ### Exposing the debug port publicly is unsafe
58
+
59
+ If the debugger is bound to a public IP address, or to 0.0.0.0, any clients that
60
+ can reach your IP address will be able to connect to the debugger without any
61
+ restriction and will be able to run arbitrary code.
62
+
63
+ By default ` node --inspect ` binds to 127.0.0.1. You explicitly need to provide a
64
+ public IP address or 0.0.0.0, etc., if you intend to allow external connections
65
+ to the debugger. Doing so may expose you a potentially significant security
66
+ threat. We suggest you ensure appropriate firewalls and access controls in place
67
+ to prevent a security exposure.
68
+
69
+ See the section on '[ Enabling remote debugging scenarios] ( #enabling-remote-debugging-scenarios ) ' on some advice on how
70
+ to safely allow remote debugger clients to connect.
71
+
72
+ ### Local applications have full access to the inspector
73
+
74
+ Even if you bind the inspector port to 127.0.0.1 (the default), any applications
75
+ running locally on your machine will have unrestricted access. This is by design
76
+ to allow local debuggers to be able to attach conveniently.
77
+
78
+ ### Browsers, WebSockets and same-origin policy
79
+
80
+ Websites open in a web-browser can make WebSocket and HTTP requests under the
81
+ browser security model. An initial HTTP connection is necessary to obtain a
82
+ unique debugger session id. The same-origin-policy prevents websites from being
83
+ able to make this HTTP connection. For additional security against
84
+ [ DNS rebinding attacks] ( https://en.wikipedia.org/wiki/DNS_rebinding ) , Node.js
85
+ verifies that the 'Host' headers for the connection either
86
+ specify an IP address or ` localhost ` or ` localhost6 ` precisely.
87
+
88
+ These security policies disallow connecting to a remote debug server by
89
+ specifying the hostname. You can work-around this restriction by specifying
90
+ either the IP address or by using ssh tunnels as described below.
50
91
51
92
## Inspector Clients
52
93
@@ -161,6 +202,36 @@ The following table lists the impact of various runtime flags on debugging:
161
202
162
203
---
163
204
205
+ ## Enabling remote debugging scenarios
206
+
207
+ We recommend that you never have the debugger listen on a public IP address. If
208
+ you need to allow remote debugging connections we recommend the use of ssh
209
+ tunnels instead. We provide the following example for illustrative purposes only.
210
+ Please understand the security risk of allowing remote access to a privileged
211
+ service before proceeding.
212
+
213
+ Let's say you are running Node on remote machine, remote.example.com, that you
214
+ want to be able to debug. On that machine, you should start the node process
215
+ with the inspector listening only to localhost (the default).
216
+
217
+ ``` sh
218
+ $ node --inspect server.js
219
+ ```
220
+
221
+ Now, on your local machine from where you want to initiate a debug client
222
+ connection, you can setup an ssh tunnel:
223
+
224
+ ```
225
+ $ ssh -L 9221:localhost:9229 [email protected]
226
+ ```
227
+
228
+ This starts a ssh tunnel session where a connection to port 9221 on your local
229
+ machine will be forwarded to port 9229 on remote.example.com. You can now attach
230
+ a debugger such as Chrome DevTools or Visual Studio Code to localhost:9221,
231
+ which should be able to debug as if the Node.js application was running locally.
232
+
233
+ ---
234
+
164
235
## Legacy Debugger
165
236
166
237
** The legacy debugger has been deprecated as of Node 7.7.0. Please use --inspect
0 commit comments