refactor(middleware): emit OIDC blocked event at specific error points

This commit is contained in:
yusing
2026-02-15 20:04:12 +08:00
parent af62ac98d3
commit fbb8a1fca4

View File

@@ -119,8 +119,10 @@ func (amw *oidcMiddleware) before(w http.ResponseWriter, r *http.Request) (proce
return true return true
} }
if r.Method != http.MethodHead { emitBlockedEvent := func() {
defer httpevents.Blocked(r, "OIDC", err.Error()) if r.Method != http.MethodHead {
httpevents.Blocked(r, "OIDC", err.Error())
}
} }
isGet := r.Method == http.MethodGet isGet := r.Method == http.MethodGet
@@ -135,11 +137,13 @@ func (amw *oidcMiddleware) before(w http.ResponseWriter, r *http.Request) (proce
reqType = "WebSocket" reqType = "WebSocket"
} }
OIDC.LogWarn(r).Msgf("[OIDC] %s request blocked.\nConsider adding bypass rule for this path if needed", reqType) OIDC.LogWarn(r).Msgf("[OIDC] %s request blocked.\nConsider adding bypass rule for this path if needed", reqType)
emitBlockedEvent()
return false return false
case errors.Is(err, auth.ErrMissingOAuthToken): case errors.Is(err, auth.ErrMissingOAuthToken):
amw.auth.HandleAuth(w, r) amw.auth.HandleAuth(w, r)
default: default:
auth.WriteBlockPage(w, http.StatusForbidden, err.Error(), "Logout", auth.OIDCLogoutPath) auth.WriteBlockPage(w, http.StatusForbidden, err.Error(), "Logout", auth.OIDCLogoutPath)
emitBlockedEvent()
} }
return false return false
} }