Skip to content

Commit 5ee9609

Browse files
committed
Patched Team Join Impersonation bug
1 parent 586e430 commit 5ee9609

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/backend/db.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,21 @@ async function SendTeamRequest(sender, team_name) {
890890
// in the database or if it is a new join-request
891891
const teamRecord = await TeamCollection.findOne({ name: team_name });
892892
if (teamRecord) {
893+
// check if the sender is already inclueded in the team profile based on team_name
894+
const userRecord = await UserCollection.findOne({ username: sender });
895+
if (userRecord) {
896+
if (userRecord.team_id === teamRecord._id.toString()) {
897+
return {
898+
"message": "Could not send request, try again!"
899+
};
900+
}
901+
} else {
902+
// user not found
903+
return {
904+
"message": "Could not send request, try again!"
905+
};
906+
}
907+
893908
// if the team already has 3 members we need to drop
894909
// this join-request due to the team being full
895910
if (teamRecord.members.length === 3) {
@@ -909,7 +924,6 @@ async function SendTeamRequest(sender, team_name) {
909924
if (requestObject === null) {
910925
// pull the users _id from the sender variable so if they
911926
// change their username we maintain data-connection
912-
const userRecord = await UserCollection.findOne({ username: sender });
913927
if (userRecord) {
914928
/*
915929
sender_id: String, // '_id'

src/backend/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ app.post('/team/request', async (req, res) => {
366366
const validJWT = await DecodeJWT(res, token);
367367

368368
if (validJWT) {
369-
const teamRequest = await SendTeamRequest(data.sender, data.team_name);
369+
const teamRequest = await SendTeamRequest(validJWT.username, data.team_name);
370370
return res.json(teamRequest);
371371
} else {
372372
return res.json(null);

src/pages/team.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ const Team = () => {
8888
"Content-Type": "application/json"
8989
},
9090
body: JSON.stringify({
91-
"sender": profileData.username,
9291
"team_name": reqTeamName
9392
}),
9493
credentials: 'include' // ensures cookies are sent

0 commit comments

Comments
 (0)