|
46 | 46 | leEmail = flag.String("le-email", "", "Contact email for Let's Encrypt notifications") |
47 | 47 | maxConnsPerIP = flag.Int("max-conns-per-ip", 10, "Maximum WebSocket connections per IP") |
48 | 48 | maxConnsTotal = flag.Int("max-conns-total", 1000, "Maximum total WebSocket connections") |
49 | | - rateLimit = flag.Int("rate-limit", 100, "Maximum requests per minute per IP") |
50 | 49 | allowedEvents = flag.String("allowed-events", func() string { |
51 | 50 | if value := os.Getenv("ALLOWED_WEBHOOK_EVENTS"); value != "" { |
52 | 51 | return value |
@@ -92,8 +91,7 @@ func main() { |
92 | 91 | hub := srv.NewHub() |
93 | 92 | go hub.Run(ctx) |
94 | 93 |
|
95 | | - // Create security components |
96 | | - rateLimiter := security.NewRateLimiter(*rateLimit) |
| 94 | + // Create connection limiter for WebSocket connections |
97 | 95 | connLimiter := security.NewConnectionLimiter(*maxConnsPerIP, *maxConnsTotal) |
98 | 96 |
|
99 | 97 | mux := http.NewServeMux() |
@@ -133,16 +131,6 @@ func main() { |
133 | 131 | return |
134 | 132 | } |
135 | 133 |
|
136 | | - // Rate limiting |
137 | | - if !rateLimiter.Allow(ip) { |
138 | | - log.Printf("Webhook 429: rate limit exceeded ip=%s", ip) |
139 | | - w.WriteHeader(http.StatusTooManyRequests) |
140 | | - if _, err := w.Write([]byte("429 Too Many Requests: Rate limit exceeded\n")); err != nil { |
141 | | - log.Printf("failed to write 429 response: %v", err) |
142 | | - } |
143 | | - return |
144 | | - } |
145 | | - |
146 | 134 | webhookHandler.ServeHTTP(w, r) |
147 | 135 | log.Printf("Webhook complete: ip=%s duration=%v", ip, time.Since(startTime)) |
148 | 136 | }) |
@@ -185,16 +173,6 @@ func main() { |
185 | 173 | return |
186 | 174 | } |
187 | 175 |
|
188 | | - // Rate limiting check |
189 | | - if !rateLimiter.Allow(ip) { |
190 | | - log.Printf("WebSocket 429: rate limit exceeded ip=%s", ip) |
191 | | - w.WriteHeader(http.StatusTooManyRequests) |
192 | | - if _, err := w.Write([]byte("429 Too Many Requests: Rate limit exceeded\n")); err != nil { |
193 | | - log.Printf("failed to write 429 response: %v", err) |
194 | | - } |
195 | | - return |
196 | | - } |
197 | | - |
198 | 176 | // Pre-validate authentication before WebSocket upgrade |
199 | 177 | authHeader := r.Header.Get("Authorization") |
200 | 178 | if !wsHandler.PreValidateAuth(r) { |
@@ -287,9 +265,6 @@ func main() { |
287 | 265 | // Stop accepting new connections |
288 | 266 | hub.Stop() |
289 | 267 |
|
290 | | - // Stop the rate limiter cleanup routine |
291 | | - rateLimiter.Stop() |
292 | | - |
293 | 268 | // Stop the connection limiter cleanup routine |
294 | 269 | connLimiter.Stop() |
295 | 270 |
|
|
0 commit comments