Skip to content

Commit b29e06a

Browse files
[server] Fix workspace service's workspace ID validation (#20468)
1 parent b5bdd24 commit b29e06a

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

components/gitpod-protocol/src/util/parse-workspace-id.spec.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import * as chai from "chai";
88
import { suite, test } from "@testdeck/mocha";
99
import {
10+
isWorkspaceId,
1011
matchesInstanceIdOrLegacyWorkspaceIdExactly,
1112
matchesNewWorkspaceIdExactly,
1213
parseWorkspaceIdFromHostname,
@@ -81,8 +82,17 @@ export class ParseWorkspaceIdTest {
8182
const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-15599b3");
8283
expect(actual).to.be.false;
8384
}
84-
@test public matchesWorkspaceIdExactly_new_negative_empty() {
85-
const actual = matchesNewWorkspaceIdExactly(undefined);
85+
86+
@test public isWorkspaceId_positive_new() {
87+
const actual = isWorkspaceId("moccasin-ferret-155799b3");
88+
expect(actual).to.be.true;
89+
}
90+
@test public isWorkspaceId_positive_legacy() {
91+
const actual = isWorkspaceId("b7e0eaf8-ec73-44ec-81ea-04859263b656");
92+
expect(actual).to.be.true;
93+
}
94+
@test public isWorkspaceId_negative_empty() {
95+
const actual = isWorkspaceId(undefined);
8696
expect(actual).to.be.false;
8797
}
8898
}

components/gitpod-protocol/src/util/parse-workspace-id.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ export const matchesInstanceIdOrLegacyWorkspaceIdExactly = function (maybeId: st
4949
* @param maybeWorkspaceId
5050
* @returns
5151
*/
52-
export const matchesNewWorkspaceIdExactly = function (maybeWorkspaceId?: string): boolean {
52+
export const matchesNewWorkspaceIdExactly = function (maybeWorkspaceId: string): boolean {
53+
return REGEX_WORKSPACE_ID_EXACT.test(maybeWorkspaceId);
54+
};
55+
56+
/**
57+
* Matches both new and legacy workspace ids
58+
*/
59+
export const isWorkspaceId = function (maybeWorkspaceId?: string): boolean {
5360
if (!maybeWorkspaceId) {
5461
return false;
5562
}
5663

57-
return REGEX_WORKSPACE_ID_EXACT.test(maybeWorkspaceId);
64+
return matchesNewWorkspaceIdExactly(maybeWorkspaceId) || REGEX_WORKSPACE_ID_LEGACY_EXACT.test(maybeWorkspaceId);
5865
};

components/server/src/api/workspace-service-api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messag
5959
import { ContextService } from "../workspace/context-service";
6060
import { UserService } from "../user/user-service";
6161
import { ContextParser } from "../workspace/context-parser-service";
62-
import { matchesNewWorkspaceIdExactly as isWorkspaceId } from "@gitpod/gitpod-protocol/lib/util/parse-workspace-id";
62+
import { isWorkspaceId } from "@gitpod/gitpod-protocol/lib/util/parse-workspace-id";
6363
import { SYSTEM_USER, SYSTEM_USER_ID } from "../authorization/authorizer";
6464

6565
@injectable()

0 commit comments

Comments
 (0)