Skip to content

Commit

Permalink
fix: Return 5xx instead of 401 for missing ALB header
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthb committed Apr 9, 2024
1 parent 55379c4 commit 2718eff
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions asgard/heimdallr.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/google/uuid"
)

const errBadAuthHeader = "missing or invalid authorization information, server is misconfigured"

type keyClientCert struct{}

// ClientCert returns the client certificate from the request context.
Expand All @@ -41,7 +43,7 @@ func Heimdallr(h HeaderName, ns uuid.UUID) func(http.Handler) http.Handler {
certHeader := r.Header.Get(h.String())
if certHeader == "" {
slog.ErrorContext(ctx, "missing authorization header")
http.Error(w, "missing authorization header", http.StatusUnauthorized)
http.Error(w, errBadAuthHeader, http.StatusServiceUnavailable)
return
}

Expand All @@ -52,7 +54,7 @@ func Heimdallr(h HeaderName, ns uuid.UUID) func(http.Handler) http.Handler {
"headerName", h.String(),
"headerValue", certHeader,
)
http.Error(w, "invalid authorization header", http.StatusUnauthorized)
http.Error(w, errBadAuthHeader, http.StatusServiceUnavailable)
return
}

Expand All @@ -63,14 +65,14 @@ func Heimdallr(h HeaderName, ns uuid.UUID) func(http.Handler) http.Handler {
"headerName", h.String(),
"headerValue", certPEM,
)
http.Error(w, "invalid authorization header", http.StatusUnauthorized)
http.Error(w, errBadAuthHeader, http.StatusServiceUnavailable)
return
}

cert, err := bifrost.ParseCertificate(block.Bytes)
if err != nil {
slog.ErrorContext(ctx, "error parsing client certificate", "error", err)
http.Error(w, "invalid authorization header", http.StatusUnauthorized)
http.Error(w, errBadAuthHeader, http.StatusServiceUnavailable)
return
}

Expand Down

0 comments on commit 2718eff

Please sign in to comment.