foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Add support for blacklisted rpc endpoints

Open mattsse opened this issue 1 year ago • 6 comments

Component

Anvil

Describe the feature you would like

anvil's api is quite massive and some endpoints are considered "god mode"

there are usecases where these should be restricted.

this should be done on the rpc server level because this is how the server is exposed and the easiest solution here is:

  1. introduce a blacklist (HashSet of string) of certain endpoints in the config: https://github.com/foundry-rs/foundry/blob/e215f3fdeada259a8886a7611151794d280ca298/crates/anvil/server/src/config.rs#L8-L8
  2. if at least 1 blacklisted method, install another layer, similar to https://github.com/foundry-rs/foundry/blob/e215f3fdeada259a8886a7611151794d280ca298/crates/anvil/server/src/lib.rs#L76-L78

this layer should deserialize the request and reject disallowed methods, this is likely slightly inefficient but this deserialization overhead should be fine because we only need to check for method.

Additional context

No response

mattsse avatar Oct 07 '24 22:10 mattsse

Hi, I would like to give this one a try

teodorstupnicki avatar Oct 07 '24 22:10 teodorstupnicki

related https://github.com/foundry-rs/foundry/issues/8731

grandizzy avatar Oct 08 '24 07:10 grandizzy

@mattsse I have 2 questions:

  1. What do you think about this usage and command line format:
anvil --blacklist eth_sendTransaction,eth_sendRawTransaction

or is this one better:

anvil --blacklist eth_sendTransaction --blacklist eth_sendRawTransaction
  1. What should be the expected response for a blacklisted method call - just a regular "Method not found"?

teodorstupnicki avatar Oct 13 '24 23:10 teodorstupnicki

yeah method not found or method not whitelisted

mattsse avatar Oct 14 '24 09:10 mattsse

I'd also like to support some presets, like unsafe or something that by makes cli usage easier

mattsse avatar Oct 14 '24 09:10 mattsse

I'd also like to support some presets, like unsafe or something that by makes cli usage easier

@mattsse Could you elaborate on that? Maybe provide an example

teodorstupnicki avatar Oct 14 '24 10:10 teodorstupnicki

just to simplify tracking, going to dupe it in favor of https://github.com/foundry-rs/foundry/issues/8731 which is the same request

grandizzy avatar Nov 07 '24 13:11 grandizzy