Skip to content

Commit 558f29b

Browse files
committed
[dashboard] Disallow team names that might conflict with dashboard URLs
1 parent e68e76d commit 558f29b

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

components/dashboard/src/teams/NewTeam.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function () {
3838
<h3 className="text-center text-xl mb-6">What's your team's name?</h3>
3939
<h4>Team Name</h4>
4040
<input className={`w-full${!!creationError ? ' error' : ''}`} type="text" onChange={event => name = event.target.value} />
41-
{!!creationError && <p className="text-gitpod-red">{creationError.message}</p>}
41+
{!!creationError && <p className="text-gitpod-red">{creationError.message.replace(/Request \w+ failed with message: /, '')}</p>}
4242
</div>
4343
<div className="flex flex-row-reverse space-x-2 space-x-reverse mt-2">
4444
<button type="submit">Create Team</button>

components/gitpod-db/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@jmondi/oauth2-server": "^1.1.0",
2626
"mysql": "^2.15.0",
2727
"reflect-metadata": "^0.1.10",
28+
"the-big-username-blacklist": "^1.5.2",
2829
"typeorm": "0.1.20",
2930
"uuid": "^3.1.0"
3031
},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
// Source: https://github.com/marteinn/The-Big-Username-Blacklist-JS/blob/master/src/index.js
8+
declare module 'the-big-username-blacklist' {
9+
export function validate (username: string): boolean;
10+
export var list: string[];
11+
}

components/gitpod-db/src/typeorm/team-db-impl.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See License-AGPL.txt in the project root for license information.
55
*/
66

7+
import { list as blocklist } from "the-big-username-blacklist";
78
import { Team, TeamMemberInfo, TeamMemberRole, TeamMembershipInvite, User } from "@gitpod/gitpod-protocol";
89
import { inject, injectable } from "inversify";
910
import { TypeORM } from "./typeorm";
@@ -15,6 +16,40 @@ import { DBTeamMembership } from "./entity/db-team-membership";
1516
import { DBUser } from "./entity/db-user";
1617
import { DBTeamMembershipInvite } from "./entity/db-team-membership-invite";
1718

19+
const FORBIDDEN_SLUGS = [
20+
'access-control',
21+
'account',
22+
'admin',
23+
'blocked',
24+
'branches',
25+
'from-referrer',
26+
'install-github-app',
27+
'integrations',
28+
'issues',
29+
'login',
30+
'merge-requests',
31+
'new',
32+
'notifications',
33+
'oauth-approval',
34+
'plans',
35+
'prebuilds',
36+
'preferences',
37+
'projects',
38+
'pull-requests',
39+
'settings',
40+
'setup',
41+
'snapshots',
42+
'sorry',
43+
'start',
44+
'subscription',
45+
'teams',
46+
'upgrade-subscription',
47+
'usage',
48+
'variables',
49+
'workspaces',
50+
...(blocklist),
51+
].sort((a, b) => b > a ? -1 : 1);
52+
1853
@injectable()
1954
export class TeamDBImpl implements TeamDB {
2055
@inject(TypeORM) typeORM: TypeORM;
@@ -79,6 +114,14 @@ export class TeamDBImpl implements TeamDB {
79114
throw new Error('Please choose a team name containing only letters, numbers, -, _, \', or spaces.');
80115
}
81116
const slug = name.toLocaleLowerCase().replace(/[ ']/g, '-');
117+
if (FORBIDDEN_SLUGS.indexOf(slug) !== -1) {
118+
throw new Error('Creating a team with this name is not allowed');
119+
}
120+
const userRepo = await this.getUserRepo();
121+
const existingUsers = await userRepo.query('SELECT COUNT(id) AS count FROM d_b_user WHERE fullName LIKE ? OR name LIKE ?', [ name, slug ]);
122+
if (existingUsers[0].count > 0) {
123+
throw new Error('A team cannot have the same name as an existing user');
124+
}
82125
const teamRepo = await this.getTeamRepo();
83126
const existingTeam = await teamRepo.findOne({ slug, deleted: false });
84127
if (!!existingTeam) {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20066,6 +20066,11 @@ [email protected], text-table@^0.2.0, text-table@~0.2.0:
2006620066
version "0.2.0"
2006720067
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
2006820068

20069+
the-big-username-blacklist@^1.5.2:
20070+
version "1.5.2"
20071+
resolved "https://registry.yarnpkg.com/the-big-username-blacklist/-/the-big-username-blacklist-1.5.2.tgz#0a4e88fe636e39552c9306b72e7722c99b6eece6"
20072+
integrity sha512-bKRIZbu3AoDhEkjNcErodWLpR18vZQQqg9DEab/zELgGw++M1x0KBeTGdoEPHPw0ghmx1jf/B6kZKuwDDPhGBQ==
20073+
2006920074
thenify-all@^1.0.0:
2007020075
version "1.6.0"
2007120076
resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726"

0 commit comments

Comments
 (0)