fix: Add corrected refernce to securityMw.js for honeypot and hCaptcha verification
This commit is contained in:
@@ -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(),
|
||||||
|
Reference in New Issue
Block a user