cliss/accidentalbot — pull request #10 by jeremybanks (2014-06-22 12:41:20+00:00)
Title:  Disconnect IP addresses which are flooding requests/messages 

(Replacing #6, given changes to history.)

Very basic, probably inadequate, but hopefully helpful DOS protection. This disconnects any users who send more than 50 messages or connection requests in a 5-second window. (This could probably be set a lot more aggressively if you wanted.)

In my limited testing this made a difference in how much a single flooding user could affect the responsiveness for other users. However, my testing was not aggressive enough to bring down a local server or a Heroku instance, so it might be much less than whatever this was attacking during the last show.

This adds the ability to switch to non-proxied mode by the environment variable `PROXIED=false`, which is useful for local testing. The default behaviour remains what we want for Heroku.

In proxied, the value of the `x-forwarded-for` header is comma-split, and only the last component is taken, since only this component may be trusted -- the rest may be provided by the end user or untrusted proxies. (The user would be able to so change the overall value and avoid the throttling.)