From 89a66283fee0255ba90136c9c9cf9e26bcecb58b Mon Sep 17 00:00:00 2001 From: Shashank Date: Wed, 10 Dec 2025 20:11:32 +0530 Subject: [PATCH 1/5] fix --- src/rpc/mod.rs | 12 +++++++++++- src/rpc/reflect/mod.rs | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index c02678ae30bf..38bf0b777e99 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -585,7 +585,17 @@ where let filter_list = filter_list.clone(); move |req| { let is_websocket = jsonrpsee::server::ws::is_upgrade_request(&req); - let path = ApiPaths::from_uri(req.uri()).unwrap_or(ApiPaths::V1); + let path = if let Ok(p) = ApiPaths::from_uri(req.uri()) { + p + } else { + return async move { + Ok(http::Response::builder() + .status(http::StatusCode::NOT_FOUND) + .body(Default::default()) + .unwrap_or_else(|_| http::Response::new(Default::default()))) + } + .boxed(); + }; let methods = methods.get(&path).cloned().unwrap_or_default(); let PerConnection { stop_handle, diff --git a/src/rpc/reflect/mod.rs b/src/rpc/reflect/mod.rs index 693cd797d79e..940f79f768b8 100644 --- a/src/rpc/reflect/mod.rs +++ b/src/rpc/reflect/mod.rs @@ -159,7 +159,7 @@ impl ApiPaths { pub fn from_uri(uri: &Uri) -> anyhow::Result { Ok(Self::from_str( - uri.path().split("/").last().expect("infallible"), + uri.path().split("rpc/").last().expect("infallible"), )?) } From 7ab7d9d857b9a4102ad2264df30cd9557915e112 Mon Sep 17 00:00:00 2001 From: Shashank Date: Wed, 10 Dec 2025 20:27:33 +0530 Subject: [PATCH 2/5] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67790329ead6..aee3dab18f76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ ### Fixed +- [#6327](https://github.com/ChainSafe/forest/pull/6327) Fixed: Forest returns 404 for all invalid api paths. + ## Forest v0.30.4 "DeLorean" This is a non-mandatory release that fixes a chain sync issue that is caused by time traveling block(s). From 71d9bfb24564a34b8f15e4296c57515eee4639a3 Mon Sep 17 00:00:00 2001 From: Shashank Date: Thu, 11 Dec 2025 13:30:01 +0530 Subject: [PATCH 3/5] fix from_uri for ApiPaths --- src/rpc/reflect/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rpc/reflect/mod.rs b/src/rpc/reflect/mod.rs index 940f79f768b8..db6a5f454c55 100644 --- a/src/rpc/reflect/mod.rs +++ b/src/rpc/reflect/mod.rs @@ -158,9 +158,7 @@ impl ApiPaths { } pub fn from_uri(uri: &Uri) -> anyhow::Result { - Ok(Self::from_str( - uri.path().split("rpc/").last().expect("infallible"), - )?) + Ok(Self::from_str(uri.path().trim_start_matches("/rpc/"))?) } pub fn path(&self) -> &'static str { From 4987fb4ab1fb81218399dab3101c42e8908a74e1 Mon Sep 17 00:00:00 2001 From: Shashank Date: Thu, 11 Dec 2025 15:05:29 +0530 Subject: [PATCH 4/5] Add test --- scripts/tests/calibnet_other_check.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/tests/calibnet_other_check.sh b/scripts/tests/calibnet_other_check.sh index bc4e97427b05..9a7b3dc0a492 100755 --- a/scripts/tests/calibnet_other_check.sh +++ b/scripts/tests/calibnet_other_check.sh @@ -97,6 +97,15 @@ if [ "$session" == "" ]; then exit 1 fi +# Assert invalid RPC path returns HTTP 404 +echo "Testing invalid RPC path handling" +invalid_path_response=$(curl -s -X POST http://localhost:2345/rpc/v3 -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"Filecoin.Version","id":1}') +status_code=$(echo "$invalid_path_response" | jq -r '.status') +if [ "$status_code" != "404" ]; then + echo "Unexpected status code for invalid RPC path: $status_code" + exit 1 +fi + # Assert unsupported method returns HTTP 200 but RPC error code -32601 echo "Testing unsupported RPC method handling" unsupported_response=$(curl -s -X POST http://localhost:2345/rpc/v1 -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"Invoke.Cthulhu","params":[],"id":1}') From 0010702fa5f7dcf898cb52aa5c7faa59dbb3add5 Mon Sep 17 00:00:00 2001 From: Shashank Date: Thu, 11 Dec 2025 15:46:22 +0530 Subject: [PATCH 5/5] fix test --- scripts/tests/calibnet_other_check.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/tests/calibnet_other_check.sh b/scripts/tests/calibnet_other_check.sh index 9a7b3dc0a492..ccaf1ac68b79 100755 --- a/scripts/tests/calibnet_other_check.sh +++ b/scripts/tests/calibnet_other_check.sh @@ -97,10 +97,9 @@ if [ "$session" == "" ]; then exit 1 fi -# Assert invalid RPC path returns HTTP 404 -echo "Testing invalid RPC path handling" -invalid_path_response=$(curl -s -X POST http://localhost:2345/rpc/v3 -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"Filecoin.Version","id":1}') -status_code=$(echo "$invalid_path_response" | jq -r '.status') +# Assert invalid API path returns HTTP 404 +echo "Testing invalid API path handling" +status_code=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://localhost:2345/rpc/v3 -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"Filecoin.Version","id":1}') if [ "$status_code" != "404" ]; then echo "Unexpected status code for invalid RPC path: $status_code" exit 1