diff options
| author | Shulhan <ms@kilabit.info> | 2019-03-11 23:32:12 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-03-11 23:32:12 +0700 |
| commit | 6d2cd8a9934b7b97adbc27beaf517e4ea2790423 (patch) | |
| tree | 1a141d0f46eb2dc0fe25bb39d4d44b94a1681670 | |
| parent | 929eef95cd27c798d8c128ae0eea83ec34220a3f (diff) | |
| download | pakakeh.go-6d2cd8a9934b7b97adbc27beaf517e4ea2790423.tar.xz | |
websocket: fix response code for fragmentation with invalid opcode
Connection without fragmentation with the first frame is CONT frame,
should be closed with bad-request (1002).
Connection with fragmentation but the next frame opcode is not CONT,
should be closed with bad-request (1002).
| -rw-r--r-- | lib/websocket/server.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/websocket/server.go b/lib/websocket/server.go index ea8108da..51247af9 100644 --- a/lib/websocket/server.go +++ b/lib/websocket/server.go @@ -498,6 +498,7 @@ func (serv *Server) handleFragment(conn int, req *Frame) (isInvalid bool) { // If a connection does not have continuous frame, then // current frame opcode must not be 0. if req.opcode == opcodeCont { + serv.handleBadRequest(conn) return true } frames = new(Frames) @@ -505,6 +506,7 @@ func (serv *Server) handleFragment(conn int, req *Frame) (isInvalid bool) { // If a connection have continuous frame, the next frame // opcode must be 0. if req.opcode != opcodeCont { + serv.handleBadRequest(conn) return true } } @@ -526,6 +528,7 @@ func (serv *Server) handleFragment(conn int, req *Frame) (isInvalid bool) { if frame.opcode == opcodeText { if !utf8.Valid(frame.payload) { + serv.handleInvalidData(conn) return true } serv.HandleText(conn, frame.payload) @@ -832,7 +835,6 @@ func (serv *Server) reader() { case opcodeCont, opcodeText, opcodeBin: isInvalid := serv.handleFragment(conn, frame) if isInvalid { - serv.handleInvalidData(conn) isClosing = true } case opcodeDataRsv3, opcodeDataRsv4, opcodeDataRsv5, opcodeDataRsv6, opcodeDataRsv7: |
