a
This commit is contained in:
@@ -4,9 +4,6 @@ module.exports = (contactController) => {
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const rateLimit = require('express-rate-limit');
|
const rateLimit = require('express-rate-limit');
|
||||||
const { body, validationResult } = require('express-validator');
|
const { body, validationResult } = require('express-validator');
|
||||||
// Remove the old require statement since we are getting the controller as an argument
|
|
||||||
// const contactController = require('../controllers/contactController');
|
|
||||||
const { formSecurityCheck } = require('../middleware/securityMw');
|
|
||||||
|
|
||||||
// 🛡️ Configure rate limiting to prevent DDoS and spamming
|
// 🛡️ Configure rate limiting to prevent DDoS and spamming
|
||||||
const apiLimiter = rateLimit({
|
const apiLimiter = rateLimit({
|
||||||
@@ -18,7 +15,14 @@ module.exports = (contactController) => {
|
|||||||
// Define the route for form submissions
|
// Define the route for form submissions
|
||||||
router.post('/submit-form',
|
router.post('/submit-form',
|
||||||
apiLimiter,
|
apiLimiter,
|
||||||
|
// In-line honeypot check
|
||||||
|
(req, res, next) => {
|
||||||
|
if (req.body.url) {
|
||||||
|
console.warn('Bot detected! Honeypot field was filled.');
|
||||||
|
return res.status(200).json({ success: true, message: 'Thank you for your submission.' });
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
},
|
||||||
[
|
[
|
||||||
// express-validator: sanitation and validation
|
// express-validator: sanitation and validation
|
||||||
body('firstName').trim().escape(),
|
body('firstName').trim().escape(),
|
||||||
@@ -37,8 +41,6 @@ module.exports = (contactController) => {
|
|||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
// The security middleware
|
|
||||||
// formSecurityCheck,
|
|
||||||
// The controller, which is the final step
|
// The controller, which is the final step
|
||||||
contactController.submitForm
|
contactController.submitForm
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user