Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[server] Reduce SRP rate-limit notification noise (#13219)

neeraj-pilot49bae0d95a46
diff --git a/server/pkg/middleware/rate_limit.go b/server/pkg/middleware/rate_limit.go
index 9a57da7962..9d7b4c5f4f 100644
--- a/server/pkg/middleware/rate_limit.go
+++ b/server/pkg/middleware/rate_limit.go
@@ -154,7 +154,9 @@ func (r *RateLimitMiddleware) isRateLimited(c *gin.Context, rateLimiter *limiter
return false
}
recordRateLimitRejection(scope, c.Request.Method, requestPath)
- go r.discordCtrl.NotifyPotentialAbuse(message)
+ if shouldNotifyPotentialAbuse(scope, requestPath) {
+ go r.discordCtrl.NotifyPotentialAbuse(message)
+ }
log.WithFields(log.Fields{
"rate_limit_scope": scope,
"req_id": requestid.Get(c),
@@ -165,6 +167,10 @@ func (r *RateLimitMiddleware) isRateLimited(c *gin.Context, rateLimiter *limiter
return true
}
+func shouldNotifyPotentialAbuse(scope rateLimitScope, requestPath string) bool {
+ return scope != rateLimitScopeIP || requestPath != "/users/srp/attributes"
+}
+
func recordRateLimitRejection(scope rateLimitScope, method string, requestPath string) {
rateLimitRejections.WithLabelValues(string(scope), method, requestPath).Inc()
}
diff --git a/server/pkg/middleware/rate_limit_metrics_test.go b/server/pkg/middleware/rate_limit_metrics_test.go
index 6b62eb8688..abebc07e75 100644
--- a/server/pkg/middleware/rate_limit_metrics_test.go
+++ b/server/pkg/middleware/rate_limit_metrics_test.go
@@ -27,6 +27,23 @@ func TestRecordRateLimitRejection(t *testing.T) {
}
}
+func TestShouldNotifyPotentialAbuse(t *testing.T) {
+ tests := []struct {
+ scope rateLimitScope
+ path string
+ want bool
+ }{
+ {rateLimitScopeIP, "/users/srp/attributes", false},
+ {rateLimitScopeIP, "/users/srp/create-session", true},
+ {rateLimitScopeRouteGlobal, "/users/srp/attributes", true},
+ }
+ for _, tt := range tests {
+ if got := shouldNotifyPotentialAbuse(tt.scope, tt.path); got != tt.want {
+ t.Errorf("shouldNotifyPotentialAbuse(%q, %q) = %t, want %t", tt.scope, tt.path, got, tt.want)
+ }
+ }
+}
+
func TestRateLimitScopeLabels(t *testing.T) {
tests := []struct {
scope rateLimitScope