Add reset_url allow list for password reset request

This commit is contained in:
rijkvanzanten
2021-03-08 13:48:59 -05:00
parent a12b148b17
commit e8222d2a28
3 changed files with 21 additions and 12 deletions

View File

@@ -166,11 +166,13 @@ router.post(
try {
await service.requestPasswordReset(req.body.email, req.body.reset_url || null);
} catch {
// We don't want to give away what email addresses exist, so we'll always return a 200
// from this endpoint
} finally {
return next();
} catch (err) {
if (err instanceof InvalidPayloadException) {
throw err;
} else {
return next();
}
}
}),
respond

View File

@@ -123,6 +123,12 @@ export class UsersService extends ItemsService {
const payload = { email, scope: 'password-reset' };
const token = jwt.sign(payload, env.SECRET as string, { expiresIn: '1d' });
const urlWhitelist = toArray(env.PASSWORD_RESET_URL_ALLOW_LIST);
if (url && urlWhitelist.includes(url) === false) {
throw new InvalidPayloadException(`Url "${url}" can't be used to reset passwords.`);
}
const acceptURL = url ? `${url}?token=${token}` : `${env.PUBLIC_URL}/admin/reset-password?token=${token}`;
await sendPasswordResetMail(email, acceptURL);