1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/middleware/handle-invalid-paths.js
2022-05-24 18:30:05 +00:00

14 lines
437 B
JavaScript

import statsd from '../lib/statsd.js'
const STATSD_KEY = 'middleware.handle_invalid_paths'
export default function handleInvalidPaths(req, res, next) {
// Prevent various malicious injection attacks targeting Next.js
if (req.path.match(/^\/_next[^/]/) || req.path === '/_next/data' || req.path === '/_next/data/') {
statsd.increment(STATSD_KEY, 1, ['check:nextjs-injection-attack'])
return next(404)
}
return next()
}