Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC request params validation #166

Open
shunsukew opened this issue Apr 24, 2024 · 2 comments
Open

RPC request params validation #166

shunsukew opened this issue Apr 24, 2024 · 2 comments

Comments

@shunsukew
Copy link
Contributor

shunsukew commented Apr 24, 2024

Some RPC methods body params should be validated before reaching backend nodes.
One use-case we can come up with is block range, it would be nice if we could validate and return an error if requested block ranges exceed the configured number allowed.

Possible ideas are

  • using the name validate middleware for future extendability and rename existing validate middleware to debug for example.
  • building another middleware called block_range
@xlc
Copy link
Member

xlc commented Apr 24, 2024

can you provide some specific examples? an example config that you would like to be able to use

@shunsukew
Copy link
Contributor Author

shunsukew commented Apr 24, 2024

The most simple case is configuring in yaml to set block range number for Filter type.
I think block range validation should be applicable to ty: Filter (which doesn't exist at this moment).
And checking param type and its values inside block_range middleware.

- method: eth_newFilter
    cache:
      size: 0
    params:
      - name: Filter
        ty: Filter
        range: 1000
pub struct BlockRangeMiddleware {
    range: u64,
    index: usize,
}

Another possible option is using an extension. All validation rules are defined there.

pub struct ValidationConfig {
    pub max_block_range: Option<u64>,
    pub max_call_data_size: Option<usize>,
}

and set config in yaml like

params
- method: eth_getLogs
    cache:
      size: 0
    validate:
        block_range: 1000
    params:
      - name: Filter
        ty: Bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants