mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 22:17:22 +01:00
add userid to ratelimit calls
This commit is contained in:
parent
5adcb7421b
commit
9c11d8dcbc
1 changed files with 4 additions and 1 deletions
|
|
@ -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}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue