-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-jvmr-5fpx-r76j
* Enforce allowlist for query parameters Also mitigate other argument injection * Add allow-remote-command option
- Loading branch information
Showing
10 changed files
with
85 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
import _ from 'lodash'; | ||
import { Socket } from 'socket.io'; | ||
import { login } from '../login.js'; | ||
import { escapeShell } from '../shared/shell.js'; | ||
import type { IncomingHttpHeaders } from 'http'; | ||
|
||
export function address( | ||
headers: IncomingHttpHeaders, | ||
export async function address( | ||
socket: Socket, | ||
user: string, | ||
host: string, | ||
): string { | ||
): Promise<string> { | ||
// Check request-header for username | ||
const remoteUser = headers['remote-user']; | ||
if (!_.isUndefined(remoteUser) && !Array.isArray(remoteUser)) { | ||
return `${escapeShell(remoteUser)}@${host}`; | ||
} | ||
if (!_.isUndefined(headers.referer)) { | ||
const match = headers.referer.match('.+/ssh/([^/]+)$'); | ||
if (match) { | ||
const username = escapeShell(match[1].split('?')[0]); | ||
return `${username}@${host}`; | ||
const { request: { headers: { | ||
'remote-user': userFromHeader, | ||
referer | ||
} } } = socket; | ||
|
||
let username: string | undefined; | ||
if (!_.isUndefined(userFromHeader) && !Array.isArray(userFromHeader)) { | ||
username = userFromHeader; | ||
} else { | ||
const userFromPathMatch = referer?.match('.+/ssh/([^/]+)$'); | ||
if (userFromPathMatch) { | ||
// eslint-disable-next-line prefer-destructuring | ||
username = userFromPathMatch[1].split('?')[0]; | ||
} else if (user) { | ||
username = user; | ||
} else { | ||
username = await login(socket); | ||
} | ||
} | ||
return user ? `${escapeShell(user)}@${host}` : host; | ||
return `${escapeShell(username)}@${host}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const escapeShell = (username: string): string => | ||
// eslint-disable-next-line no-useless-escape | ||
username.replace(/^-|[^a-zA-Z0-9_\\\-\.\@-]/g, ''); | ||
username.replace(/[^a-zA-Z0-9_\\\-\.\@-]/g, '').replace(/^-+/g, ''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters