dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 2bd756ef86e9fa0b929ab32b515e90b10efb4350
parent 45f6f745619ccc8966ac597cc7127335eb3f6cc5
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 18 Dec 2022 15:44:27 -0800

cleanup

Diffstat:
Mpkg/web/middlewares/middlewares.go | 21+++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/pkg/web/middlewares/middlewares.go b/pkg/web/middlewares/middlewares.go @@ -390,29 +390,26 @@ func AprilFoolMiddleware() echo.MiddlewareFunc { } func DdosMiddleware(next echo.HandlerFunc) echo.HandlerFunc { + stopFn := func(c echo.Context) error { + hutils.KillCircuit(c) + config.RejectedReqCounter.Incr() + time.Sleep(utils.RandSec(5, 20)) + return c.NoContent(http.StatusOK) + } return func(c echo.Context) error { config.RpsCounter.Incr() if authCookie, err := c.Cookie(hutils.AuthCookieName); err == nil { if len(authCookie.Value) > 64 { - hutils.KillCircuit(c) - config.RejectedReqCounter.Incr() - time.Sleep(utils.RandSec(5, 20)) - return c.NoContent(http.StatusOK) + return stopFn(c) } } if csrfCookie, err := c.Cookie("_csrf"); err == nil { if len(csrfCookie.Value) > 32 { - hutils.KillCircuit(c) - config.RejectedReqCounter.Incr() - time.Sleep(utils.RandSec(5, 20)) - return c.NoContent(http.StatusOK) + return stopFn(c) } } if len(c.QueryParam("captcha")) > 6 { - hutils.KillCircuit(c) - config.RejectedReqCounter.Incr() - time.Sleep(utils.RandSec(5, 20)) - return c.NoContent(http.StatusOK) + return stopFn(c) } return next(c) }