From 25448482789f7a6c68ed635e243cbb6ce9f8c1d5 Mon Sep 17 00:00:00 2001 From: gregorydemay Date: Thu, 28 Nov 2024 10:43:54 +0100 Subject: [PATCH] XC-246: remove errHostNotAllowed --- candid/evm_rpc.did | 1 - src/constants.rs | 2 -- src/http.rs | 10 +--------- src/metrics.rs | 5 ----- src/types.rs | 2 -- src/validate.rs | 39 +-------------------------------------- 6 files changed, 2 insertions(+), 57 deletions(-) diff --git a/candid/evm_rpc.did b/candid/evm_rpc.did index d6102d37..0cae6a0a 100644 --- a/candid/evm_rpc.did +++ b/candid/evm_rpc.did @@ -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; diff --git a/src/constants.rs b/src/constants.rs index 53e5af8b..be854088 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -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] = &[]; diff --git a/src/http.rs b/src/http.rs index 23f10a9f..abb4701e 100644 --- a/src/http.rs +++ b/src/http.rs @@ -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, @@ -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); diff --git a/src/metrics.rs b/src/metrics.rs index 33c7823b..20e62ad4 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -104,11 +104,6 @@ pub fn encode_metrics(w: &mut ic_metrics_encoder::MetricsEncoder>) -> 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(), diff --git a/src/types.rs b/src/types.rs index 2a133bd5..e32e1324 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/src/validate.rs b/src/validate.rs index 846ff36a..1687358e 100644 --- a/src/validate.rs +++ b/src/validate.rs @@ -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() { @@ -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(()));