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

feat(protobuf): added error wrappers for invalid length validation #1563

Merged
merged 1 commit into from
Feb 20, 2023

Conversation

LNSD
Copy link
Contributor

@LNSD LNSD commented Feb 15, 2023

Context

At this moment, no protobuf max field length validation is performed. In 14/WAKU2-MESSAGE RFC, no maximum length for the content_topic attribute is specified. This is potentially problematic. Additionally, this is not supported by libp2p's minprotobuf implementation.

This requirement motivates the present PR to add support in the common/protobuf wrapper module for validating the protobuf field length.

Acceptance criteria

  • Added a maximum content_topic attribute length: 128 bytes (128 ASCII chars).
  • Added new wrapper result and error types to the minprotobuf's ProtoError. Added some error details for better debugging.
  • Updated the different protocols codec modules with the new result type.

Other Considerations

Note that the validation is only executed during the deserialization phase. The content topic length is assumed to be valid in the serialisation phase.

Initially, the minprotobuf's getRequirefField was also considered. But as there isn't a max length validation equivalent, for homogeneity, I discarded its usage and added also the "required field missing" error variant.

@LNSD LNSD added the invalid This doesn't seem right label Feb 15, 2023
@LNSD LNSD added track:production and removed invalid This doesn't seem right labels Feb 15, 2023
@LNSD LNSD self-assigned this Feb 15, 2023
Copy link
Contributor

@rymnc rymnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will create a tracking issue to use the new error in rln-relay's protobuf decoding too.

Maybe the RFC should include the 128 byte size constraint on content_topic?

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, left some minor comments.

mind adding some testcases? at least something basic testing this new MaxTopicAttributeLength check?

waku/v2/protocol/waku_message/message.nim Outdated Show resolved Hide resolved
waku/v2/protocol/waku_store/rpc_codec.nim Outdated Show resolved Hide resolved
@LNSD
Copy link
Contributor Author

LNSD commented Feb 16, 2023

Maybe the RFC should include the 128 byte size constraint on content_topic?

Honestly, I don't know if we should. IIRC Gossipsub RFC does not specify a maximum topic length; hence it is up to the implementations to set limits. I see here the same kind of situation. Wdyt?

@rymnc
Copy link
Contributor

rymnc commented Feb 16, 2023

Maybe the RFC should include the 128 byte size constraint on content_topic?

Honestly, I don't know if we should. IIRC Gossipsub RFC does not specify a maximum topic length; hence it is up to the implementations to set limits. I see here the same kind of situation. Wdyt?

Works either way, maybe this is better noted in a "Recommendations" section

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the RFC should include the 128 byte size constraint on content_topic?

I would say whatever can create an incompatibility issue should be added to the spec. I mean, if one implementation has that 128bytes limit and another doesn't, a message sent with a content_topic longer than 128byte, may not be routed by the second implementation (depending on how we do message validation).

regarding the PR, lgtm!

@@ -0,0 +1,103 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. I actually was thinkinig about testing the encode, decode functions of the protos that were changed, like PagingInfoRPC.

A simple back and forth converstion like this to assert that encode()/decode() work as expected and protect the code from future modifications. Also, test this extra logic if topic.len > MaxPubsubTopicLen: trying to encode eg a FilterRequest with a longer topic, and asserting it fails.

But we can leave that for another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ofc testing all encode/decode functions would be a long PR) beyond this, but perhaps we are lacking some testing in protos in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ofc testing all encode/decode functions would be a long PR) beyond this, but perhaps we are lacking some testing in protos in general?

Protocol-specific protobuf tests can be found in the different protocol folders (see the tests/v2/waku_store module). Additionally, the different protocols' integration/end-to-end tests implicitly test protocol RPC serialisation.

I don't see the need to add test suites for unit testing/covering specifically the RPC serialization of the different protocols. If we had to add tests to cover this area: Interoperability tests (a.k.a integration-tests) would be the ones providing additional value.

@LNSD
Copy link
Contributor Author

LNSD commented Feb 20, 2023

@jm-clius Looking forward to your feedback on the size limit of the topic and if we should specify it as part of the 14/WAKU2-MESSAGE RFC 😁

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Since these can introduce incompatibilities/breaking change in how the protocol is used, it should be part of an RFC and agreed upon before merging, especially since we don't know how this will affect current applications. My suggestion is https://rfc.vac.dev/spec/23/ as recommendations (i.e. the pubsubTopic SHOULD be less than 128 characters. Individual Waku nodes MAY choose to discard messages that does not adhere to....). To get this PR merged, unstaging the changes specific to max topic length and leaving that for a next PR (after RFC agreement) will work. 👍

@LNSD
Copy link
Contributor Author

LNSD commented Feb 20, 2023

To get this PR merged, unstaging the changes specific to max topic length and leaving that for a next PR (after RFC agreement) will work.

I have split the different codecs' topic length validation changes into a separate commit. Waiting for re-review/approval. cc @jm-clius @alrevuelta @rymnc

I will open the "max topic length recommendation" RFC PR with the split-out changes after this PR gets merged.


EDIT:

JFYI, you can review the removed portion of code by clicking here:
image

Copy link
Contributor

@rymnc rymnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +15 to +16
const
MaxWakuMessageSize* = 1024 * 1024 # 1 Mibytes. Corresponds to PubSub default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const
MaxWakuMessageSize* = 1024 * 1024 # 1 Mibytes. Corresponds to PubSub default
const MaxWakuMessageSize* = 1024 * 1024 # 1 Mibytes. Corresponds to PubSub default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I plan to restore the max topic length constants, I opted not to restore the single line const :)

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@LNSD LNSD merged commit f7584df into master Feb 20, 2023
@LNSD LNSD deleted the feat-common-protobuf branch February 20, 2023 14:03
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

Successfully merging this pull request may close these issues.

4 participants