mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
initial work on #1483
Add the new utf8-only cap, disallow non-utf8 when websockets are enabled
This commit is contained in:
parent
5095a4d814
commit
db81b15acb
@ -686,9 +686,12 @@ func (client *Client) run(session *Session) {
|
||||
if err == errInvalidUtf8 {
|
||||
invalidUtf8 = true // handle as normal, including labeling
|
||||
} else if err != nil {
|
||||
quitMessage := "connection closed"
|
||||
if err == errReadQ {
|
||||
quitMessage = "readQ exceeded"
|
||||
var quitMessage string
|
||||
switch err {
|
||||
case errReadQ, errWSBinaryMessage:
|
||||
quitMessage = err.Error()
|
||||
default:
|
||||
quitMessage = "connection closed"
|
||||
}
|
||||
client.Quit(quitMessage, session)
|
||||
// since the client did not actually send us a QUIT,
|
||||
|
@ -837,6 +837,9 @@ func (conf *Config) prepareListeners() (err error) {
|
||||
}
|
||||
lconf.RequireProxy = block.TLS.Proxy || block.Proxy
|
||||
lconf.WebSocket = block.WebSocket
|
||||
if lconf.WebSocket && !conf.Server.EnforceUtf8 {
|
||||
return fmt.Errorf("enabling a websocket listener requires the use of server.enforce-utf8")
|
||||
}
|
||||
lconf.HideSTS = block.HideSTS
|
||||
conf.Server.trueListeners[addr] = lconf
|
||||
}
|
||||
@ -1446,6 +1449,9 @@ func (config *Config) generateISupport() (err error) {
|
||||
if config.Server.Casemapping == CasemappingPRECIS {
|
||||
isupport.Add("UTF8MAPPING", precisUTF8MappingToken)
|
||||
}
|
||||
if config.Server.EnforceUtf8 {
|
||||
isupport.Add("UTF8ONLY", "")
|
||||
}
|
||||
isupport.Add("WHOX", "")
|
||||
|
||||
err = isupport.RegenerateCachedReply()
|
||||
|
@ -19,8 +19,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
crlf = []byte{'\r', '\n'}
|
||||
errReadQ = errors.New("ReadQ Exceeded")
|
||||
crlf = []byte{'\r', '\n'}
|
||||
errReadQ = errors.New("ReadQ Exceeded")
|
||||
errWSBinaryMessage = errors.New("WebSocket binary messages are unsupported")
|
||||
)
|
||||
|
||||
// IRCConn abstracts away the distinction between a regular
|
||||
@ -148,11 +149,7 @@ func (wc IRCWSConn) UnderlyingConn() *utils.WrappedConn {
|
||||
|
||||
func (wc IRCWSConn) WriteLine(buf []byte) (err error) {
|
||||
buf = bytes.TrimSuffix(buf, crlf)
|
||||
if !globalUtf8EnforcementSetting && !utf8.Valid(buf) {
|
||||
// there's not much we can do about this;
|
||||
// silently drop the message
|
||||
return nil
|
||||
}
|
||||
// #1483: if we have websockets at all, then we're enforcing utf8
|
||||
return wc.conn.WriteMessage(websocket.TextMessage, buf)
|
||||
}
|
||||
|
||||
@ -172,8 +169,7 @@ func (wc IRCWSConn) ReadLine() (line []byte, err error) {
|
||||
if messageType == websocket.TextMessage {
|
||||
return line, nil
|
||||
} else {
|
||||
// for purposes of fakelag, treat non-text message as an empty line
|
||||
return nil, nil
|
||||
return nil, errWSBinaryMessage
|
||||
}
|
||||
} else if err == websocket.ErrReadLimit {
|
||||
return line, errReadQ
|
||||
|
@ -166,6 +166,7 @@ func (wl *WSListener) handle(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
return false
|
||||
},
|
||||
Subprotocols: []string{"text.ircv3.net"},
|
||||
}
|
||||
|
||||
conn, err := wsUpgrader.Upgrade(w, r, nil)
|
||||
|
Loading…
Reference in New Issue
Block a user