Skip to content

Add middleware to protect against DoS#3620

Open
JR40159 wants to merge 1 commit into
mainfrom
innovation/dos-protection
Open

Add middleware to protect against DoS#3620
JR40159 wants to merge 1 commit into
mainfrom
innovation/dos-protection

Conversation

@JR40159

@JR40159 JR40159 commented May 22, 2026

Copy link
Copy Markdown
Member

@github-actions github-actions Bot added javascript Pull requests that update Javascript code backend Changes affecting server-side logic, APIs, data processing, or internal services. labels May 22, 2026

@GB907762 GB907762 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rate limiting might be good? You could abuse this by just hogging Bailo resources? Meaning no one else can use the tool?

export function tooBusy(req, res, next) {
if (toobusy()) {
log.warn('Server response time too long, preventing more requests from being handled.')
res.status(503).send('Server Too Busy')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw a ConfigurationError

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I naively assumed this library was only limiting requests from the same origin. Also, is ConfigurationError what we want? To me that would imply that there was a problem with the configuration, whereas this is a purposely thrown error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our naming for this error isn't correct. Really it should be ServiceUnavailable but we should let our error handler handle it so that error is consistent for the user, inline with all other errors within the app.

Have a look here for usage of a 503

Common causes are that a server is down for maintenance or overloaded

@GCHQDeveloper36

Copy link
Copy Markdown
Member

That library hasn't been updated in 10 years (although how much maintenance does it need) - maybe a slightly different approach by using rate limiting like suggested above - perhaps: https://www.npmjs.com/package/express-rate-limit instead?

@GB907762

Copy link
Copy Markdown
Member

That library hasn't been updated in 10 years (although how much maintenance does it need) - maybe a slightly different approach by using rate limiting like suggested above - perhaps: https://www.npmjs.com/package/express-rate-limit instead?

https://github.com/STRML/node-toobusy/blob/master/toobusy.js#L35-L41

too-busy.js looks equally old. Although it looks fairly minimal. You could make a small function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Changes affecting server-side logic, APIs, data processing, or internal services. javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants