Skip to content

Commit

Permalink
feat: check server returns a PNG image
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Feb 17, 2025
1 parent e57f883 commit a1c63e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions crates/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ ark-ff.workspace = true
eigen-crypto-bls.workspace = true
eigen-utils.workspace = true
ethers.workspace = true
num-bigint = "0.4.4"
regex = "1"
serde_json.workspace = true
serde.workspace = true
thiserror.workspace = true
tokio.workspace = true
url.workspace = true

num-bigint = "0.4.4"
regex = "1"
mime-sniffer = "0.1"

[dev-dependencies]
ark-bn254.workspace = true
12 changes: 10 additions & 2 deletions crates/types/src/operator_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy::transports::http::reqwest::Url;
use alloy::transports::http::reqwest::{self, Url};
use mime_sniffer::MimeTypeSniffer;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use thiserror::Error;
Expand Down Expand Up @@ -46,6 +47,8 @@ pub enum OperatorMetadataError {
LogoUrlInvalid,
#[error("Logo url has an invalid image extension")]
LogoUrlInvalidImageExtension,
#[error("Logo has an unsupported mime type")]
LogoUrlInvalidMimeType,

#[error("Website url is invalid")]
WebsiteUrlInvalid,
Expand Down Expand Up @@ -104,7 +107,12 @@ impl OperatorMetadata {
if path.extension().map(|ext| ext != "png").unwrap_or(true) {
return Err(LogoUrlInvalidImageExtension);
}
// TODO: check if the server returns the content with a "image/png" mime type
let response = reqwest::get(&self.logo).await.unwrap();
let body = response.bytes().await.unwrap();

if body.sniff_mime_type().map_or(true, |m| m != "image/png") {
return Err(LogoUrlInvalidMimeType);
}

// website, if non-empty, must have less than 1024 characters,
// not point to localhost or 127.0.0.1, and must be a valid URL that matches the regex
Expand Down

0 comments on commit a1c63e4

Please sign in to comment.