-
-
Save cb-v4s/042652c591ce8fc75a8b3894f0af8ab3 to your computer and use it in GitHub Desktop.
express webserver rate limiting and more security measures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const limitter = require('express-rate-limit') | |
| const helmet = require('helmet') | |
| ... | |
| // middlewares | |
| app.use( | |
| limitter({ | |
| windowMs: 5000, | |
| max: 5, | |
| message: { | |
| code: 429, /* Too Many Requests */ | |
| message: "You've made too many requests recently. Please wait and try your request again later." | |
| } | |
| }) | |
| ) | |
| app.use(express.csrf()); // csrf protection | |
| app.use(helmet.xframe()) | |
| app.use(helmet.iexss()) | |
| app.use(helmet.contentTypeOptions()) | |
| app.use(helmet.cacheControl()) | |
| app.use((req, res, next) => { | |
| delete req.headers['x-powered-by']; | |
| next(); | |
| }); | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment