Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func (cm *ConsumerManager) createConsumer(groupID string, topics []string, callb
}

// consumerGroupID generates a unique, safe consumer group ID for a callback URL.
// Format: {prefix}-websub-{sha256(callbackURL)[:16]}
// Format: {prefix}-websub-{sha256(callbackURL)[:32]}
func (cm *ConsumerManager) consumerGroupID(callbackURL string) string {
h := sha256.Sum256([]byte(callbackURL))
return cm.groupPrefix + "-websub-" + hex.EncodeToString(h[:])[:16]
return cm.groupPrefix + "-websub-" + hex.EncodeToString(h[:])[:32]
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ func (h *HubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (h *HubHandler) handleSubscribe(w http.ResponseWriter, r *http.Request) {
// Enforce subscribe policies before processing.
subMsg := httpRequestToMessage(r)
message, shortCircuited, err := h.processor.ProcessSubscribe(r.Context(), h.bindingName, subMsg)
_, shortCircuited, err := h.processor.ProcessSubscribe(r.Context(), h.bindingName, subMsg)
if err != nil {
slog.Error("Subscribe policy execution failed", "error", err)
http.Error(w, "policy execution failed", http.StatusInternalServerError)
return
}
if shortCircuited {
writePolicyResponse(w, message, http.StatusForbidden, "forbidden by policy")
writePolicyResponse(w, nil, http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized))
return
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Expand Down Expand Up @@ -203,14 +203,14 @@ func (h *HubHandler) handleSubscribe(w http.ResponseWriter, r *http.Request) {
func (h *HubHandler) handleUnsubscribe(w http.ResponseWriter, r *http.Request) {
// Enforce subscribe policies before processing.
subMsg := httpRequestToMessage(r)
message, shortCircuited, err := h.processor.ProcessSubscribe(r.Context(), h.bindingName, subMsg)
_, shortCircuited, err := h.processor.ProcessSubscribe(r.Context(), h.bindingName, subMsg)
if err != nil {
slog.Error("Unsubscribe policy execution failed", "error", err)
http.Error(w, "policy execution failed", http.StatusInternalServerError)
return
}
if shortCircuited {
writePolicyResponse(w, message, http.StatusForbidden, "forbidden by policy")
writePolicyResponse(w, nil, http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized))
return
}

Expand Down Expand Up @@ -342,7 +342,7 @@ func (h *WebhookReceiverHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
}
if shortCircuited {
slog.Info("Inbound request rejected by policy", "channel", channelName, "binding", h.bindingName)
writePolicyResponse(w, processed, http.StatusForbidden, "forbidden by policy")
writePolicyResponse(w, processed, http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized))
return
}

Expand Down Expand Up @@ -379,6 +379,9 @@ func writePolicyResponse(w http.ResponseWriter, msg *connectors.Message, fallbac
w.WriteHeader(statusCode)
return
}
if fallbackStatus == http.StatusUnauthorized {
w.Header().Set("WWW-Authenticate", `Bearer realm="event-gateway"`)
}
http.Error(w, fallbackBody, fallbackStatus)
}

Expand Down