From c45d55938b09c84a6870e21eecb2b6b72e418a11 Mon Sep 17 00:00:00 2001 From: anupamme Date: Sat, 3 Oct 2026 08:09:20 +0000 Subject: [PATCH] fix: secure auth.go The BasicAuth middleware lacks rate limiting, account lockout, or progressive delay mechanisms Addresses CWE-799 --- auth.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/auth.go b/auth.go index 5d3222d5..9221e145 100644 --- a/auth.go +++ b/auth.go @@ -9,10 +9,16 @@ import ( "encoding/base64" "net/http" "strconv" + "time" "github.com/gin-gonic/gin/internal/bytesconv" ) +// basicAuthFailureDelay is a small artificial delay applied on failed +// authentication attempts to throttle brute-force and credential-stuffing +// attacks against BasicAuth protected routes. +const basicAuthFailureDelay = 500 * time.Millisecond + // AuthUserKey is the cookie name for user credential in basic auth. const AuthUserKey = "user"