8000 Disconnect clients in case of inappropriate protocol by FZambia · Pull Request #256 · centrifugal/centrifuge · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Disconnect clients in case of inappropriate protocol #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ func (c *Client) writeEncodedPush(rep *protocol.Reply, rw *replyWriter) {
data, err = encoder.Encode(rep.Push)
if err != nil {
c.node.logger.log(newLogEntry(LogLevelError, "error encoding connect push", map[string]interface{}{"push": fmt.Sprintf("%v", rep.Push), "client": c.ID(), "user": c.UserID(), "error": err.Error()}))
go func() { _ = c.close(DisconnectInappropriateProtocol) }()
return
}
}
Expand Down Expand Up @@ 8000 -1272,6 +1273,7 @@ func (c *Client) writeEncodedCommandReply(method protocol.Command_MethodType, cm
replyData, err := replyEncoder.Encode(rep)
if err != nil {
c.node.logger.log(newLogEntry(LogLevelError, "error encoding reply", map[string]interface{}{"reply": fmt.Sprintf("%v", rep), "client": c.ID(), "user": c.UserID(), "error": err.Error()}))
go func() { _ = c.close(DisconnectInappropriateProtocol) }()
return
}
disconnect := c.messageWriter.enqueue(queue.Item{Data: replyData})
Expand Down
15 changes: 15 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func newTestConnectedClient(t *testing.T, n *Node, userID string) *Client {
return client
}

func newTestConnectedClientV2(t *testing.T, n *Node, userID string) *Client {
client := newTestClientV2(t, n, userID)
connectClientV2(t, client)
require.True(t, len(n.hub.UserConnections(userID)) > 0)
return client
}

func newTestConnectedClientWithTransport(t *testing.T, ctx context.Context, n *Node, transport Transport, userID string) *Client {
client := newTestClientCustomTransport(t, ctx, n, transport, userID)
if transport.ProtocolVersion() == ProtocolVersion1 {
Expand All @@ -50,6 +57,14 @@ func newTestSubscribedClient(t *testing.T, n *Node, userID, chanID string) *Clie
return client
}

func newTestSubscribedClientV2(t *testing.T, n *Node, userID, chanID string) *Client {
client := newTestConnectedClientV2(t, n, userID)
subscribeClientV2(t, client, chanID)
require.True(t, n.hub.NumSubscribers(chanID) > 0)
require.Contains(t, client.channels, chanID)
return client
}

func newTestSubscribedClientWithTransport(t *testing.T, ctx context.Context, n *Node, transport Transport, userID, chanID string) *Client {
client := newTestConnectedClientWithTransport(t, ctx, n, transport, userID)
if transport.ProtocolVersion() == ProtocolVersion1 {
Expand Down
8 changes: 8 additions & 0 deletions disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,12 @@ var (
Code: 3505,
Reason: "channel limit",
}
// DisconnectInappropriateProtocol can be issued when client connection format can not
// handle incoming data. For example, this happens when JSON-based clients receive
// binary data in a channel. This is usually an indicator of programmer error, JSON
// clients can not handle binary.
DisconnectInappropriateProtocol = Disconnect{
Code: 3506,
Reason: "inappropriate protocol",
}
)
Loading
0