Skip to content

Commit

Permalink
Issue 365: allow host to be specified from http host headers
Browse files Browse the repository at this point in the history
  • Loading branch information
butlerx committed Jan 29, 2022
1 parent 031910b commit 7ddf405
Show file tree
Hide file tree
Showing 6 changed files with 1,022 additions and 1,004 deletions.
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ const opts = yargs
'Allow WeTTY to be embedded in an iframe, defaults to allowing same origin',
type: 'boolean',
})
.option('allow-remote-hosts', {
description:
'Allow WeTTY to use the `host` param in a url as ssh destination',
type: 'boolean',
})
.option('help', {
alias: 'h',
type: 'boolean',
Expand Down
52 changes: 31 additions & 21 deletions src/server/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,39 @@ export function getCommand(
conn: { remoteAddress },
},
}: Socket,
{ user, host, port, auth, pass, key, knownHosts, config }: SSH,
{
user,
host,
port,
auth,
pass,
key,
knownHosts,
config,
allowRemoteHosts,
}: SSH,
command: string,
forcessh: boolean,
): [string[], boolean] {
const sshAddress = address(headers, user, host);
const localLogin = !forcessh && localhost(host);
return localLogin
? [loginOptions(command, remoteAddress), localLogin]
: [
sshOptions(
{
...urlArgs(headers.referer, {
port: `${port}`,
pass: pass || '',
command,
auth,
knownHosts,
config: config || '',
}),
host: sshAddress,
},
key,
),
user !== '' || user.includes('@') || sshAddress.includes('@'),
];
if (!forcessh && localhost(host)) {
return [loginOptions(command, remoteAddress), true];
}
const args = urlArgs(headers.referer, {
host: sshAddress,
port: `${port}`,
pass: pass || '',
command,
auth,
knownHosts,
config: config || '',
});
if (!allowRemoteHosts) {
args.host = sshAddress;
}

return [
sshOptions(args, key),
user !== '' || user.includes('@') || sshAddress.includes('@'),
];
}
1 change: 1 addition & 0 deletions src/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export function mergeCliConf(opts: Arguments, config: Config): Config {
port: opts['ssh-port'],
pass: opts['ssh-pass'],
key: opts['ssh-key'],
allowRemoteHosts: opts['allow-remote-hosts'],
config: opts['ssh-config'],
knownHosts: opts['known-hosts'],
}) as SSH,
Expand Down
1 change: 1 addition & 0 deletions src/shared/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const sshDefault: SSH = {
key: process.env.SSHKEY || undefined,
port: parseInt(process.env.SSHPORT || '22', 10),
knownHosts: process.env.KNOWNHOSTS || '/dev/null',
allowRemoteHosts: false,
config: process.env.SSHCONFIG || undefined,
};

Expand Down
1 change: 1 addition & 0 deletions src/shared/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface SSH {
auth: string;
port: number;
knownHosts: string;
allowRemoteHosts: boolean;
pass?: string;
key?: string;
config?: string;
Expand Down
Loading

0 comments on commit 7ddf405

Please sign in to comment.