Skip to content
Open
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
36 changes: 36 additions & 0 deletions coprocessor/fhevm-engine/gw-listener/src/aws_s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,38 @@ fn bucket_from_domain(url: &Url) -> anyhow::Result<String> {
Ok(domain_parts[0].to_owned())
}

fn is_url_suspicious(parsed_url_and_bucket: &Url) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

no unit test?

Else lgtm
My understanding, url is suspicious if there are any of:

  • query
  • fragment
  • username
  • password
  • not http or https
  • no host

if parsed_url_and_bucket.query().is_some() || parsed_url_and_bucket.fragment().is_some() {
warn!(
url = %parsed_url_and_bucket,
"S3 bucket URL contains query or fragment, which looks suspicious"
);
return true;
}
if parsed_url_and_bucket.username() != "" || parsed_url_and_bucket.password().is_some() {
warn!(
url = %parsed_url_and_bucket,
"S3 bucket URL contains username or password, which looks suspicious"
);
return true;
}
if !["https", "http"].contains(&parsed_url_and_bucket.scheme()) {
warn!(
url = %parsed_url_and_bucket,
"S3 bucket URL scheme is neither http nor https, which looks suspicious"
);
return true;
}
if parsed_url_and_bucket.host_str().is_none() {
warn!(
url = %parsed_url_and_bucket,
"S3 bucket URL has no host, which looks suspicious"
);
return true;
}
false
}

fn split_url(s3_bucket_url: &String) -> anyhow::Result<(String, String)> {
// e.g BBBBBB.s3.bla.bli.amazonaws.blu, the bucket is part of the domain
let s3_bucket_url = if s3_bucket_url.contains("minio:9000") {
Expand All @@ -154,6 +186,10 @@ fn split_url(s3_bucket_url: &String) -> anyhow::Result<(String, String)> {
s3_bucket_url.to_owned()
};
let parsed_url_and_bucket = url::Url::parse(&s3_bucket_url)?;
if is_url_suspicious(&parsed_url_and_bucket) {
error!(s3_bucket_url, "S3 bucket URL looks suspicious");
return Err(anyhow::Error::msg("S3 bucket URL looks suspicious"));
}
let mut bucket = parsed_url_and_bucket
.path()
.trim_start_matches('/')
Expand Down
Loading