Skip to content

Commit

Permalink
Merge branch 'tiago/restrict-ascii-router-paths' (#2447)
Browse files Browse the repository at this point in the history
* tiago/restrict-ascii-router-paths:
  changelog: add #2447
  Test router request handling with non-ascii paths
  Restrict router queries to ascii paths
  • Loading branch information
tzemanovic committed Jan 25, 2024
2 parents cc6e682 + 2b6bac7 commit 055ae9a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Restricted RPC router paths to ASCII characters to prevent crashes.
([\#2447](https://github.com/anoma/namada/pull/2447))
23 changes: 22 additions & 1 deletion crates/sdk/src/queries/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,29 @@ mod test {
let result = TEST_RPC.handle(ctx, &request);
assert!(result.is_err());

// Test requests to valid paths using the router's methods
// Test request with a non-ascii path
let request = RequestQuery {
path: "ÀÁõö÷øùúûüýþÿ".to_owned(),
data: Default::default(),
height: block::Height::from(0_u32),
prove: Default::default(),
};
let ctx = RequestCtx {
event_log: &client.event_log,
wl_storage: &client.wl_storage,
vp_wasm_cache: (),
tx_wasm_cache: (),
storage_read_past_height_limit: None,
};
let result = TEST_RPC.handle(ctx, &request);
assert!(matches!(
result,
Err(namada_storage::Error::SimpleMessage(
"Non-ascii request paths are unsupported",
))
));

// Test requests to valid paths using the router's methods
let result = TEST_RPC.a(&client).await.unwrap();
assert_eq!(result, "a");

Expand Down
5 changes: 5 additions & 0 deletions crates/sdk/src/queries/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ pub trait Router {
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
{
if !request.path.is_ascii() {
return Err(namada_storage::Error::SimpleMessage(
"Non-ascii request paths are unsupported",
));
}
self.internal_handle(ctx, request, 0)
}

Expand Down

0 comments on commit 055ae9a

Please sign in to comment.