websocket 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd819fd576b9bc42e42b888bf9407c20e1557d62
4
- data.tar.gz: b5a0b3732a0058688c3d2121833dd4909b5d9371
3
+ metadata.gz: 3d5e949888cd78a33c1418916aa773e1408a9302
4
+ data.tar.gz: d74a71f238b56bf1711dd7b117cde1d3cf5bc037
5
5
  SHA512:
6
- metadata.gz: ba657ffa0c0efe8cfbdca9fa5b229bb8aba86eda86a37eca0d7511695a42008e86c18ad8e89280773a97212ad1b08b3b811bdf9219974f1205c6effb1f9d5c90
7
- data.tar.gz: 6ed217acb30fd88f14b7007a4df1e4534f7d0f01057c450ed463fe7cdaa94023d2de51ba8c373bc6f383e13e07bacecea731ee079d7102cc7b351d01c26f1049
6
+ metadata.gz: 5a7e71df6d11c0fc817d094845dd059a0d2ec00586f7373a714bde6d3ee9dbf15e27ecbb94c00aef039f2fc85da34933b21110d767429a8aa2bce35cb192cd9f
7
+ data.tar.gz: 48e22828b858a469f179bcf08ecc8acbc427f6f863e1cf38a3ca3e5b36a9a4c06a93a72b024e6dd5b7f1b11864cb6abefbef6334c7f789cfbe1451e766c0a0ed
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.4
4
+
5
+ - verify valid close codes according to spec
6
+ - return error on invalid UTF-8 payload
7
+ - expose error message
8
+
3
9
  ## 1.1.3
4
10
 
5
11
  - fix close code support
@@ -47,6 +47,10 @@ module WebSocket
47
47
  def message; :unknown_opcode; end
48
48
  end
49
49
 
50
+ class UnknownCloseCode < ::WebSocket::Error::Frame
51
+ def message; :unknown_close_code; end
52
+ end
53
+
50
54
  class UnknownVersion < ::WebSocket::Error::Frame
51
55
  def message; :unknown_protocol_version; end
52
56
  end
@@ -4,7 +4,7 @@ module WebSocket
4
4
  class Base
5
5
  include ExceptionHandler
6
6
 
7
- attr_reader :type, :version
7
+ attr_reader :type, :version, :error
8
8
  attr_accessor :data, :code
9
9
 
10
10
  # Initialize frame
@@ -21,6 +21,7 @@ module WebSocket
21
21
  def encode_frame
22
22
  if @frame.type == :close
23
23
  code = @frame.code || 1000
24
+ raise WebSocket::Error::Frame::UnknownCloseCode unless valid_code?(code)
24
25
  @frame.data = Data.new([code].pack('n') + @frame.data.to_s)
25
26
  @frame.code = nil
26
27
  end
@@ -32,12 +33,26 @@ module WebSocket
32
33
  if has_close_code?(result)
33
34
  code = result.data.slice!(0..1)
34
35
  result.code = code.unpack('n').first
36
+ raise WebSocket::Error::Frame::UnknownCloseCode unless valid_code?(result.code)
37
+ raise WebSocket::Error::Frame::InvalidPayloadEncoding unless valid_encoding?(result.data)
35
38
  end
36
39
  result
37
40
  end
38
41
 
39
42
  private
40
43
 
44
+ def valid_code?(code)
45
+ [1000,1001,1002,1003,1007,1008,1009,1010,1011].include?(code) || (3000..4999).include?(code)
46
+ end
47
+
48
+ def valid_encoding?(data)
49
+ return true if data.nil? || !data.respond_to?(:encode)
50
+ data.encode('UTF-8')
51
+ true
52
+ rescue
53
+ false
54
+ end
55
+
41
56
  def has_close_code?(frame)
42
57
  frame && frame.type == :close && !frame.data.empty?
43
58
  end
@@ -1,3 +1,3 @@
1
1
  module WebSocket
2
- VERSION = '1.1.3'
2
+ VERSION = '1.1.4'
3
3
  end
@@ -21,6 +21,22 @@ describe 'Incoming frame draft 07' do
21
21
  it_should_behave_like 'valid_incoming_frame'
22
22
  end
23
23
 
24
+ context "should raise error with invalid close code" do
25
+ let(:encoded_text) { "\x88\x07\x03\xEDHello" }
26
+ let(:decoded_text) { nil }
27
+ let(:error) { WebSocket::Error::Frame::UnknownCloseCode }
28
+
29
+ it_should_behave_like 'valid_incoming_frame'
30
+ end
31
+
32
+ context "should properly decode close frame with invalid UTF-8 message" do
33
+ let(:encoded_text) { "\x88\x03\x03\xE8\xE3" }
34
+ let(:decoded_text) { nil }
35
+ let(:error) { WebSocket::Error::Frame::InvalidPayloadEncoding }
36
+
37
+ it_should_behave_like 'valid_incoming_frame'
38
+ end
39
+
24
40
  context "should properly decode ping frame" do
25
41
  let(:encoded_text) { "\x89\x05" + decoded_text }
26
42
  let(:frame_type) { :ping }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Potocki