Skip to content

Commit

Permalink
Only allow decimal values in timeouts
Browse files Browse the repository at this point in the history
This allowed users to have durations in other number systems like hexadecimal. For example `0xfd` was a valid timeout.
  • Loading branch information
filiptronicek committed Feb 8, 2023
1 parent 5217ce9 commit b9891f2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,12 @@ const WORKSPACE_MAXIMUM_TIMEOUT_HOURS = 24;
export type WorkspaceTimeoutDuration = string;
export namespace WorkspaceTimeoutDuration {
export function validate(duration: string): WorkspaceTimeoutDuration {
duration = duration.toLowerCase();
const unit = duration.slice(-1);
if (!["m", "h", "d"].includes(unit)) {
throw new Error(`Invalid timeout unit: ${unit}`);
}
const value = parseInt(duration.slice(0, -1));
const value = parseInt(duration.slice(0, -1), 10);
if (isNaN(value) || value <= 0) {
throw new Error(`Invalid timeout value: ${duration}`);
}
Expand Down

0 comments on commit b9891f2

Please sign in to comment.