Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit bfe5003

Browse files
matthewwithanmfacebook-github-bot
authored andcommitted
Escape connection config for notifications
Reviewed By: wanderley Differential Revision: D9523253 fbshipit-source-id: b676701a287b202324ba4e1eefa2d011486aafb6
1 parent 6e8f6f4 commit bfe5003

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

pkg/nuclide-remote-projects/lib/notification.js

+28-26
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*
8-
* @flow strict-local
8+
* @flow
99
* @format
1010
*/
1111

@@ -17,6 +17,7 @@ import type {
1717
import {SshHandshake} from '../../nuclide-remote-connection';
1818

1919
import {shell} from 'electron';
20+
import escapeHtml from 'escape-html';
2021
import child_process from 'child_process';
2122

2223
export function notifySshHandshakeError(
@@ -28,52 +29,59 @@ export function notifySshHandshakeError(
2829
let detail = '';
2930
let buttons = [];
3031
const originalErrorDetail = `Original error message:\n ${error.message}`;
32+
33+
// This comes from people and people can't be trusted. Escape it before dumping it into the DOM.
34+
const host = escapeHtml(config.host);
35+
const remoteServerCommand = escapeHtml(config.remoteServerCommand);
36+
const cwd = escapeHtml(config.cwd);
37+
const sshPort = escapeHtml(config.sshPort.toString());
38+
const pathToPrivateKey = escapeHtml(config.pathToPrivateKey);
39+
const authMethod = escapeHtml(config.authMethod);
40+
3141
const createTimeoutDetail = () =>
3242
'Troubleshooting:\n' +
33-
`Make sure you can run "sftp ${config.host}" on the command line.\n` +
43+
`Make sure you can run "sftp ${host}" on the command line.\n` +
3444
'Check your .bashrc / .bash_profile for extraneous output.\n' +
3545
'You may need to add the following to the top of your .bashrc:\n' +
3646
' [ -z "$PS1" ] && return';
3747

3848
switch (errorType) {
3949
case 'HOST_NOT_FOUND':
40-
message = `Can't resolve IP address for host ${config.host}.`;
50+
message = `Can't resolve IP address for host ${host}.`;
4151
detail =
4252
'Troubleshooting:\n' +
4353
' 1. Check your network connection.\n' +
44-
` 2. Make sure the hostname ${config.host} is valid.\n`;
54+
` 2. Make sure the hostname ${host} is valid.\n`;
4555
break;
4656
case 'CANT_READ_PRIVATE_KEY':
47-
message = `Can't read content of private key path ${
48-
config.pathToPrivateKey
49-
}.`;
57+
message = `Can't read content of private key path ${pathToPrivateKey}.`;
5058
detail =
5159
'Make sure the private key path is properly configured.\n' +
5260
'You may need to convert your private key from PKCS to RSA.\n' +
5361
originalErrorDetail;
5462
break;
5563
case 'SSH_CONNECT_TIMEOUT':
56-
message = `Timeout while connecting to ${config.host}.`;
64+
message = `Timeout while connecting to ${host}.`;
5765
detail =
5866
'Troubleshooting:\n' +
5967
' 1. Check your network connection.\n' +
6068
' 2. Input correct 2Fac passcode when prompted.';
6169
break;
6270
case 'SFTP_TIMEOUT':
63-
message = `Timeout while connecting to ${config.host}.`;
71+
message = `Timeout while connecting to ${host}.`;
6472
detail = createTimeoutDetail();
6573
break;
6674
case 'USER_CANCELLED':
67-
message = `User cancelled while connecting to ${config.host}.`;
75+
message = `User cancelled while connecting to ${host}.`;
6876
detail = createTimeoutDetail();
6977
break;
7078
case 'SSH_CONNECT_FAILED':
71-
message = `Failed to connect to ${config.host}:${config.sshPort}.`;
79+
message = `Failed to connect to ${host}:${sshPort}.`;
7280
detail =
7381
'Troubleshooting:\n' +
7482
' 1. Check your network connection.\n' +
75-
` 2. Make sure the host ${config.host} is running and has` +
76-
` ssh server running on ${config.sshPort}.\n\n` +
83+
` 2. Make sure the host ${host} is running and has` +
84+
` ssh server running on ${sshPort}.\n\n` +
7785
originalErrorDetail;
7886
break;
7987
case 'SSH_AUTHENTICATION':
@@ -102,30 +110,24 @@ export function notifySshHandshakeError(
102110
default:
103111
message = 'Unknown SSH Authentication Method failed';
104112
detail =
105-
`Unknown authentication method '${
106-
config.authMethod
107-
}' provided. Make sure your` +
113+
`Unknown authentication method '${authMethod}' provided. Make sure your` +
108114
' SSH connection is properly configured.';
109115
break;
110116
}
111117
break;
112118
case 'DIRECTORY_NOT_FOUND':
113-
message = `There is no such directory ${config.cwd} on ${config.host}.`;
114-
detail = `Make sure ${config.cwd} exists on ${config.host}.`;
119+
message = `There is no such directory ${cwd} on ${host}.`;
120+
detail = `Make sure ${cwd} exists on ${host}.`;
115121
break;
116122
case 'SERVER_START_FAILED':
117123
message =
118-
`Failed to start nuclide-server on ${config.host} using ` +
119-
`${config.remoteServerCommand}`;
124+
`Failed to start nuclide-server on ${host} using ` +
125+
`${remoteServerCommand}`;
120126
detail =
121127
'Troubleshooting: \n' +
122-
` 1. Make sure the command "${
123-
config.remoteServerCommand
124-
}" is correct.\n` +
128+
` 1. Make sure the command "${remoteServerCommand}" is correct.\n` +
125129
' 2. The server might take longer to start up than expected, try to connect again.\n' +
126-
` 3. If none of above works, ssh to ${
127-
config.host
128-
} and kill existing nuclide-server` +
130+
` 3. If none of above works, ssh to ${host} and kill existing nuclide-server` +
129131
' by running "killall node", and reconnect.\n\n\n' +
130132
originalErrorDetail;
131133
break;

0 commit comments

Comments
 (0)