mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[chore] skip trusted-proxies
warning if ip excepted from rate limiting (#3699)
* [chore] skip `trusted-proxies` warning if ip excepted from rate limiting * weep * typo * fix env parsing test
This commit is contained in:
@@ -48,7 +48,7 @@ const rateLimitPeriod = 5 * time.Minute
|
||||
//
|
||||
// If the config AdvancedRateLimitRequests value is <= 0, then a noop
|
||||
// handler will be returned, which performs no rate limiting.
|
||||
func RateLimit(limit int, exceptions []string) gin.HandlerFunc {
|
||||
func RateLimit(limit int, except []netip.Prefix) gin.HandlerFunc {
|
||||
if limit <= 0 {
|
||||
// Rate limiting is disabled.
|
||||
// Return noop middleware.
|
||||
@@ -63,12 +63,6 @@ func RateLimit(limit int, exceptions []string) gin.HandlerFunc {
|
||||
},
|
||||
)
|
||||
|
||||
// Convert exceptions IP ranges into prefixes.
|
||||
exceptPrefs := make([]netip.Prefix, len(exceptions))
|
||||
for i, str := range exceptions {
|
||||
exceptPrefs[i] = netip.MustParsePrefix(str)
|
||||
}
|
||||
|
||||
// It's prettymuch impossible to effectively
|
||||
// rate limit the immense IPv6 address space
|
||||
// unless we mask some of the bytes.
|
||||
@@ -88,7 +82,7 @@ func RateLimit(limit int, exceptions []string) gin.HandlerFunc {
|
||||
|
||||
// Check if this IP is exempt from rate
|
||||
// limits and skip further checks if so.
|
||||
for _, prefix := range exceptPrefs {
|
||||
for _, prefix := range except {
|
||||
if prefix.Contains(clientIP) {
|
||||
c.Next()
|
||||
return
|
||||
|
Reference in New Issue
Block a user