Skip to content

Commit

Permalink
Disregard whitespace in whitelist check
Browse files Browse the repository at this point in the history
Disregard leading and trailing whitespace in both input email and
whitelisted domains to make the check more robust against
unintentionally added whitespace.
  • Loading branch information
simenheg committed Oct 11, 2023
1 parent 39fc690 commit 710bf7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class DomainWhitelistCollection {
this.collection = firestore.collection('domainWhitelist');
}

getDocumentById(id) {
return this.collection.doc(id).get();
listDocuments() {
return this.collection.listDocuments();
}
}

Expand Down
8 changes: 3 additions & 5 deletions functions/backend/utils/handleAccessRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ export const createAccessRequest = async (db, accessRequest) => {
return { code: 400, message: 'toaster.request.noEmail' };
}

const emailDomain = email.split('@')[1];
const emailDomain = email.split('@')[1].trim();
const domainWhitelistCollection = new DomainWhitelistCollection(db);
const usersCollection = new UsersCollection(db);

const domainWhitelistSnapshot = await domainWhitelistCollection.getDocumentById(
emailDomain
);
const whitelist = await domainWhitelistCollection.listDocuments();

if (domainWhitelistSnapshot.exists) {
if (whitelist.some((x) => x.id.trim() === emailDomain)) {
try {
await usersCollection.addDocument({ id: email, email });

Expand Down

0 comments on commit 710bf7d

Please sign in to comment.