From 8f5e782583b928c0273229622799c5daa55c7854 Mon Sep 17 00:00:00 2001 From: SuperComboGamer Date: Sat, 20 Dec 2025 23:20:31 -0500 Subject: [PATCH] refactor: update token generation method and improve maxSessions validation - Changed the token generation method to use slice instead of substr for better readability. - Enhanced maxSessions validation in the settings update handler to check for undefined values and ensure the input is a number before processing. --- apps/server/src/routes/terminal/common.ts | 2 +- apps/server/src/routes/terminal/routes/settings.ts | 10 +++++++++- apps/server/src/services/terminal-service.ts | 2 +- apps/ui/src/components/views/terminal-view.tsx | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/server/src/routes/terminal/common.ts b/apps/server/src/routes/terminal/common.ts index 80b3a496..85039c39 100644 --- a/apps/server/src/routes/terminal/common.ts +++ b/apps/server/src/routes/terminal/common.ts @@ -54,7 +54,7 @@ export function getTokenData( export function generateToken(): string { return `term-${Date.now()}-${Math.random() .toString(36) - .substr(2, 15)}${Math.random().toString(36).substr(2, 15)}`; + .slice(2, 17)}${Math.random().toString(36).slice(2, 17)}`; } /** diff --git a/apps/server/src/routes/terminal/routes/settings.ts b/apps/server/src/routes/terminal/routes/settings.ts index 21151ee6..08e670ae 100644 --- a/apps/server/src/routes/terminal/routes/settings.ts +++ b/apps/server/src/routes/terminal/routes/settings.ts @@ -25,7 +25,15 @@ export function createSettingsUpdateHandler() { const terminalService = getTerminalService(); const { maxSessions } = req.body; - if (typeof maxSessions === "number") { + // Validate maxSessions if provided + if (maxSessions !== undefined) { + if (typeof maxSessions !== "number") { + res.status(400).json({ + success: false, + error: "maxSessions must be a number", + }); + return; + } if (!Number.isInteger(maxSessions)) { res.status(400).json({ success: false, diff --git a/apps/server/src/services/terminal-service.ts b/apps/server/src/services/terminal-service.ts index b569ec28..c11af057 100644 --- a/apps/server/src/services/terminal-service.ts +++ b/apps/server/src/services/terminal-service.ts @@ -233,7 +233,7 @@ export class TerminalService extends EventEmitter { return null; } - const id = `term-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; + const id = `term-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`; const { shell: detectedShell, args: shellArgs } = this.detectShell(); const shell = options.shell || detectedShell; diff --git a/apps/ui/src/components/views/terminal-view.tsx b/apps/ui/src/components/views/terminal-view.tsx index 3559d6b7..5f2b1a42 100644 --- a/apps/ui/src/components/views/terminal-view.tsx +++ b/apps/ui/src/components/views/terminal-view.tsx @@ -579,7 +579,7 @@ export function TerminalView() { return { type: "split", - id: persisted.id || `split-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, + id: persisted.id || `split-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`, direction: persisted.direction, panels: childPanels, size: persisted.size,