Skip to content

Commit 4e08ac2

Browse files
committed
fix: restore SSO functionality with basic auth credentials
- Pass SSH credentials from basic auth session to client config in connectionHandler - Add webssh2Config placeholder to client index.html for proper injection - Enable autoConnect when credentials are provided via basic auth - Credentials now properly flow from HTTP basic auth to WebSocket session - bump webssh2_client@2.0.0-alpha.6 chore: update example Dockerfile to `node:22-alpine`
1 parent 52b6180 commit 4e08ac2

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

Dockerfile

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
# Use debian:bookworm-slim runtime as a parent image
2-
FROM debian:bookworm-slim
1+
# Use node:22-alpine as a parent image for smallest size and best security
2+
FROM node:22-alpine
33

4-
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
5-
6-
RUN apt-get update \
7-
&& apt-get install -y curl \
8-
&& apt-get -y autoclean
9-
10-
# nvm environment variables
11-
ENV NVM_DIR /usr/local/nvm
12-
ENV NODE_VERSION 22
13-
14-
RUN mkdir -p $NVM_DIR
15-
16-
# install nvm
17-
# https://github.com/creationix/nvm#install-script
18-
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
19-
20-
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
21-
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
22-
23-
RUN echo "source $NVM_DIR/nvm.sh && \
24-
nvm install $NODE_VERSION && \
25-
nvm alias default $NODE_VERSION && \
26-
nvm use default" | bash
4+
# Alpine uses ash shell by default, which is sufficient for our needs
5+
# No need to install bash unless specifically required
276

287
# Set the working directory in the container
298
WORKDIR /usr/src/app

app/connectionHandler.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { promises as fs } from 'fs'
55
import path from 'path'
66
import { createNamespacedDebug } from './logger.js'
77
import { HTTP, MESSAGES, DEFAULTS } from './constants.js'
8-
import { modifyHtml } from './utils.js'
8+
import { modifyHtml, maskSensitiveData } from './utils.js'
99
import { getClientPublicPath } from './client-path.js'
1010
const debug = createNamespacedDebug('connectionHandler')
1111

@@ -43,6 +43,27 @@ async function handleConnection(req, res) {
4343
autoConnect: req.path.startsWith('/host/'), // Automatically connect if path starts with /host/
4444
}
4545

46+
// Include SSH credentials from session when using basic auth
47+
if (req.session.usedBasicAuth && req.session.sshCredentials) {
48+
tempConfig.ssh = {
49+
host: req.session.sshCredentials.host,
50+
port: req.session.sshCredentials.port,
51+
username: req.session.sshCredentials.username,
52+
password: req.session.sshCredentials.password,
53+
...(req.session.sshCredentials.privateKey && { privateKey: req.session.sshCredentials.privateKey }),
54+
...(req.session.sshCredentials.passphrase && { passphrase: req.session.sshCredentials.passphrase }),
55+
...(req.session.sshCredentials.term && { sshterm: req.session.sshCredentials.term })
56+
}
57+
debug('Including SSH credentials from basic auth session: %O', {
58+
host: tempConfig.ssh.host,
59+
port: tempConfig.ssh.port,
60+
username: tempConfig.ssh.username,
61+
hasPassword: !!tempConfig.ssh.password,
62+
hasPrivateKey: !!tempConfig.ssh.privateKey,
63+
term: tempConfig.ssh.sshterm
64+
})
65+
}
66+
4667
const filePath = path.join(clientPath, DEFAULTS.CLIENT_FILE)
4768
await handleFileRead(filePath, tempConfig, res)
4869
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"socket.io": "^4.8.1",
4343
"ssh2": "1.17",
4444
"validator": "^13.15.15",
45-
"webssh2_client": "^2.0.0-alpha.4"
45+
"webssh2_client": "^2.0.0-alpha.6"
4646
},
4747
"scripts": {
4848
"start": "node index.js",

0 commit comments

Comments
 (0)