Skip to content

Commit 15fc586

Browse files
committed
fix: add propper error message if someone sends only parts of a google.protobuf.Any message
1 parent 1f0ec43 commit 15fc586

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

runtime/fieldmask.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*field_mask.Field
6363
continue
6464
}
6565

66-
if isProtobufAnyType(fd.Message()) {
67-
queue = append(queue, fieldMaskPathItem{path: k})
68-
continue
66+
if isProtobufAnyMessage(fd.Message()) {
67+
_, hasTypeField := v.(map[string]interface{})["@type"]
68+
if hasTypeField {
69+
queue = append(queue, fieldMaskPathItem{path: k})
70+
continue
71+
} else {
72+
return nil, fmt.Errorf("could not find field @type in %q in message %q", k, item.msg.Descriptor().FullName())
73+
}
74+
6975
}
7076

7177
child := fieldMaskPathItem{
@@ -102,7 +108,7 @@ func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*field_mask.Field
102108
return fm, nil
103109
}
104110

105-
func isProtobufAnyType(md protoreflect.MessageDescriptor) bool {
111+
func isProtobufAnyMessage(md protoreflect.MessageDescriptor) bool {
106112
return md != nil && (md.FullName() == "google.protobuf.Any")
107113
}
108114

0 commit comments

Comments
 (0)