@@ -72,6 +72,7 @@ type Server struct {
72
72
overrideLims map [string ]FrontendRateLimiter
73
73
senderLim FrontendRateLimiter
74
74
allowedChainIds []* big.Int
75
+ limExemptProxyClients []* regexp.Regexp
75
76
limExemptOrigins []* regexp.Regexp
76
77
limExemptUserAgents []* regexp.Regexp
77
78
globallyLimitedMethods map [string ]bool
@@ -131,10 +132,18 @@ func NewServer(
131
132
}
132
133
133
134
var mainLim FrontendRateLimiter
135
+ limExemptProxyClients := make ([]* regexp.Regexp , 0 )
134
136
limExemptOrigins := make ([]* regexp.Regexp , 0 )
135
137
limExemptUserAgents := make ([]* regexp.Regexp , 0 )
136
138
if rateLimitConfig .BaseRate > 0 {
137
139
mainLim = limiterFactory (time .Duration (rateLimitConfig .BaseInterval ), rateLimitConfig .BaseRate , "main" )
140
+ for _ , client := range rateLimitConfig .ExemptProxyClients {
141
+ pattern , err := regexp .Compile (client )
142
+ if err != nil {
143
+ return nil , err
144
+ }
145
+ limExemptProxyClients = append (limExemptProxyClients , pattern )
146
+ }
138
147
for _ , origin := range rateLimitConfig .ExemptOrigins {
139
148
pattern , err := regexp .Compile (origin )
140
149
if err != nil {
@@ -194,6 +203,7 @@ func NewServer(
194
203
globallyLimitedMethods : globalMethodLims ,
195
204
senderLim : senderLim ,
196
205
allowedChainIds : senderRateLimitConfig .AllowedChainIds ,
206
+ limExemptProxyClients : limExemptProxyClients ,
197
207
limExemptOrigins : limExemptOrigins ,
198
208
limExemptUserAgents : limExemptUserAgents ,
199
209
rateLimitHeader : rateLimitHeader ,
@@ -269,6 +279,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
269
279
userAgent := r .Header .Get ("User-Agent" )
270
280
// Use XFF in context since it will automatically be replaced by the remote IP
271
281
xff := stripXFF (GetXForwardedFor (ctx ))
282
+ isUnlimitedProxyClient := s .isUnlimitedProxyClient (xff )
272
283
isUnlimitedOrigin := s .isUnlimitedOrigin (origin )
273
284
isUnlimitedUserAgent := s .isUnlimitedUserAgent (userAgent )
274
285
@@ -279,7 +290,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
279
290
280
291
isLimited := func (method string ) bool {
281
292
isGloballyLimitedMethod := s .isGlobalLimit (method )
282
- if ! isGloballyLimitedMethod && (isUnlimitedOrigin || isUnlimitedUserAgent ) {
293
+ if ! isGloballyLimitedMethod && (isUnlimitedProxyClient || isUnlimitedOrigin || isUnlimitedUserAgent ) {
283
294
return false
284
295
}
285
296
@@ -802,6 +813,15 @@ func randStr(l int) string {
802
813
return hex .EncodeToString (b )
803
814
}
804
815
816
+ func (s * Server ) isUnlimitedProxyClient (client string ) bool {
817
+ for _ , pat := range s .limExemptProxyClients {
818
+ if pat .MatchString (client ) {
819
+ return true
820
+ }
821
+ }
822
+
823
+ return false
824
+ }
805
825
func (s * Server ) isUnlimitedOrigin (origin string ) bool {
806
826
for _ , pat := range s .limExemptOrigins {
807
827
if pat .MatchString (origin ) {
0 commit comments