Skip to content

Commit d873fe7

Browse files
geroplroboquat
authored andcommitted
[server] Guard prebuild-related APIs with GuardedPrebuild resource
1 parent 59bb214 commit d873fe7

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,15 +2234,26 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
22342234
this.checkAndBlockUser("getPrebuild");
22352235

22362236
const pbws = await this.workspaceDb.trace(ctx).findPrebuiltWorkspaceById(prebuildId);
2237-
const info = (await this.workspaceDb.trace(ctx).findPrebuildInfos([prebuildId]))[0];
2237+
if (!pbws) {
2238+
return undefined;
2239+
}
2240+
const [info, workspace] = await Promise.all([
2241+
this.workspaceDb
2242+
.trace(ctx)
2243+
.findPrebuildInfos([prebuildId])
2244+
.then((infos) => (infos.length > 0 ? infos[0] : undefined)),
2245+
this.workspaceDb.trace(ctx).findById(pbws.buildWorkspaceId),
2246+
]);
2247+
if (!info || !workspace) {
2248+
return undefined;
2249+
}
22382250

2239-
if (info && pbws) {
2240-
const result: PrebuildWithStatus = { info, status: pbws.state };
2241-
if (pbws.error) {
2242-
result.error = pbws.error;
2243-
}
2244-
return result;
2251+
await this.guardAccess({ kind: "prebuild", subject: pbws, workspace, teamMembers: undefined }, "get");
2252+
const result: PrebuildWithStatus = { info, status: pbws.state };
2253+
if (pbws.error) {
2254+
result.error = pbws.error;
22452255
}
2256+
return result;
22462257
}
22472258

22482259
public async findPrebuildByWorkspaceID(
@@ -2251,7 +2262,17 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
22512262
): Promise<PrebuiltWorkspace | undefined> {
22522263
traceAPIParams(ctx, { workspaceId });
22532264
this.checkAndBlockUser("findPrebuildByWorkspaceID");
2254-
return this.workspaceDb.trace(ctx).findPrebuildByWorkspaceID(workspaceId);
2265+
2266+
const [pbws, workspace] = await Promise.all([
2267+
this.workspaceDb.trace(ctx).findPrebuildByWorkspaceID(workspaceId),
2268+
this.workspaceDb.trace(ctx).findById(workspaceId),
2269+
]);
2270+
if (!pbws || !workspace) {
2271+
return undefined;
2272+
}
2273+
2274+
await this.guardAccess({ kind: "prebuild", subject: pbws, workspace, teamMembers: undefined }, "get");
2275+
return pbws;
22552276
}
22562277

22572278
public async getProjectOverview(ctx: TraceContext, projectId: string): Promise<Project.Overview | undefined> {

0 commit comments

Comments
 (0)