summaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-02-14 14:46:48 -0800
committerbndw <ben@bdw.to>2026-02-14 14:46:48 -0800
commit9ee32a917b13ffb3f52ddbc3a0c72dd8ec71953c (patch)
tree142c4452716d933324f6e0abff079529251ed693 /internal
parent212154fc29e3631d13cf7af9a0a3046c9683173b (diff)
fix: silently wait for auth instead of sending NOTICE
After sending AUTH challenge, return nil instead of error to avoid sending NOTICE messages to clients. Add explicit checks in handleEvent and handleReq to silently ignore requests when auth is required but client hasn't authenticated yet. This follows NIP-42 spec more closely.
Diffstat (limited to 'internal')
-rw-r--r--internal/handler/websocket/handler.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go
index c8fb6cc..581c434 100644
--- a/internal/handler/websocket/handler.go
+++ b/internal/handler/websocket/handler.go
@@ -177,7 +177,7 @@ func (h *Handler) requireAuth(ctx context.Context, conn *websocket.Conn, isWrite
177 *authChallenge = challenge 177 *authChallenge = challenge
178 h.sendAuthChallenge(ctx, conn, challenge) 178 h.sendAuthChallenge(ctx, conn, challenge)
179 } 179 }
180 return fmt.Errorf("restricted: authentication required") 180 return nil
181 } 181 }
182 182
183 if len(allowedPubkeys) > 0 { 183 if len(allowedPubkeys) > 0 {
@@ -205,6 +205,10 @@ func (h *Handler) handleEvent(ctx context.Context, conn *websocket.Conn, raw []j
205 return err 205 return err
206 } 206 }
207 207
208 if *authenticatedPubkey == "" && h.authConfig != nil && h.authConfig.WriteEnabled {
209 return nil
210 }
211
208 var event nostr.Event 212 var event nostr.Event
209 if err := json.Unmarshal(raw[1], &event); err != nil { 213 if err := json.Unmarshal(raw[1], &event); err != nil {
210 return fmt.Errorf("invalid event: %w", err) 214 return fmt.Errorf("invalid event: %w", err)
@@ -263,6 +267,10 @@ func (h *Handler) handleReq(ctx context.Context, conn *websocket.Conn, raw []jso
263 return err 267 return err
264 } 268 }
265 269
270 if *authenticatedPubkey == "" && h.authConfig != nil && h.authConfig.ReadEnabled {
271 return nil
272 }
273
266 var subID string 274 var subID string
267 if err := json.Unmarshal(raw[1], &subID); err != nil { 275 if err := json.Unmarshal(raw[1], &subID); err != nil {
268 return fmt.Errorf("invalid subscription ID") 276 return fmt.Errorf("invalid subscription ID")