Skip to content

Commit

Permalink
XC-246: remove errHostNotAllowed
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorydemay committed Nov 28, 2024
1 parent 2eccb25 commit 2544848
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 57 deletions.
1 change: 0 additions & 1 deletion candid/evm_rpc.did
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ type Metrics = record {
cyclesCharged : vec record { record { text; text }; nat };
errNoPermission : nat64;
errHttpOutcall : vec record { record { text; text }; nat64 };
errHostNotAllowed : vec record { text; nat64 };
};
type MultiFeeHistoryResult = variant {
Consistent : FeeHistoryResult;
Expand Down
2 changes: 0 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ pub const ETH_SEPOLIA_CHAIN_ID: u64 = 11155111;
pub const ARBITRUM_ONE_CHAIN_ID: u64 = 42161;
pub const BASE_MAINNET_CHAIN_ID: u64 = 8453;
pub const OPTIMISM_MAINNET_CHAIN_ID: u64 = 10;

pub const SERVICE_HOSTS_BLOCKLIST: &[&str] = &[];
10 changes: 1 addition & 9 deletions src/http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
accounting::{get_cost_with_collateral, get_http_request_cost},
add_metric_entry,
constants::{CONTENT_TYPE_HEADER_LOWERCASE, CONTENT_TYPE_VALUE, SERVICE_HOSTS_BLOCKLIST},
constants::{CONTENT_TYPE_HEADER_LOWERCASE, CONTENT_TYPE_VALUE},
memory::is_demo_active,
types::{MetricRpcHost, MetricRpcMethod, ResolvedRpcService},
util::canonicalize_json,
Expand Down Expand Up @@ -69,14 +69,6 @@ pub async fn http_request(
}
};
let rpc_host = MetricRpcHost(host.to_string());
if SERVICE_HOSTS_BLOCKLIST.contains(&rpc_host.0.as_str()) {
add_metric_entry!(err_host_not_allowed, rpc_host.clone(), 1);
return Err(ValidationError::Custom(format!(
"Disallowed RPC service host: {}",
rpc_host.0
))
.into());
}
if !is_demo_active() {
let cycles_available = ic_cdk::api::call::msg_cycles_available128();
let cycles_cost_with_collateral = get_cost_with_collateral(cycles_cost);
Expand Down
5 changes: 0 additions & 5 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ pub fn encode_metrics(w: &mut ic_metrics_encoder::MetricsEncoder<Vec<u8>>) -> st
&m.err_http_outcall,
"Number of unsuccessful HTTP outcalls",
);
w.counter_entries(
"evmrpc_err_host_not_allowed",
&m.err_host_not_allowed,
"Number of HostNotAllowed errors",
);
w.encode_counter(
"evmrpc_err_no_permission",
m.err_no_permission.metric_value(),
Expand Down
2 changes: 0 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ pub struct Metrics {
pub err_no_permission: u64,
#[serde(rename = "errHttpOutcall")]
pub err_http_outcall: HashMap<(MetricRpcMethod, MetricRpcHost), u64>,
#[serde(rename = "errHostNotAllowed")]
pub err_host_not_allowed: HashMap<MetricRpcHost, u64>,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
39 changes: 1 addition & 38 deletions src/validate.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
use crate::{
constants::{SERVICE_HOSTS_BLOCKLIST, VALID_API_KEY_CHARS},
util::hostname_from_url,
};

pub fn validate_hostname(hostname: &str) -> Result<(), &'static str> {
if SERVICE_HOSTS_BLOCKLIST.contains(&hostname) {
Err("Hostname not allowed")
} else {
Ok(())
}
}

pub fn validate_url_pattern(url_pattern: &str) -> Result<(), &'static str> {
validate_hostname(&hostname_from_url(url_pattern).ok_or("Invalid hostname in URL")?)
}
use crate::constants::VALID_API_KEY_CHARS;

pub fn validate_api_key(api_key: &str) -> Result<(), &'static str> {
if api_key.is_empty() {
Expand All @@ -34,28 +19,6 @@ pub fn validate_api_key(api_key: &str) -> Result<(), &'static str> {
mod test {
use super::*;

#[test]
pub fn test_validate_url_pattern() {
assert_eq!(validate_url_pattern("https://example.com"), Ok(()));
assert_eq!(validate_url_pattern("https://example.com/v1/rpc"), Ok(()));
assert_eq!(
validate_url_pattern("https://example.com/{API_KEY}"),
Ok(())
);
assert_eq!(
validate_url_pattern("https://{API_KEY}"),
Err("Invalid hostname in URL")
);
assert_eq!(
validate_url_pattern("https://{API_KEY}/v1/rpc"),
Err("Invalid hostname in URL")
);
assert_eq!(
validate_url_pattern("https://{API_KEY}/{API_KEY}"),
Err("Invalid hostname in URL")
);
}

#[test]
pub fn test_validate_api_key() {
assert_eq!(validate_api_key("abc"), Ok(()));
Expand Down

0 comments on commit 2544848

Please sign in to comment.