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

Enforce same origin for all resources of an RRDP server. #953

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion src/collector/rrdp/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;
use bytes::Bytes;
use chrono::{DateTime, Utc};
use log::{error, warn};
use reqwest::header;
use reqwest::{header, redirect};
use reqwest::{Certificate, Proxy, StatusCode};
use reqwest::blocking::{Client, ClientBuilder, RequestBuilder, Response};
use rpki::uri;
Expand Down Expand Up @@ -52,6 +52,9 @@ impl HttpClient {
builder = builder.user_agent(&config.rrdp_user_agent);
builder = builder.tcp_keepalive(config.rrdp_tcp_keepalive);
builder = builder.timeout(None); // Set per request.
builder = builder.redirect(
redirect::Policy::custom(Self::redirect_policy)
);
if let Some(timeout) = config.rrdp_connect_timeout {
builder = builder.connect_timeout(timeout);
}
Expand Down Expand Up @@ -256,6 +259,29 @@ impl HttpClient {
}
}
*/

/// The redirect policy.
///
/// We allow up to 10 redirects (reqwest’s default policy) but only if
/// the origin stays the same.
fn redirect_policy(attempt: redirect::Attempt) -> redirect::Action {
if attempt.previous().len() > 9 {
return attempt.stop();
}
let orig = match attempt.previous().first() {
Some(url) => url,
None => return attempt.follow() // Shouldn’t happen?
};
let new = attempt.url();
let orig = (orig.scheme(), orig.host(), orig.port());
let new = (new.scheme(), new.host(), new.port());
if orig == new {
attempt.follow()
}
else {
attempt.stop()
}
}
}


Expand Down
6 changes: 6 additions & 0 deletions src/collector/rrdp/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ impl Notification {
warn!("RRDP {}: {}", uri, err);
Failed
})?;
if !content.has_matching_origins(&uri) {
warn!("RRDP {}: snapshot or delta files with different origin",
uri
);
return Err(Failed)
}
content.sort_deltas();
Ok(Notification { uri, content, etag, last_modified })
}
Expand Down
Loading