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

Panicky, non-validating conversions involving protobuf types and/or domain types #1037

Open
8 tasks
mzabaluev opened this issue Nov 30, 2021 · 3 comments
Open
8 tasks
Labels
bug Something isn't working code-quality Issues relating to linting configuration and general code quality domain-types Anything relating to the creation, modification or removal of domain types rpc security

Comments

@mzabaluev
Copy link
Contributor

mzabaluev commented Nov 30, 2021

After #1022 has landed, there is a number of conversions between protobuf types and so-called domain types that do not validate their input, are prone to panic when the input does not conform to expectations on the destination value, or produce a protobuf message struct value that falls afoul of the specification on well-known protobuf types.

Here's why this is problematic for protobuf ⭢ domain type:
As the most likely origin of protobuf DTO values is by having been parsed from an incoming message by prost without any validation as to its contents, this is an easy DoS bomb under application developers who would make use of these conversions. Please consider using fallible conversions when dealing with untrusted values originating from the network.

Here's why this is problematic for domain type ⭢ protobuf:
Aside from the low-level tendermint-proto crate, tendermint-rs should never produce protocol messages that do not comply with the specification. The alternative of panicking makes for poor API usability. The tendermint API should provide true domain types where the From-type conversion to their protobuf DTOs is a total function always resulting in valid messages.

List of problematic conversions

The list of identified conversions that exhibit the problems described above, along with the PR addressing them:

Homespun domain types

Domain types to be provided in tendermint for lack of a suitable alternative:

Originally posted by @mzabaluev in #1030 (comment)

@mzabaluev mzabaluev added bug Something isn't working code-quality Issues relating to linting configuration and general code quality domain-types Anything relating to the creation, modification or removal of domain types rpc security labels Nov 30, 2021
@tony-iqlusion
Copy link
Collaborator

tony-iqlusion commented Nov 30, 2021

FWIW, in cosmrs I used a trait with an associated type to enforce conversion bounds between "domain types" and their associated prost-generated protobufs:

https://docs.rs/cosmrs/0.3.0/cosmrs/tx/trait.Msg.html

pub trait Msg: Clone + Sized + TryFrom<Self::Proto, Error = ErrorReport> + Into<Self::Proto> {
    type Proto: MsgProto;
    [...]
}

This is somewhat specialized to the tx.Msg use case, but with the elided portion aside it works for any "domain type" with an associated protobuf type.

The bounds ensure that there's always a TryFrom conversion available from the associated Protobuf type, as well as an Into conversion to convert to the domain type.

I think it'd be great if there were a trait in tendermint-rs that wrapped up this pattern which we could build on in cosmrs.

@thanethomson
Copy link
Contributor

Would the approach outlined in #661 be of use here?

@mzabaluev
Copy link
Contributor Author

Would the approach outlined in #661 be of use here?

Yes, essentially this issue is tracking transgressions against that approach.

@mzabaluev mzabaluev changed the title Panicky, non-validating conversions from/to protobuf types Panicky, non-validating conversions involving protobuf types and/or domain types Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code-quality Issues relating to linting configuration and general code quality domain-types Anything relating to the creation, modification or removal of domain types rpc security
Projects
None yet
Development

No branches or pull requests

3 participants