@@ -86,22 +86,27 @@ func NewRatelimitingInterceptor(f map[string]RateLimit) RatelimitingInterceptor
86
86
}
87
87
88
88
func fieldAccessKey (key string ) keyFunc {
89
+ fields := strings .Split (key , "," )
90
+ paths := make ([][]string , len (fields ))
91
+ for i , field := range fields {
92
+ paths [i ] = strings .Split (field , "." )
93
+ }
89
94
return func (req interface {}) (string , error ) {
90
95
msg , ok := req .(proto.Message )
91
96
if ! ok {
92
97
return "" , status .Errorf (codes .Internal , "request was not a protobuf message" )
93
98
}
94
99
95
- fields := strings .Split (key , "," )
96
100
var composite string
97
- for _ , field := range fields {
98
- val , ok := getFieldValue (msg .ProtoReflect (), strings . Split ( field , "." ) )
101
+ for i , field := range fields {
102
+ val , ok := getFieldValue (msg .ProtoReflect (), paths [ i ] )
99
103
if ! ok {
100
104
return "" , status .Errorf (codes .Internal , "Field %s does not exist in message. This is a rate limiting configuration error." , field )
101
105
}
102
106
// It's technically possible that `|` is part of one of the field values, and therefore could cause collisions
103
107
// in composite keys, e.g. values (`a|`, `b`), and (`a`, `|b`) would result in the same composite key `a||b`
104
- // and share the rate limit. This is currently not possible though given the fields we rate limit on.
108
+ // and share the rate limit. This is highly unlikely though given the current fields we rate limit on and
109
+ // otherwise unlikely to cause issues.
105
110
composite += "|" + val
106
111
}
107
112
0 commit comments