mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add reset_url allow list for password reset request
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user