Skip to content

Commit 04e34fd

Browse files
Correctly get the session cookie for web terminal (hestiacp#3969)
* Correctly get the session cookie * Fix format --------- Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent cd5935f commit 04e34fd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/deb/web-terminal/server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { readFileSync } from 'node:fs';
55
import { spawn } from 'node-pty';
66
import { WebSocketServer } from 'ws';
77

8+
const sessionName = 'HESTIASID';
89
const hostname = execSync('hostname', { silent: true }).toString().trim();
910
const systemIPs = JSON.parse(
1011
execSync(`${process.env.HESTIA}/bin/v-list-sys-ips json`, { silent: true }).toString(),
@@ -16,7 +17,7 @@ const { config } = JSON.parse(
1617
const wss = new WebSocketServer({
1718
port: parseInt(config.WEB_TERMINAL_PORT, 10),
1819
verifyClient: async (info, cb) => {
19-
if (!info.req.headers.cookie.includes('PHPSESSID')) {
20+
if (!info.req.headers.cookie.includes(sessionName)) {
2021
cb(false, 401, 'Unauthorized');
2122
return;
2223
}
@@ -47,7 +48,7 @@ wss.on('connection', (ws, req) => {
4748
const remoteIP = req.headers['x-real-ip'] || req.socket.remoteAddress;
4849

4950
// Check if session is valid
50-
const sessionID = req.headers.cookie.split('=')[1];
51+
const sessionID = req.headers.cookie.split(`${sessionName}=`)[1].split(';')[0];
5152
console.log(`New connection from ${remoteIP} (${sessionID})`);
5253

5354
const file = readFileSync(`${process.env.HESTIA}/data/sessions/sess_${sessionID}`);

0 commit comments

Comments
 (0)