go-chi / httprate

net/http rate limiter middleware
MIT License
270 stars 18 forks source link

There should be a delimiter between key components to avoid conflict #18

Closed tamalsaha closed 1 year ago

tamalsaha commented 1 year ago

https://github.com/go-chi/httprate/blob/master/httprate.go#L101

pkieltyka commented 1 year ago

Thanks for the note — do you mind elaborating what is the potential key conflict?

tamalsaha commented 1 year ago

Say there are 2 key functions k1, k2

For req_1, k1(req_1) = aa and k2(req_1) = b, so final key = aab For req_2, k1(req_2) = a and k2(req_2) = ab, so final key = aab

If some kind of delimiter is used to concat the components, this two requests will not generate the same final key.

pkieltyka commented 1 year ago

Ah yes indeed. Thx, I’ll separate with “:”

pkieltyka commented 1 year ago

solved https://github.com/go-chi/httprate/commit/0ea2148d09a46ae62efcad05b70d87418d8e4f43 / https://github.com/go-chi/httprate/tree/v0.7.1