RFC: Issues with multiple Attack instances in the same process / Rack stack (class ivar binding) #569
Replies: 4 comments
-
Interesting idea, though I'm trying to understand the motivation. Can you explain your use-case a bit more? |
Beta Was this translation helpful? Give feedback.
-
We are using multiple Rack apps within our Rails monolith. Within some of these apps we would like to throttle based on some context that does not get set up globally, but gets set up only within that particular app (mostly API endpoints). This means that we need to have lots if |
Beta Was this translation helpful? Give feedback.
-
It sounds like something worth trying. |
Beta Was this translation helpful? Give feedback.
-
We're seeing similar issues, in our case there are some throttles we can apply without any user details. We then hit an internal service to get additional information about the connecting user, then apply any rate limits which require things like the list of user roles applied to their account. We've worked around it with a middleware inserted after the first phase which deletes the key |
Beta Was this translation helpful? Give feedback.
-
I would like to use multiple instances of Rack::Attack in the same Rack stack, but in different places. Each one of these would accept it's own throttles, blacklists etc. Judging from the code, I assumed I could do
It turned out, however, that the method performing the throttling still reaches into the attribute reader of the superclass, and thus finds throttles defined on the parent instance. I think the same is the case for blacklisting and whitelisting, but I don't necessarily need them in this specific application. I was only able to make throttles work in a subclass by doing
This stems from the fact that some smart machinery is involved in making the configuration available on the class level. I think that it might make more sense if the same configuration could be applied with, say, options (since block handling with middleware attachment is not that well understood):
So I think there was some thought given to separating the various classes' configurations within one Ruby process, but this was not really tested. You could in theory alter the
throttled?
etc. methods to call into the right class for the variables and consider this a bug, but maybe the API can just be improved and handle this explicitly?Beta Was this translation helpful? Give feedback.
All reactions