Repository navigation
This point release addresses a potential issue identified here: GHSA-gw5g-6mrm-5rmj
While fixing this issue, a number of other bugs were identified and fixed at the same time.
"github.com/jhump/protoreflect/v2/protoresolve/remotereg"
Changes/fixes:
- If the types fetched from the server resulted in files with an import cycle,
Registrywould recurse forever and the calling program would terminate with a "stack overflow" fatal error. This could happen with legitimate schemas if the server didn't provide source context/filenames, since mutually recursive types would each get their own file, resulting in an import cycle. Such types are now put into the same synthesized file, and any explicit import cycle (when the server does provide file names) is reported as an error. - The number of types that may be reachable from a single requested type is now limited, to 1500 by default. Previously, a malicious server could serve an endless chain of types, causing the client to fetch forever. Even very large real-world schemas have fewer than about 1200 types reachable from any one type, so this limit should not be reached in practice. But if you do have a schema that exceeds it, you can raise it with the new
MaxReachableTypesfield (see below). - Previously, the name of a fetched type was not checked. A type's name must now be a valid fully-qualified name, and it must match the name in the URL from which the type was fetched. Similarly,
DescriptorConverter.ToMessageDescriptorandToEnumDescriptornow return an error if the given type has an invalid name. - Previously, nested types that did not indicate their file (server did not provide a source context and file name) could fail to resolve, with an error about a name conflict between a package and a message. Nested types are now put into the same file as their enclosing type.
- If a requested type exists but refers to another type that cannot be found, the returned error now identifies the missing type and the field that refers to it. This error no longer matches
protoregistry.NotFoundwhen checked witherrors.Is, sinceNotFoundmeans that the requested type itself is unknown. (Requesting a type that is unknown still returns exactlyprotoregistry.NotFound.) - Previously, resolving a type that referred to an already-cached message could fail with a "cannot resolve type" error if the cached message had a nested message that referred to other types. Resolving a type that referred to already-cached types could also intermittently fail with a "missing dependency" error, if those cached types did not indicate their file. Both have been fixed.
DescriptorConverter.ToServiceDescriptorno longer drops nested types from request and response messages that are already in theRegistry.
Additions:
- Adds a
MaxReachableTypesfield toRegistry, to override the new limit on the number of types reachable from a single requested type. This is only needed if your schema is large enough to exceed the new default limit of 1500 (see above). It can also be used to shrink the limit, so that a potentially abusive schema can be identified and fail faster (for cases where you know the schema is smaller and less complex).