Conversation
Redis was misconfigured for a long time in timdex-api. That was patched yesterday. On doing so, it exposed this incorrect configuration in rack-attack that was missed during a version upgrade. https://mitlibraries.atlassian.net/browse/TIMX-679
matt-bernhardt
left a comment
There was a problem hiding this comment.
I see that the PR has been merged, and this ticket closed. I also think I remember that you wanted to do a retroactive review - so that's what I'm doing now.
I'm fine with the approach we're using here, but have two questions to help me understand.
First, I'm wondering whether it would make sense to extract the calculation of reset to a helper function? Part of me says "no, this is the only place where this value gets used" - but then I wonder whether having a separate helper would let us document its operation more clearly. So I'm torn.
Second, you mention in the PR text that TIMDEX-UI has already fixed this issue, but when I look at the initializer over there, it doesn't seem similar to what we're doing here - and when I look at the Rack::Attack docmentation, what they indicate seems to be what we're moving away from (which caused the issue in Sentry that started this). My question about all of this is whether I'm understanding the intent of this change (that we have a fallback method of calculating reset in case env doesn't have a value in rack.attack.match_data)
Neither of these two questions are me asking for a change, or saying that I'd have denied a code review - this works, which is the concern.
![]()
| match_data = request.env['rack.attack.match_data'] || {} | ||
| now = match_data[:epoch_time] || Time.now.to_i | ||
| period = match_data[:period].to_i | ||
| reset = period.positive? ? (now + (period - now % period)) : now |
There was a problem hiding this comment.
Is there a world where we extract lines 85-88 to some helper method to make the assembly of this value more separate / testable? I really like the approach of calculating reset separately from the invocation of it down on line 94, but working out the logic of how we got there took me a minute.
Redis was misconfigured for a long time in timdex-api. That was patched yesterday. On doing so, it exposed this incorrect configuration in rack-attack that was missed during a version upgrade.
https://mitlibraries.atlassian.net/browse/TIMX-679
This was already fixed in TIMDEX-UI and only missed in TIMDEX API because rack-attack was not realized to have been not working for different reasons.
Developer
our guide and
all issues introduced by these changes have been resolved or opened as new
issues (link to those issues in the Pull Request details above)
Code Reviewer
(not just this pull request message)
Requires database migrations?
NO
Includes new or updated dependencies?
NO