mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
fix: potential panics in login and return proper http 405 (#8065)
# Which Problems Are Solved We identified some parts in the code, which could panic with a nil pointer when accessed without auth request. Additionally, if a GRPC method was called with an unmapped HTTP method, e.g. POST instead of GET a 501 instead of a 405 was returned. # How the Problems Are Solved - Additional checks for existing authRequest - custom http status code mapper for gateway # Additional Changes None. # Additional Context - noted internally in OPS
This commit is contained in:
@@ -10,9 +10,11 @@ import (
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/zitadel/logging"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
@@ -36,6 +38,23 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
httpErrorHandler = runtime.RoutingErrorHandlerFunc(
|
||||
func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, httpStatus int) {
|
||||
if httpStatus != http.StatusMethodNotAllowed {
|
||||
runtime.DefaultRoutingErrorHandler(ctx, mux, marshaler, w, r, httpStatus)
|
||||
return
|
||||
}
|
||||
|
||||
// Use HTTPStatusError to customize the DefaultHTTPErrorHandler status code
|
||||
err := &runtime.HTTPStatusError{
|
||||
HTTPStatus: httpStatus,
|
||||
Err: status.Error(codes.Unimplemented, http.StatusText(httpStatus)),
|
||||
}
|
||||
|
||||
runtime.DefaultHTTPErrorHandler(ctx, mux, marshaler, w, r, err)
|
||||
},
|
||||
)
|
||||
|
||||
serveMuxOptions = []runtime.ServeMuxOption{
|
||||
runtime.WithMarshalerOption(jsonMarshaler.ContentType(nil), jsonMarshaler),
|
||||
runtime.WithMarshalerOption(mimeWildcard, jsonMarshaler),
|
||||
@@ -43,6 +62,7 @@ var (
|
||||
runtime.WithIncomingHeaderMatcher(headerMatcher),
|
||||
runtime.WithOutgoingHeaderMatcher(runtime.DefaultHeaderMatcher),
|
||||
runtime.WithForwardResponseOption(responseForwarder),
|
||||
runtime.WithRoutingErrorHandler(httpErrorHandler),
|
||||
}
|
||||
|
||||
headerMatcher = runtime.HeaderMatcherFunc(
|
||||
|
Reference in New Issue
Block a user