fix: Add corrected refernce to securityMw.js for honeypot and hCaptcha verification

This commit is contained in:
2025-08-21 07:51:58 -05:00
parent b1093f3cfc
commit 0dea7fcaec

View File

@@ -1,5 +1,5 @@
// The entire module is now a function that accepts 'contactController' as an argument. // The entire module is now a function that accepts 'contactController' and security middleware as an argument.
module.exports = (contactController) => { module.exports = (contactController, securityMw) => {
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const rateLimit = require('express-rate-limit'); const rateLimit = require('express-rate-limit');
@@ -12,17 +12,12 @@ module.exports = (contactController) => {
message: "Too many requests from this IP, please try again after 15 minutes." message: "Too many requests from this IP, please try again after 15 minutes."
}); });
// Define the route for form submissions // Define the route for form submissions with all middleware
router.post('/submit-form', router.post('/submit-form',
apiLimiter, apiLimiter,
// In-line honeypot check // The security middleware is now a separate step,
(req, res, next) => { // containing both the honeypot check and hCaptcha verification.
if (req.body.url) { securityMw.formSecurityCheck,
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(),
@@ -47,4 +42,4 @@ module.exports = (contactController) => {
// Return the configured router // Return the configured router
return router; return router;
}; };