From 9c11d8dcbcb70dda1444bcfaf113d71302c0c210 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Sat, 6 Aug 2022 00:43:26 +0200 Subject: [PATCH] add userid to ratelimit calls --- .../MareSynchronosServer/Throttling/SignalRLimitFilter.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MareSynchronosServer/MareSynchronosServer/Throttling/SignalRLimitFilter.cs b/MareSynchronosServer/MareSynchronosServer/Throttling/SignalRLimitFilter.cs index 66cdba2..0664b39 100644 --- a/MareSynchronosServer/MareSynchronosServer/Throttling/SignalRLimitFilter.cs +++ b/MareSynchronosServer/MareSynchronosServer/Throttling/SignalRLimitFilter.cs @@ -4,6 +4,8 @@ using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; +using System.Linq; +using System.Security.Claims; using System.Threading.Tasks; namespace MareSynchronosServer.Throttling; @@ -37,8 +39,9 @@ public class SignalRLimitFilter : IHubFilter var counter = await _processor.ProcessRequestAsync(client, rule); if (counter.Count > rule.Limit) { + var authUserId = invocationContext.Context.User.Claims?.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ?? "Unknown"; var retry = counter.Timestamp.RetryAfterFrom(rule); - logger.LogWarning($"Method rate limit triggered from {ip}: {invocationContext.HubMethodName}"); + logger.LogWarning($"Method rate limit triggered from {ip}/{authUserId}: {invocationContext.HubMethodName}"); throw new HubException($"call limit {retry}"); } }