Skip to content

Commit 1ef643b

Browse files
committed
Expose less detailed errors for changing primary email to avoid it being too easy to enumate emails
1 parent 0d00427 commit 1ef643b

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/commands/members/change-primary-email.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,26 @@ const process: Command<ChangeMemberPrimaryEmail>['process'] = input => {
2424
if (state === undefined) {
2525
return TE.left(
2626
failureWithStatus(
27-
'The requested member does not exist',
27+
'Invalid request',
2828
StatusCodes.NOT_FOUND
2929
)()
3030
);
3131
}
3232

3333
const emailAddress = normaliseEmailAddress(input.command.email);
3434
const email = state.emails[emailAddress];
35-
if (!email) {
35+
if (
36+
!email ||
37+
!email.verified
38+
) {
3639
return TE.left(
3740
failureWithStatus(
38-
'The requested email address is not attached to this member',
39-
StatusCodes.BAD_REQUEST
40-
)()
41-
);
42-
}
43-
if (!email.verified) {
44-
return TE.left(
45-
failureWithStatus(
46-
'The requested email address must be verified before it can be made primary',
41+
'Invalid request',
4742
StatusCodes.BAD_REQUEST
4843
)()
4944
);
5045
}
46+
5147
if (state.primaryEmailAddress === emailAddress) {
5248
return TE.right(O.none);
5349
}

tests/commands/members/email-management.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('member email commands', () => {
135135

136136
expect(result).toMatchObject({
137137
message:
138-
'The requested email address must be verified before it can be made primary',
138+
'Invalid request',
139139
status: StatusCodes.BAD_REQUEST,
140140
});
141141
});

0 commit comments

Comments
 (0)