Skip to content

Commit a1c63e4

Browse files
committed
feat: check server returns a PNG image
1 parent e57f883 commit a1c63e4

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/types/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ ark-ff.workspace = true
1414
eigen-crypto-bls.workspace = true
1515
eigen-utils.workspace = true
1616
ethers.workspace = true
17-
num-bigint = "0.4.4"
18-
regex = "1"
1917
serde_json.workspace = true
2018
serde.workspace = true
2119
thiserror.workspace = true
2220
tokio.workspace = true
2321
url.workspace = true
2422

23+
num-bigint = "0.4.4"
24+
regex = "1"
25+
mime-sniffer = "0.1"
26+
2527
[dev-dependencies]
2628
ark-bn254.workspace = true

crates/types/src/operator_metadata.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use alloy::transports::http::reqwest::Url;
1+
use alloy::transports::http::reqwest::{self, Url};
2+
use mime_sniffer::MimeTypeSniffer;
23
use serde::{Deserialize, Serialize};
34
use std::path::PathBuf;
45
use thiserror::Error;
@@ -46,6 +47,8 @@ pub enum OperatorMetadataError {
4647
LogoUrlInvalid,
4748
#[error("Logo url has an invalid image extension")]
4849
LogoUrlInvalidImageExtension,
50+
#[error("Logo has an unsupported mime type")]
51+
LogoUrlInvalidMimeType,
4952

5053
#[error("Website url is invalid")]
5154
WebsiteUrlInvalid,
@@ -104,7 +107,12 @@ impl OperatorMetadata {
104107
if path.extension().map(|ext| ext != "png").unwrap_or(true) {
105108
return Err(LogoUrlInvalidImageExtension);
106109
}
107-
// TODO: check if the server returns the content with a "image/png" mime type
110+
let response = reqwest::get(&self.logo).await.unwrap();
111+
let body = response.bytes().await.unwrap();
112+
113+
if body.sniff_mime_type().map_or(true, |m| m != "image/png") {
114+
return Err(LogoUrlInvalidMimeType);
115+
}
108116

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

0 commit comments

Comments
 (0)