Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/gitpod-protocol/src/util/gitpod-host-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const baseWorkspaceIDRegex =
"(([a-f][0-9a-f]{7}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|([0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}))";

// this pattern matches v4 UUIDs as well as the new generated workspace ids (e.g. pink-panda-ns35kd21)
export const workspaceIDRegex = RegExp(`^(?:debug-)?${baseWorkspaceIDRegex}$`);
const workspaceIDRegex = RegExp(`^(?:debug-)?${baseWorkspaceIDRegex}$`);

// this pattern matches URL prefixes of workspaces
const workspaceUrlPrefixRegex = RegExp(`^(([0-9]{4,6}|debug)-)?${baseWorkspaceIDRegex}\\.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ export class ParseWorkspaceIdTest {
const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-15599b3");
expect(actual).to.be.false;
}
@test public matchesWorkspaceIdExactly_new_negative_empty() {
const actual = matchesNewWorkspaceIdExactly(undefined);
expect(actual).to.be.false;
}
}
module.exports = new ParseWorkspaceIdTest();
8 changes: 6 additions & 2 deletions components/gitpod-protocol/src/util/parse-workspace-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const parseWorkspaceIdFromHostname = function (hostname: string) {
}
};

/** Equalls UUIDv4 (and REGEX_WORKSPACE_ID_LEGACY!) */
/** Equals UUIDv4 (and REGEX_WORKSPACE_ID_LEGACY!) */
const REGEX_INSTANCE_ID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
const REGEX_INSTANCE_ID_EXACT = new RegExp(`^${REGEX_INSTANCE_ID.source}$`);

Expand All @@ -49,6 +49,10 @@ export const matchesInstanceIdOrLegacyWorkspaceIdExactly = function (maybeId: st
* @param maybeWorkspaceId
* @returns
*/
export const matchesNewWorkspaceIdExactly = function (maybeWorkspaceId: string): boolean {
export const matchesNewWorkspaceIdExactly = function (maybeWorkspaceId?: string): boolean {
if (!maybeWorkspaceId) {
return false;
}

return REGEX_WORKSPACE_ID_EXACT.test(maybeWorkspaceId);
};
10 changes: 1 addition & 9 deletions components/server/src/api/workspace-service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messag
import { ContextService } from "../workspace/context-service";
import { UserService } from "../user/user-service";
import { ContextParser } from "../workspace/context-parser-service";
import { workspaceIDRegex } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url";

const isWorkspaceId = (workspaceId?: string) => {
if (!workspaceId) {
return false;
}

return workspaceIDRegex.test(workspaceId);
};
import { matchesNewWorkspaceIdExactly as isWorkspaceId } from "@gitpod/gitpod-protocol/lib/util/parse-workspace-id";

@injectable()
export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceInterface> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class SpiceDBAuthorizer {
const permitted = response.permissionship === v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION;
return { permitted, checkedAt: response.checkedAt?.token };
} catch (err) {
// we should not consider users supplying invalid requests as internal server errors
if (isGrpcError(err) && err.code === grpc.status.INVALID_ARGUMENT) {
throw new ApplicationError(ErrorCodes.BAD_REQUEST, `Invalid request for permission check: ${err}`);
}
Expand Down
Loading