Skip to content

does this shit work for auth?#170

Open
TekkadanPlays wants to merge 3 commits intohoytech:masterfrom
TekkadanPlays:master
Open

does this shit work for auth?#170
TekkadanPlays wants to merge 3 commits intohoytech:masterfrom
TekkadanPlays:master

Conversation

@TekkadanPlays
Copy link

nonce clientID for unique origin string and create session tokens.. why not? i haven't been here for every discussion so forgive me if this has been suggested or attempted

i am here to discover the meaning of sensible, stateless authentication

what are the implications??

godspeed

Implement NIP-42 (AUTH) challenge-response authentication for strfry,
plus a session token mechanism that eliminates redundant signing on
reconnection and unifies WebSocket/HTTP auth.

Changes:
- New src/SessionToken.h: HMAC-SHA256 session token generation/validation
- RelayIngester: AUTH and SESSION command handling, per-connection auth
  state tracking, operation gating when auth is required
- RelayServer.h: OpenConn message variant, session secret, auth helpers
- RelayWebsocket: AUTH challenge on connect, NIP-11 auth advertising,
  GET /auth/verify HTTP endpoint for session token validation
- cmd_relay: session secret init, auth config validation on startup
- golpe.yaml + strfry.conf: auth config (enabled, required, relayUrl,
  sessionTokenEnabled, sessionTokenLifetimeSeconds)
- README: full documentation including extension authentication guide
- Reject kind:22242 events via EVENT (must use AUTH per NIP-42 spec)
Three new auth features absorbing the best ideas from interceptor-proxy
into strfry natively, eliminating the need for a separate proxy process.

1. Anti-abuse tarpit (RelayIngester.cpp):
   - Track failed AUTH attempts per connection (authFailCount)
   - After tarpitThreshold (default 10) failures, delay responses by
     tarpitDelaySeconds (default 30s) on that connection
   - Makes brute-force/replay attacks impractical

2. Sensitive event filtering (RelayReqWorker.cpp, RelayReqMonitor.cpp):
   - Configurable sensitiveKinds JSON array (e.g. [4,1059,1060,...])
   - Events of sensitive kinds only returned to author or p-tag recipients
   - Subscription carries authedPubkey for per-subscriber filtering
   - Batch sends in monitor filtered per-recipient via getSubAuthedPubkey()
   - Protects DMs, gift wraps, sealed messages from unauthorized readers

3. Authorization plugin (RelayIngester.cpp):
   - Long-running stdin/stdout plugin (same pattern as writePolicy)
   - Called after successful NIP-42 or SESSION auth
   - Returns {allowed, tier} where tier is 'full' or 'partial'
   - Partial tier: write-only (EVENT allowed, REQ blocked)
   - Fail-closed: plugin errors deny access
   - Replaces interceptor-proxy's external config API

Supporting changes:
- golpe.yaml: 4 new config entries
- strfry.conf: documented all new options
- Subscription.h: added authedPubkey field
- ActiveMonitors.h: added getSubAuthedPubkey() lookup
- RelayServer.h: added parseSensitiveKinds(), isSensitiveEventAllowed()
  static helpers, updated ingesterProcessReq signature
- ConnectionAuth: added authTier, authFailCount fields
- README.md: full documentation for all three features with examples
@hoytech
Copy link
Owner

hoytech commented Feb 28, 2026

This is a very big changeset. We're still discussing how AUTH can/should be implemented. What are your thoughts on the approach in #156 ?

Please join our telegram channel if you'd like to strike up a conversation on this: https://t.me/strfry_users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants