Просмотр исходного кода

Correctly get the session cookie for web terminal (#3969)

* Correctly get the session cookie

* Fix format

---------

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
Jakob Bouchard 2 лет назад
Родитель
Сommit
04e34fd29b
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      src/deb/web-terminal/server.js

+ 3 - 2
src/deb/web-terminal/server.js

@@ -5,6 +5,7 @@ import { readFileSync } from 'node:fs';
 import { spawn } from 'node-pty';
 import { WebSocketServer } from 'ws';
 
+const sessionName = 'HESTIASID';
 const hostname = execSync('hostname', { silent: true }).toString().trim();
 const systemIPs = JSON.parse(
 	execSync(`${process.env.HESTIA}/bin/v-list-sys-ips json`, { silent: true }).toString(),
@@ -16,7 +17,7 @@ const { config } = JSON.parse(
 const wss = new WebSocketServer({
 	port: parseInt(config.WEB_TERMINAL_PORT, 10),
 	verifyClient: async (info, cb) => {
-		if (!info.req.headers.cookie.includes('PHPSESSID')) {
+		if (!info.req.headers.cookie.includes(sessionName)) {
 			cb(false, 401, 'Unauthorized');
 			return;
 		}
@@ -47,7 +48,7 @@ wss.on('connection', (ws, req) => {
 	const remoteIP = req.headers['x-real-ip'] || req.socket.remoteAddress;
 
 	// Check if session is valid
-	const sessionID = req.headers.cookie.split('=')[1];
+	const sessionID = req.headers.cookie.split(`${sessionName}=`)[1].split(';')[0];
 	console.log(`New connection from ${remoteIP} (${sessionID})`);
 
 	const file = readFileSync(`${process.env.HESTIA}/data/sessions/sess_${sessionID}`);