question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rate limit rules based on whether or not a request is to an endpoint that needs authentication

See original GitHub issue

Hello,

I was wondering if I could get some help with/pointers for implementing rate limiting based on whether or not a request is hitting an api endpoint that needs authentication?

I thought I could add a GeneralRules section to my appsettings.json file, where I start off with with the first rule targeting * and then get more specific, and override it, but it doesnt seem to work :

                {
			"Endpoint": "*",
			"Period": "1h",
			"Limit": 60
		},
		{
			"Endpoint": "*:/my-non-authenticated-endpoint",
			"Period": "1h",
			"Limit": 120
		},

So that by default all my endpoints except for my-non-authenticated-endpoint would have the first rule, and my-non-authenticated-endpoint would have my second rule, but it doesnt seem to work that way? or do I have bad rules? I’m going off of IpRateLimiting with Redis, if it makes a difference.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
dupuis2387commented, Sep 21, 2020

Sorry, i was being dense. I got what I needed by using

app.UseWhen(x => x.User.Identity.IsAuthenticated, builder => builder.UseClientRateLimiting()); app.UseWhen(x => !x.User.Identity.IsAuthenticated, builder => app.UseIpRateLimiting());

and configuring both ClientRateLimiting and IpRateLimiting settings in my appSettings.json file

0reactions
manisha201301commented, Jul 28, 2021

@dupuis2387 d Did you explored if there any way to override ResolveClientAsync(HttpContext httpContext) to use custom-client-id or ip-address based on a if-else condition?

Read more comments on GitHub >

github_iconTop Results From Across the Web

AspNetCoreRateLimit and rate limit rules based on ...
AspNetCoreRateLimit and rate limit rules based on whether or not a request is to an endpoint that needs authentication.
Read more >
Rate Limit Policy
To ensure the quality of Auth0's services, the Auth0 APIs are subject to rate limiting. Depending on the API endpoint, the request limit...
Read more >
load balancing - Rate limiting *un*-authenticated requests
Another approach to rate limiting you can take is to require a proof of work for any unauthenticated requests.
Read more >
Rate-based rule statement
The rule aggregates requests according to your criteria, and counts and rate limits the aggregate groupings, based on the rule's limit and action...
Read more >
Rate limiting best practices - WAF
These two rate limiting rules match requests performing a selected action (look up price, in this example) and use IP as the counting ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found