Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

### Fixed

- [#6327](https://github.com/ChainSafe/forest/pull/6327) Fixed: Forest returns 404 for all invalid api paths.

## Forest v0.30.5 "Dulce de Leche"

Non-mandatory release supporting new API methods and addressing a critical panic issue.
Expand Down
8 changes: 8 additions & 0 deletions scripts/tests/calibnet_other_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ if [ "$session" == "" ]; then
exit 1
fi

# 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
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}')
Expand Down
12 changes: 11 additions & 1 deletion src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,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,
Expand Down
4 changes: 1 addition & 3 deletions src/rpc/reflect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ impl ApiPaths {
}

pub fn from_uri(uri: &Uri) -> anyhow::Result<Self> {
Ok(Self::from_str(
uri.path().split("/").last().expect("infallible"),
)?)
Ok(Self::from_str(uri.path().trim_start_matches("/rpc/"))?)
}

pub fn path(&self) -> &'static str {
Expand Down
Loading