diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-14 11:42:05 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-14 13:40:03 +0000 |
| commit | 50000cd9d47681390c3c45feef98fe51c7b79a0f (patch) | |
| tree | 53ede8cb63ac2c5fe2321a6ecd9c87956537bbc7 /src/nostr | |
| parent | e3792b9abefd43b4594af2640ad4665c006fa3b0 (diff) | |
Add explicit rate limits and total connection limit
- Make RateLimit explicit in relay builder (500 subs, 60 events/min)
- Add NGIT_MAX_CONNECTIONS config option (default: 500)
- Update all 4 config locations (src, nix, docs, .env.example)
- Fix documentation error: filter limit 5000→500
- Document Phase 2 deferral decision (per-IP enforcement)
Addresses primary DoS vector (connection exhaustion) with minimal code.
Per-IP rate limiting deferred until abuse detected in production.
Related: issue ff38 (git endpoint throttling - separate concern)
Diffstat (limited to 'src/nostr')
| -rw-r--r-- | src/nostr/builder.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index c2de1df..ef1b700 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -624,6 +624,14 @@ pub async fn create_relay( | |||
| 624 | let relay = LocalRelayBuilder::default() | 624 | let relay = LocalRelayBuilder::default() |
| 625 | .database(database.clone()) | 625 | .database(database.clone()) |
| 626 | .write_policy(write_policy.clone()) | 626 | .write_policy(write_policy.clone()) |
| 627 | // Explicitly set rate limits (make defaults visible in code) | ||
| 628 | // Per-connection limits: 500 max subscriptions, 60 events/min | ||
| 629 | .rate_limit(RateLimit { | ||
| 630 | max_reqs: 500, // Max concurrent subscriptions per connection | ||
| 631 | notes_per_minute: 60, // Max events per minute per connection | ||
| 632 | }) | ||
| 633 | // Total connection limit to prevent DoS attacks | ||
| 634 | .max_connections(config.max_connections) | ||
| 627 | .build(); | 635 | .build(); |
| 628 | 636 | ||
| 629 | tracing::info!( | 637 | tracing::info!( |