Reject unknown fields in TxDecoder and sign mode handlers (#6883)
* WIP on unknown field rejection in TxDecoder * WIP on unknown field rejection in TxDecoder * WIP * WIP * WIP * WIP * Fix bugs with RejectUnknownFields * Fix tests * Fix bug and update docs * Lint * Add tests * Add unknown field tests * Lint * Address review comments
This commit is contained in:
@@ -6,22 +6,18 @@ a) Unknown fields in the stream -- this is indicative of mismatched services, pe
|
||||
|
||||
b) Mismatched wire types for a field -- this is indicative of mismatched services
|
||||
|
||||
Its API signature is similar to proto.Unmarshal([]byte, proto.Message) as
|
||||
Its API signature is similar to proto.Unmarshal([]byte, proto.Message) in the strict case
|
||||
|
||||
ckr := new(unknownproto.Checker)
|
||||
if err := ckr.RejectUnknownFields(protoBlob, protoMessage); err != nil {
|
||||
if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil {
|
||||
// Handle the error.
|
||||
}
|
||||
|
||||
and ideally should be added before invoking proto.Unmarshal, if you'd like to enforce the features mentioned above.
|
||||
|
||||
By default, for security we report every single field that's unknown, whether a non-critical field or not. To customize
|
||||
this behavior, please create a Checker and set the AllowUnknownNonCriticals to true, for example:
|
||||
this behavior, please set the boolean parameter allowUnknownNonCriticals to true to RejectUnknownFields:
|
||||
|
||||
ckr := &unknownproto.Checker{
|
||||
AllowUnknownNonCriticals: true,
|
||||
}
|
||||
if err := ckr.RejectUnknownFields(protoBlob, protoMessage); err != nil {
|
||||
if err := RejectUnknownFields(protoBlob, protoMessage, true); err != nil {
|
||||
// Handle the error.
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user