Spaces:
Running
Running
Download middleware/botDetection.js from 4send/messenger: direct link, hf CLI and curl.
- Browser
- Download file 575 Bytes
-
https://huggingface.co/spaces/4send/messenger/resolve/3eed13eb90e615af90ff1b6efdcb9ee6eee182cd/middleware/botDetection.js
- Command line
-
hf download hf://spaces/4send/messenger@3eed13eb90e615af90ff1b6efdcb9ee6eee182cd/middleware/botDetection.js
-
curl -L -o botDetection.js https://huggingface.co/spaces/4send/messenger/resolve/3eed13eb90e615af90ff1b6efdcb9ee6eee182cd/middleware/botDetection.js
575 Bytes
| const botDetection = (req, res, next) => { | |
| const dangerousChars = /["';<>]/g; | |
| ['user-agent', 'referer', 'x-forwarded-for'].forEach(h => { | |
| if (req.headers[h] && dangerousChars.test(req.headers[h])) { | |
| req.headers[h] = req.headers[h].replace(dangerousChars, ""); | |
| } | |
| }); | |
| const ua = req.headers['user-agent']; | |
| if (!ua || ua.length < 10) return res.status(403).send('Bot detected'); | |
| if (req.headers['content-length'] > 30 * 1024 * 1024) return res.status(413).send('Too large'); | |
| next(); | |
| }; | |
| module.exports = { botDetection }; | |