Skip to content

Commit d02e165

Browse files
Minor improvements to the workspace timeout validation
1. Only allow decimal values in timeouts This allowed users to have durations in other number systems like hexadecimal. For example `0xfd` was a valid timeout. 2. Remove "d" (day) as a unit Because this unit is both rejected by the backend and timeouts cannot be longer than 24 hours, it does not make sense to allow it. Co-authored-by: Lou Bichard <[email protected]>
1 parent c650217 commit d02e165

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,19 +363,20 @@ const WORKSPACE_MAXIMUM_TIMEOUT_HOURS = 24;
363363
export type WorkspaceTimeoutDuration = string;
364364
export namespace WorkspaceTimeoutDuration {
365365
export function validate(duration: string): WorkspaceTimeoutDuration {
366+
duration = duration.toLowerCase();
366367
const unit = duration.slice(-1);
367-
if (!["m", "h", "d"].includes(unit)) {
368+
if (!["m", "h"].includes(unit)) {
368369
throw new Error(`Invalid timeout unit: ${unit}`);
369370
}
370-
const value = parseInt(duration.slice(0, -1));
371+
const value = parseInt(duration.slice(0, -1), 10);
371372
if (isNaN(value) || value <= 0) {
372373
throw new Error(`Invalid timeout value: ${duration}`);
373374
}
374375
if (
375376
(unit === "h" && value > WORKSPACE_MAXIMUM_TIMEOUT_HOURS) ||
376377
(unit === "m" && value > WORKSPACE_MAXIMUM_TIMEOUT_HOURS * 60)
377378
) {
378-
throw new Error(`Timeouts cannot extend to more than a day`);
379+
throw new Error("Workspace inactivity timeout cannot exceed 24h");
379380
}
380381
return duration;
381382
}

0 commit comments

Comments
 (0)