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

security: Rate limit GetAddr responses #7955

Merged
merged 26 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
969819f
Updates ADDR_RESPONSE_LIMIT_DENOMINATOR to 4
arya2 Nov 16, 2023
ba0cfc6
Moves logic getting a fraction of Zebra's peers to a method in the ad…
arya2 Nov 16, 2023
70e0cc1
Adds and uses CachedPeerAddrs struct in inbound service
arya2 Nov 16, 2023
81cf5a5
moves and documents constant
arya2 Nov 16, 2023
f28c529
fixes test
arya2 Nov 16, 2023
a82a404
Apply suggestions from code review
arya2 Nov 17, 2023
78234ba
updates docs
arya2 Nov 17, 2023
a5d6b25
renames sanitized_window method
arya2 Nov 17, 2023
a431e1b
renames CachedPeerAddrs to CachedPeerAddrResponse
arya2 Nov 17, 2023
66e1cfc
updates test
arya2 Nov 17, 2023
788c620
moves try_refresh to per request
arya2 Nov 17, 2023
29f3aed
Make unused sanitization method pub(crate)
teor2345 Nov 19, 2023
2032361
Apply suggestions from code review
arya2 Nov 20, 2023
f2c2968
moves CachedPeerAddrResponse to a module
arya2 Nov 20, 2023
2ee9a20
updates unit test
arya2 Nov 20, 2023
4d9bc0f
fixes unit test
arya2 Nov 20, 2023
7c35da6
removes unnecessary condition
arya2 Nov 20, 2023
cca2857
clears cached getaddr response if it can't refresh for over a minute …
arya2 Nov 20, 2023
7c84398
tests that inbound service gives out the same addresses for every Pee…
arya2 Nov 20, 2023
f72a52b
Applies suggestion from code review
arya2 Nov 20, 2023
5327d17
fixes doc link
arya2 Nov 20, 2023
1e3fb0e
renames constant
arya2 Nov 20, 2023
a4a8963
Fix docs on new constant
arya2 Nov 20, 2023
f902adb
applies suggestion from code review
arya2 Nov 20, 2023
120b6a5
uses longer cache expiry time
arya2 Nov 20, 2023
48f419e
Adds code comments
arya2 Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adds code comments
  • Loading branch information
arya2 committed Nov 21, 2023
commit 48f419e3db72ab254e9101ffe75ef4e90b98372d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{

use super::*;

/// The minumum duration that a `CachedPeerAddrResponse` is considered fresh before the inbound service
/// The minimum duration that a `CachedPeerAddrResponse` is considered fresh before the inbound service
/// should get new peer addresses from the address book to send as a `GetAddr` response.
///
/// Cached responses are considered stale and should be cleared after twice this duration.
Expand Down Expand Up @@ -68,6 +68,7 @@ impl CachedPeerAddrResponse {
self.value = zn::Response::Peers(peers);
}

// Clear the cached response if the time has past the cache expiry time.
Ok(_) if now > cache_expiry => {
self.value = zn::Response::Nil;
}
Expand All @@ -77,6 +78,8 @@ impl CachedPeerAddrResponse {
self.value = zn::Response::Nil;
}

// Don't update the cached response or refresh time if unable to get new peer addresses
// from the address book and `now` is before the cache expiry.
Ok(_) => {
debug!(
"could not refresh cached response because our address \
Expand All @@ -86,6 +89,7 @@ impl CachedPeerAddrResponse {

Err(TryLockError::WouldBlock) => {}

// Panic if the address book lock is poisoned
Err(TryLockError::Poisoned(_)) => {
panic!("previous thread panicked while holding the address book lock")
}
Expand Down
Loading