Skip to content

Commit b63f285

Browse files
Merge pull request #1193 from DEVTomatoCake/fix/forgot-password-security
2 parents 4f19ee1 + 98c1b93 commit b63f285

File tree

1 file changed

+13
-53
lines changed

1 file changed

+13
-53
lines changed

src/api/routes/auth/forgot.ts

+13-53
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
/*
22
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
33
Copyright (C) 2023 Spacebar and Spacebar Contributors
4-
4+
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU Affero General Public License as published
77
by the Free Software Foundation, either version 3 of the License, or
88
(at your option) any later version.
9-
9+
1010
This program is distributed in the hope that it will be useful,
1111
but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
GNU Affero General Public License for more details.
14-
14+
1515
You should have received a copy of the GNU Affero General Public License
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

1919
import { getIpAdress, route, verifyCaptcha } from "@spacebar/api";
20-
import {
21-
Config,
22-
Email,
23-
FieldErrors,
24-
ForgotPasswordSchema,
25-
User,
26-
} from "@spacebar/util";
20+
import { Config, Email, ForgotPasswordSchema, User } from "@spacebar/util";
2721
import { Request, Response, Router } from "express";
28-
import { HTTPError } from "lambert-server";
2922
const router = Router();
3023

3124
router.post(
@@ -37,9 +30,6 @@ router.post(
3730
400: {
3831
body: "APIErrorOrCaptchaResponse",
3932
},
40-
500: {
41-
body: "APIErrorResponse",
42-
},
4333
},
4434
}),
4535
async (req: Request, res: Response) => {
@@ -71,50 +61,20 @@ router.post(
7161
}
7262
}
7363

74-
const user = await User.findOneOrFail({
75-
where: [{ phone: login }, { email: login }],
76-
select: ["username", "id", "disabled", "deleted", "email"],
77-
relations: ["security_keys"],
78-
}).catch(() => {
79-
throw FieldErrors({
80-
login: {
81-
message: req.t("auth:password_reset.EMAIL_DOES_NOT_EXIST"),
82-
code: "EMAIL_DOES_NOT_EXIST",
83-
},
84-
});
85-
});
64+
res.sendStatus(204);
8665

87-
if (!user.email)
88-
throw FieldErrors({
89-
login: {
90-
message:
91-
"This account does not have an email address associated with it.",
92-
code: "NO_EMAIL",
93-
},
94-
});
95-
96-
if (user.deleted)
97-
return res.status(400).json({
98-
message: "This account is scheduled for deletion.",
99-
code: 20011,
100-
});
101-
102-
if (user.disabled)
103-
return res.status(400).json({
104-
message: req.t("auth:login.ACCOUNT_DISABLED"),
105-
code: 20013,
106-
});
66+
const user = await User.findOne({
67+
where: [{ phone: login }, { email: login }],
68+
select: ["username", "id", "email"],
69+
}).catch(() => {});
10770

108-
return await Email.sendResetPassword(user, user.email)
109-
.then(() => {
110-
return res.sendStatus(204);
111-
})
112-
.catch((e) => {
71+
if (user && user.email) {
72+
Email.sendResetPassword(user, user.email).catch((e) => {
11373
console.error(
114-
`Failed to send password reset email to ${user.username}#${user.discriminator}: ${e}`,
74+
`Failed to send password reset email to ${user.username}#${user.discriminator} (${user.id}): ${e}`,
11575
);
116-
throw new HTTPError("Failed to send password reset email", 500);
11776
});
77+
}
11878
},
11979
);
12080

0 commit comments

Comments
 (0)