Skip to content

Commit

Permalink
[server] Validate userID, teamID is a UUID on team operations
Browse files Browse the repository at this point in the history
  • Loading branch information
easyCZ authored and roboquat committed Jan 10, 2023
1 parent 169fbed commit 0789eda
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {

public async getTeam(ctx: TraceContext, teamId: string): Promise<Team> {
traceAPIParams(ctx, { teamId });

if (!uuidValidate(teamId)) {
throw new ResponseError(ErrorCodes.BAD_REQUEST, "team ID must be a valid UUID");
}

this.checkAndBlockUser("getTeam");

const team = await this.teamDB.findTeamById(teamId);
Expand All @@ -2059,6 +2064,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
public async getTeamMembers(ctx: TraceContext, teamId: string): Promise<TeamMemberInfo[]> {
traceAPIParams(ctx, { teamId });

if (!uuidValidate(teamId)) {
throw new ResponseError(ErrorCodes.BAD_REQUEST, "team ID must be a valid UUID");
}

this.checkUser("getTeamMembers");
const team = await this.getTeam(ctx, teamId);
const members = await this.teamDB.findMembersByTeam(team.id);
Expand Down Expand Up @@ -2145,6 +2154,14 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
public async removeTeamMember(ctx: TraceContext, teamId: string, userId: string): Promise<void> {
traceAPIParams(ctx, { teamId, userId });

if (!uuidValidate(teamId)) {
throw new ResponseError(ErrorCodes.BAD_REQUEST, "team ID must be a valid UUID");
}

if (!uuidValidate(userId)) {
throw new ResponseError(ErrorCodes.BAD_REQUEST, "user ID must be a valid UUID");
}

const user = this.checkAndBlockUser("removeTeamMember");
// Users are free to leave any team themselves, but only owners can remove others from their teams.
await this.guardTeamOperation(teamId, user.id === userId ? "get" : "update");
Expand All @@ -2167,6 +2184,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
public async getGenericInvite(ctx: TraceContext, teamId: string): Promise<TeamMembershipInvite> {
traceAPIParams(ctx, { teamId });

if (!uuidValidate(teamId)) {
throw new ResponseError(ErrorCodes.BAD_REQUEST, "team ID must be a valid UUID");
}

this.checkUser("getGenericInvite");
await this.guardTeamOperation(teamId, "get");
const invite = await this.teamDB.findGenericInviteByTeamId(teamId);
Expand All @@ -2179,6 +2200,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
public async resetGenericInvite(ctx: TraceContext, teamId: string): Promise<TeamMembershipInvite> {
traceAPIParams(ctx, { teamId });

if (!uuidValidate(teamId)) {
throw new ResponseError(ErrorCodes.BAD_REQUEST, "team ID must be a valid UUID");
}

this.checkAndBlockUser("resetGenericInvite");
await this.guardTeamOperation(teamId, "update");
return this.teamDB.resetGenericInvite(teamId);
Expand Down

0 comments on commit 0789eda

Please sign in to comment.