5
5
* This source code is licensed under the license found in the LICENSE file in
6
6
* the root directory of this source tree.
7
7
*
8
- * @flow strict-local
8
+ * @flow
9
9
* @format
10
10
*/
11
11
@@ -17,6 +17,7 @@ import type {
17
17
import { SshHandshake } from '../../nuclide-remote-connection' ;
18
18
19
19
import { shell } from 'electron' ;
20
+ import escapeHtml from 'escape-html' ;
20
21
import child_process from 'child_process' ;
21
22
22
23
export function notifySshHandshakeError (
@@ -28,52 +29,59 @@ export function notifySshHandshakeError(
28
29
let detail = '' ;
29
30
let buttons = [ ] ;
30
31
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
+
31
41
const createTimeoutDetail = ( ) =>
32
42
'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` +
34
44
'Check your .bashrc / .bash_profile for extraneous output.\n' +
35
45
'You may need to add the following to the top of your .bashrc:\n' +
36
46
' [ -z "$PS1" ] && return' ;
37
47
38
48
switch ( errorType ) {
39
49
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 } .` ;
41
51
detail =
42
52
'Troubleshooting:\n' +
43
53
' 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` ;
45
55
break ;
46
56
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 } .` ;
50
58
detail =
51
59
'Make sure the private key path is properly configured.\n' +
52
60
'You may need to convert your private key from PKCS to RSA.\n' +
53
61
originalErrorDetail ;
54
62
break ;
55
63
case 'SSH_CONNECT_TIMEOUT' :
56
- message = `Timeout while connecting to ${ config . host } .` ;
64
+ message = `Timeout while connecting to ${ host } .` ;
57
65
detail =
58
66
'Troubleshooting:\n' +
59
67
' 1. Check your network connection.\n' +
60
68
' 2. Input correct 2Fac passcode when prompted.' ;
61
69
break ;
62
70
case 'SFTP_TIMEOUT' :
63
- message = `Timeout while connecting to ${ config . host } .` ;
71
+ message = `Timeout while connecting to ${ host } .` ;
64
72
detail = createTimeoutDetail ( ) ;
65
73
break ;
66
74
case 'USER_CANCELLED' :
67
- message = `User cancelled while connecting to ${ config . host } .` ;
75
+ message = `User cancelled while connecting to ${ host } .` ;
68
76
detail = createTimeoutDetail ( ) ;
69
77
break ;
70
78
case 'SSH_CONNECT_FAILED' :
71
- message = `Failed to connect to ${ config . host } :${ config . sshPort } .` ;
79
+ message = `Failed to connect to ${ host } :${ sshPort } .` ;
72
80
detail =
73
81
'Troubleshooting:\n' +
74
82
' 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` +
77
85
originalErrorDetail ;
78
86
break ;
79
87
case 'SSH_AUTHENTICATION' :
@@ -102,30 +110,24 @@ export function notifySshHandshakeError(
102
110
default :
103
111
message = 'Unknown SSH Authentication Method failed' ;
104
112
detail =
105
- `Unknown authentication method '${
106
- config . authMethod
107
- } ' provided. Make sure your` +
113
+ `Unknown authentication method '${ authMethod } ' provided. Make sure your` +
108
114
' SSH connection is properly configured.' ;
109
115
break ;
110
116
}
111
117
break ;
112
118
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 } .` ;
115
121
break ;
116
122
case 'SERVER_START_FAILED' :
117
123
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 } ` ;
120
126
detail =
121
127
'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` +
125
129
' 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` +
129
131
' by running "killall node", and reconnect.\n\n\n' +
130
132
originalErrorDetail ;
131
133
break ;
0 commit comments