Skip to content

Commit cc7645a

Browse files
ptoneScion Agent (msg-cleanups-lead)
andauthored
Tighten web channel default to actual web clients only (#448)
Only set channel="web" when the authenticated user's ClientType is "web", not for CLI or API callers hitting the same endpoint. Also update stale doc-comment on the stream handler. Co-authored-by: Scion Agent (msg-cleanups-lead) <agent@scion.dev>
1 parent 9e59488 commit cc7645a

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

pkg/hub/handlers.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,8 +2575,14 @@ func (s *Server) handleAgentMessage(w http.ResponseWriter, r *http.Request, id s
25752575
structuredMsg.RecipientID = agent.ID
25762576

25772577
// Default the channel to "web" for messages sent through the web UI.
2578-
if structuredMsg.Channel == "" && GetUserIdentityFromContext(ctx) != nil {
2579-
structuredMsg.Channel = "web"
2578+
// Only tag as "web" when the authenticated user's client type is
2579+
// actually "web" — CLI and API callers should not be tagged.
2580+
if structuredMsg.Channel == "" {
2581+
if user := GetUserIdentityFromContext(ctx); user != nil {
2582+
if au, ok := user.(*AuthenticatedUser); ok && au.ClientType() == "web" {
2583+
structuredMsg.Channel = "web"
2584+
}
2585+
}
25802586
}
25812587

25822588
if !s.checkBrokerAvailability(w, r, agent) {

pkg/hub/handlers_messages.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ func (s *Server) handleAgentMessages(w http.ResponseWriter, r *http.Request, age
210210
}
211211

212212
// handleAgentMessagesStream handles GET /api/v1/agents/{id}/messages/stream.
213-
// Streams new messages involving a specific agent in real time, scoped to
214-
// the conversation between the current authenticated user and the agent.
213+
// Streams new messages involving a specific agent in real time. Users who
214+
// can manage the agent see all messages; others see only their own.
215215
// Unlike /message-logs/stream this does not depend on Cloud Logging: it
216216
// subscribes to the in-process event bus that handleAgentOutboundMessage
217217
// and handleAgentMessage already publish to, so it works on any hub

0 commit comments

Comments
 (0)