Change 404 errors for aliases to 401s (#4575)

* Change 404 errors for alias resolution to 401s
---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
ToddandJohan Brandhorst-Satzkorn authored and GitHub committed 2024-03-27 16:14:49 -07:00
1 parent 8533433868
commit 55fe70e643
3 files changed
+42 -12

No files matched your search

+11 -3
View File
@@ -335,10 +335,9 @@ func errorInterceptor(
// For an field in the request to be considered for alias resolution, it must
// be annotated with the Aliasable proto option.
func aliasResolutionInterceptor(
ctx context.Context,
_ context.Context,
aliasRepoFn common.AliasRepoFactory,
) grpc.UnaryServerInterceptor {
const op = "alias.ResolutionInterceptor"
return func(interceptorCtx context.Context,
req any,
_ *grpc.UnaryServerInfo,
@@ -355,7 +354,16 @@ func aliasResolutionInterceptor(
}
interceptorCtx, err = alias.ResolveRequestIds(interceptorCtx, reqMsg, r)
if err != nil {
return nil, err
// Since this is intercepted prior to checking that the requester
// is authorized to make the request, returning a 404 here and a 401
// when the request is checked in the handler would expose which
// aliases exist. Instead, we return a unauthenticated error here so there
// is no way to distinguish between a missing alias and an existing
// alias that points to a destination the requester is not allowed
// to perform an action on.
// handlers.UnauthenticatedError() turns into an http 401 status
// code "Unauthorized".
return nil, handlers.UnauthenticatedError()
}
return handler(interceptorCtx, req)
}