Parcourir la source

pass the correct quit message when a proxied client is banned

If you were banned and the ban was only detected when you proxied
(because you were proxying from a DLINE'd IP), you'd get an incorrect
quit message: `QUIT: Bad or unauthorized PROXY command`. This propagates
the correct ban message as the quit line.
tags/v1.1.0-rc1
Shivaram Lingamneni il y a 5 ans
Parent
révision
316d45917d
3 fichiers modifiés avec 23 ajouts et 22 suppressions
  1. 1
    5
      irc/errors.go
  2. 15
    16
      irc/gateways.go
  3. 7
    1
      irc/handlers.go

+ 1
- 5
irc/errors.go Voir le fichier

@@ -13,7 +13,6 @@ var (
13 13
 	errAccountAlreadyVerified         = errors.New(`Account is already verified`)
14 14
 	errAccountCantDropPrimaryNick     = errors.New("Can't unreserve primary nickname")
15 15
 	errAccountCreation                = errors.New("Account could not be created")
16
-	errAccountCredUpdate              = errors.New("Could not update password hash to new method")
17 16
 	errAccountDoesNotExist            = errors.New("Account does not exist")
18 17
 	errAccountInvalidCredentials      = errors.New("Invalid account credentials")
19 18
 	errAccountBadPassphrase           = errors.New(`Passphrase contains forbidden characters or is otherwise invalid`)
@@ -28,7 +27,6 @@ var (
28 27
 	errCallbackFailed                 = errors.New("Account verification could not be sent")
29 28
 	errCertfpAlreadyExists            = errors.New(`An account already exists for your certificate fingerprint`)
30 29
 	errChannelNotOwnedByAccount       = errors.New("Channel not owned by the specified account")
31
-	errChannelDoesNotExist            = errors.New("Channel does not exist")
32 30
 	errChannelAlreadyRegistered       = errors.New("Channel is already registered")
33 31
 	errChannelNameInUse               = errors.New(`Channel name in use`)
34 32
 	errInvalidChannelName             = errors.New(`Invalid channel name`)
@@ -38,12 +36,10 @@ var (
38 36
 	errNicknameReserved               = errors.New("nickname is reserved")
39 37
 	errNoExistingBan                  = errors.New("Ban does not exist")
40 38
 	errNoSuchChannel                  = errors.New(`No such channel`)
41
-	errRenamePrivsNeeded              = errors.New(`Only chanops can rename channels`)
42 39
 	errInsufficientPrivs              = errors.New("Insufficient privileges")
43
-	errSaslFail                       = errors.New("SASL failed")
44
-	errResumeTokenAlreadySet          = errors.New("Client was already assigned a resume token")
45 40
 	errInvalidUsername                = errors.New("Invalid username")
46 41
 	errFeatureDisabled                = errors.New(`That feature is disabled`)
42
+	errBanned                         = errors.New("IP or nickmask banned")
47 43
 	errInvalidParams                  = errors.New("Invalid parameters")
48 44
 )
49 45
 

+ 15
- 16
irc/gateways.go Voir le fichier

@@ -46,24 +46,22 @@ func (wc *webircConfig) Populate() (err error) {
46 46
 }
47 47
 
48 48
 // ApplyProxiedIP applies the given IP to the client.
49
-func (client *Client) ApplyProxiedIP(session *Session, proxiedIP string, tls bool) (success bool) {
49
+func (client *Client) ApplyProxiedIP(session *Session, proxiedIP string, tls bool) (err error, quitMsg string) {
50 50
 	// PROXY and WEBIRC are never accepted from a Tor listener, even if the address itself
51 51
 	// is whitelisted:
52 52
 	if client.isTor {
53
-		return false
53
+		return errBadProxyLine, ""
54 54
 	}
55 55
 
56 56
 	// ensure IP is sane
57 57
 	parsedProxiedIP := net.ParseIP(proxiedIP).To16()
58 58
 	if parsedProxiedIP == nil {
59
-		client.Quit(fmt.Sprintf(client.t("Proxied IP address is not valid: [%s]"), proxiedIP), session)
60
-		return false
59
+		return errBadProxyLine, fmt.Sprintf(client.t("Proxied IP address is not valid: [%s]"), proxiedIP)
61 60
 	}
62 61
 
63 62
 	isBanned, banMsg := client.server.checkBans(parsedProxiedIP)
64 63
 	if isBanned {
65
-		client.Quit(banMsg, session)
66
-		return false
64
+		return errBanned, banMsg
67 65
 	}
68 66
 
69 67
 	// given IP is sane! override the client's current IP
@@ -84,7 +82,7 @@ func (client *Client) ApplyProxiedIP(session *Session, proxiedIP string, tls boo
84 82
 	client.certfp = ""
85 83
 	client.SetMode(modes.TLS, tls)
86 84
 
87
-	return true
85
+	return nil, ""
88 86
 }
89 87
 
90 88
 // handle the PROXY command: http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
@@ -93,9 +91,13 @@ func (client *Client) ApplyProxiedIP(session *Session, proxiedIP string, tls boo
93 91
 // unfortunately, an ipv6 SOURCEIP can start with a double colon; in this case,
94 92
 // the message is invalid IRC and can't be parsed normally, hence the special handling.
95 93
 func handleProxyCommand(server *Server, client *Client, session *Session, line string) (err error) {
94
+	var quitMsg string
96 95
 	defer func() {
97 96
 		if err != nil {
98
-			client.Quit(client.t("Bad or unauthorized PROXY command"), session)
97
+			if quitMsg == "" {
98
+				quitMsg = client.t("Bad or unauthorized PROXY command")
99
+			}
100
+			client.Quit(quitMsg, session)
99 101
 		}
100 102
 	}()
101 103
 
@@ -106,13 +108,10 @@ func handleProxyCommand(server *Server, client *Client, session *Session, line s
106 108
 
107 109
 	if utils.IPInNets(client.realIP, server.Config().Server.proxyAllowedFromNets) {
108 110
 		// assume PROXY connections are always secure
109
-		if client.ApplyProxiedIP(session, params[2], true) {
110
-			return nil
111
-		} else {
112
-			return errBadProxyLine
113
-		}
111
+		err, quitMsg = client.ApplyProxiedIP(session, params[2], true)
112
+		return
113
+	} else {
114
+		// real source IP is not authorized to issue PROXY:
115
+		return errBadGatewayAddress
114 116
 	}
115
-
116
-	// real source IP is not authorized to issue PROXY:
117
-	return errBadGatewayAddress
118 117
 }

+ 7
- 1
irc/handlers.go Voir le fichier

@@ -2576,7 +2576,13 @@ func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2576 2576
 			if strings.HasPrefix(proxiedIP, "[") && strings.HasSuffix(proxiedIP, "]") {
2577 2577
 				proxiedIP = proxiedIP[1 : len(proxiedIP)-1]
2578 2578
 			}
2579
-			return !client.ApplyProxiedIP(rb.session, proxiedIP, secure)
2579
+			err, quitMsg := client.ApplyProxiedIP(rb.session, proxiedIP, secure)
2580
+			if err != nil {
2581
+				client.Quit(quitMsg, rb.session)
2582
+				return true
2583
+			} else {
2584
+				return false
2585
+			}
2580 2586
 		}
2581 2587
 	}
2582 2588
 

Chargement…
Annuler
Enregistrer