Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8067 Use nanotime for DosFilter rate tracker #8082

Merged
merged 3 commits into from Jun 6, 2022

Conversation

gregw
Copy link
Contributor

@gregw gregw commented May 31, 2022

Use nano time to avoid false positives when wall clock changes.

Use nano time to avoid false positives when wall clock changes.
@gregw gregw added this to In progress in Jetty 9.4.47 - 🧊 FROZEN 🥶 via automation May 31, 2022
@gregw gregw requested a review from joakime May 31, 2022 06:54
@gregw gregw linked an issue May 31, 2022 that may be closed by this pull request
Jetty 9.4.47 - 🧊 FROZEN 🥶 automation moved this from In progress to Review in progress Jun 1, 2022
@@ -1235,7 +1235,7 @@ public OverLimit isRateExceeded(long now)
}

long rate = (now - last);
if (rate < 1000L)
if (TimeUnit.NANOSECONDS.toSeconds(rate) < 1L)
{
return new Overage(Duration.ofMillis(rate), _maxRequestsPerSecond);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this still using Duration.ofMillis ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@@ -326,7 +326,7 @@ protected void doFilter(HttpServletRequest request, HttpServletResponse response
tracker = getRateTracker(request);

// Calculate the rate and check if it is over the allowed limit
final OverLimit overLimit = tracker.isRateExceeded(System.currentTimeMillis());
final OverLimit overLimit = tracker.isRateExceeded(System.nanoTime());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the javadoc of isRateExceeded. It specifies that the value is in ms.

now the time now (in milliseconds)

lorban
lorban previously approved these changes Jun 3, 2022
@@ -1216,7 +1216,7 @@ public RateTracker(ServletContext context, String filterName, String id, RateTyp
}

/**
* @param now the time now (in milliseconds)
* @param now the time now (in nanoseconds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please mention elapsed time or something in the javadoc as a hint that nanoTime() should be used instead of currentTimeMillis()?

olamy
olamy previously approved these changes Jun 3, 2022
sbordet
sbordet previously approved these changes Jun 3, 2022
@gregw gregw dismissed stale reviews from sbordet, olamy, and lorban via 974637e June 3, 2022 22:50
@gregw
Copy link
Contributor Author

gregw commented Jun 3, 2022

@lachlan-roberts can you rereview to remove your objection.

Jetty 9.4.47 - 🧊 FROZEN 🥶 automation moved this from Review in progress to Reviewer approved Jun 5, 2022
@gregw
Copy link
Contributor Author

gregw commented Jun 6, 2022

I think the CI failure is some kind of CI problem. Distribution tests work locally

@gregw gregw merged commit fb65b2e into jetty-9.4.x Jun 6, 2022
Jetty 9.4.47 - 🧊 FROZEN 🥶 automation moved this from Reviewer approved to Done Jun 6, 2022
@gregw gregw deleted the jetty-9.4.x-8067-nanotrackertime branch June 6, 2022 00:41
gregw added a commit that referenced this pull request Jun 6, 2022
* Fix #8067 Use nanotime for DosFilter rate tracker

Use nano time to avoid false positives when wall clock changes.
gregw added a commit that referenced this pull request Jun 7, 2022
* Fix #8067 Use nanotime for DosFilter rate tracker

Use nano time to avoid false positives when wall clock changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Wall time usage in DoSFilter RateTracker results in false positive alert
5 participants