Просмотр исходного кода

put an upper limit on registration messages

Fixes #505
tags/v1.1.0-rc1
Shivaram Lingamneni 5 лет назад
Родитель
Сommit
4e13f72ca9
3 измененных файлов: 29 добавлений и 10 удалений
  1. 11
    0
      irc/client.go
  2. 14
    10
      irc/config.go
  3. 4
    0
      oragono.yaml

+ 11
- 0
irc/client.go Просмотреть файл

@@ -111,6 +111,8 @@ type Session struct {
111 111
 	capState     caps.State
112 112
 	capVersion   caps.Version
113 113
 
114
+	registrationMessages int
115
+
114 116
 	resumeID         string
115 117
 	resumeDetails    *ResumeDetails
116 118
 	zncPlaybackTimes *zncPlaybackTimes
@@ -396,6 +398,15 @@ func (client *Client) run(session *Session) {
396 398
 			}
397 399
 		}
398 400
 
401
+		// DoS hardening, #505
402
+		if !client.registered {
403
+			session.registrationMessages++
404
+			if client.server.Config().Limits.RegistrationMessages < session.registrationMessages {
405
+				client.Send(nil, client.server.name, ERR_UNKNOWNERROR, "*", client.t("You have sent too many registration messages"))
406
+				break
407
+			}
408
+		}
409
+
399 410
 		msg, err := ircmsg.ParseLineStrict(line, true, maxlenRest)
400 411
 		if err == ircmsg.ErrorLineIsEmpty {
401 412
 			continue

+ 14
- 10
irc/config.go Просмотреть файл

@@ -214,16 +214,17 @@ type LineLenLimits struct {
214 214
 
215 215
 // Various server-enforced limits on data size.
216 216
 type Limits struct {
217
-	AwayLen        int           `yaml:"awaylen"`
218
-	ChanListModes  int           `yaml:"chan-list-modes"`
219
-	ChannelLen     int           `yaml:"channellen"`
220
-	IdentLen       int           `yaml:"identlen"`
221
-	KickLen        int           `yaml:"kicklen"`
222
-	LineLen        LineLenLimits `yaml:"linelen"`
223
-	MonitorEntries int           `yaml:"monitor-entries"`
224
-	NickLen        int           `yaml:"nicklen"`
225
-	TopicLen       int           `yaml:"topiclen"`
226
-	WhowasEntries  int           `yaml:"whowas-entries"`
217
+	AwayLen              int           `yaml:"awaylen"`
218
+	ChanListModes        int           `yaml:"chan-list-modes"`
219
+	ChannelLen           int           `yaml:"channellen"`
220
+	IdentLen             int           `yaml:"identlen"`
221
+	KickLen              int           `yaml:"kicklen"`
222
+	LineLen              LineLenLimits `yaml:"linelen"`
223
+	MonitorEntries       int           `yaml:"monitor-entries"`
224
+	NickLen              int           `yaml:"nicklen"`
225
+	TopicLen             int           `yaml:"topiclen"`
226
+	WhowasEntries        int           `yaml:"whowas-entries"`
227
+	RegistrationMessages int           `yaml:"registration-messages"`
227 228
 }
228 229
 
229 230
 // STSConfig controls the STS configuration/
@@ -532,6 +533,9 @@ func LoadConfig(filename string) (config *Config, err error) {
532 533
 	if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
533 534
 		return nil, ErrLimitsAreInsane
534 535
 	}
536
+	if config.Limits.RegistrationMessages == 0 {
537
+		config.Limits.RegistrationMessages = 1024
538
+	}
535 539
 	if config.Server.STS.Enabled {
536 540
 		config.Server.STS.Duration, err = custime.ParseDuration(config.Server.STS.DurationString)
537 541
 		if err != nil {

+ 4
- 0
oragono.yaml Просмотреть файл

@@ -557,6 +557,10 @@ limits:
557 557
         # configurable length for the rest of the message:
558 558
         rest: 2048
559 559
 
560
+    # maximum number of messages to accept during registration (prevents
561
+    # DoS / resource exhaustion attacks):
562
+    registration-messages: 1024
563
+
560 564
 # fakelag: prevents clients from spamming commands too rapidly
561 565
 fakelag:
562 566
     # whether to enforce fakelag

Загрузка…
Отмена
Сохранить