Skip to content

Commit

Permalink
fix: Initialize LoggingMiddleware after ContextMiddleware to ensure i…
Browse files Browse the repository at this point in the history
…t is populated for log generation (#323)
  • Loading branch information
juggernot325 authored Jan 17, 2024
1 parent b3a81f1 commit 95df8a4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cmd/api/src/api/registration/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package registration

import (
"net/http"

"github.com/specterops/bloodhound/cache"
"github.com/specterops/bloodhound/dawgs/graph"
"github.com/specterops/bloodhound/src/api"
Expand All @@ -28,19 +30,18 @@ import (
"github.com/specterops/bloodhound/src/config"
"github.com/specterops/bloodhound/src/daemons/datapipe"
"github.com/specterops/bloodhound/src/database"
"net/http"
)

func RegisterFossGlobalMiddleware(routerInst *router.Router, cfg config.Configuration, identityResolver auth.IdentityResolver, authenticator api.Authenticator) {
// Set up logging
if cfg.EnableAPILogging {
routerInst.UsePrerouting(middleware.LoggingMiddleware(cfg, identityResolver))
}

// Set up the middleware stack
routerInst.UsePrerouting(middleware.ContextMiddleware)
routerInst.UsePrerouting(middleware.CORSMiddleware())

// Set up logging. This must be done after ContextMiddleware is initialized so the context can be accessed in the log logic
if cfg.EnableAPILogging {
routerInst.UsePrerouting(middleware.LoggingMiddleware(cfg, identityResolver))
}

routerInst.UsePostrouting(
middleware.PanicHandler,
middleware.AuthMiddleware(authenticator),
Expand Down

0 comments on commit 95df8a4

Please sign in to comment.