Skip to content

Commit

Permalink
Merge pull request #9179 from weseek/fix/154291-fix-password-api
Browse files Browse the repository at this point in the history
fix: Forgot password API - reject requests with invalid email format
  • Loading branch information
mergify[bot] authored Oct 3, 2024
2 parents c092fa2 + 6a3ce0d commit 8bbf17d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/app/src/server/middlewares/apiv3-form-validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ErrorV3 } from '@growi/core/dist/models';
import { NextFunction, Request, Response } from 'express';
import type { NextFunction, Request, Response } from 'express';

import loggerFactory from '~/utils/logger';

Expand Down
10 changes: 9 additions & 1 deletion apps/app/src/server/routes/apiv3/forgot-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ module.exports = (crowi) => {
return (value === req.body.newPassword);
}),
],
email: [
body('email')
.isEmail()
.escape()
.withMessage('message.Email format is invalid')
.notEmpty()
.withMessage('message.Email field is required'),
],
};

const checkPassportStrategyMiddleware = checkForgotPasswordEnabledMiddlewareFactory(crowi, true);
Expand All @@ -61,7 +69,7 @@ module.exports = (crowi) => {
});
}

router.post('/', checkPassportStrategyMiddleware, addActivity, async(req, res) => {
router.post('/', checkPassportStrategyMiddleware, validator.email, apiV3FormValidator, addActivity, async(req, res) => {
const { email } = req.body;
const locale = configManager.getConfig('crowi', 'app:globalLang');
const appUrl = appService.getSiteUrl();
Expand Down
4 changes: 2 additions & 2 deletions apps/app/src/server/routes/forgot-password.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
import type {
NextFunction, Request, Response,
} from 'express';
import createError from 'http-errors';

import { forgotPasswordErrorCode } from '~/interfaces/errors/forgot-password';
import loggerFactory from '~/utils/logger';

import { IPasswordResetOrder } from '../models/password-reset-order';
import type { IPasswordResetOrder } from '../models/password-reset-order';

const logger = loggerFactory('growi:routes:forgot-password');

Expand Down

0 comments on commit 8bbf17d

Please sign in to comment.