Skip to content

Commit 81b0b84

Browse files
Configure the JSON decoder for safer parsing
1 parent 9ff8bf3 commit 81b0b84

File tree

8 files changed

+14
-7
lines changed

8 files changed

+14
-7
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
platforms='any',
3131
install_requires=[
3232
'bidict>=0.21.0',
33-
'python-engineio>=4',
33+
'python-engineio>=4.1.0',
3434
],
3535
extras_require={
3636
'client': [

socketio/asyncio_pubsub_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import partial
22
import uuid
33

4-
import json
4+
from engineio import json
55
import pickle
66

77
from .asyncio_manager import AsyncManager

socketio/packet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import functools
2-
import json as _json
2+
from engineio import json as _json
33

44
(CONNECT, DISCONNECT, EVENT, ACK, CONNECT_ERROR, BINARY_EVENT, BINARY_ACK) = \
55
(0, 1, 2, 3, 4, 5, 6)
@@ -79,6 +79,8 @@ def decode(self, encoded_packet):
7979
self.data = None
8080
ep = ep[1:]
8181
dash = ep.find('-')
82+
if dash > 10:
83+
raise ValueError('too many attachments')
8284
attachment_count = 0
8385
if dash > 0 and ep[0:dash].isdigit():
8486
attachment_count = int(ep[0:dash])

socketio/pubsub_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import partial
22
import uuid
33

4-
import json
4+
from engineio import json
55
import pickle
66

77
from .base_manager import BaseManager

tests/asyncio/test_asyncio_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import asyncio
2-
import json
32
import logging
43
import sys
54
import unittest
65
from unittest import mock
76

7+
from engineio import json
88
import pytest
99

1010
from socketio import asyncio_server

tests/common/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import json
21
import logging
32
import sys
43
import unittest
54
from unittest import mock
65

76
from engineio import exceptions as engineio_exceptions
7+
from engineio import json
88
from engineio import packet as engineio_packet
99
import pytest
1010

tests/common/test_packet.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def test_decode_id_long(self):
165165
def test_decode_id_too_long(self):
166166
with pytest.raises(ValueError):
167167
packet.Packet(encoded_packet='2' + '1' * 101)
168+
with pytest.raises(ValueError):
168169
packet.Packet(encoded_packet='2' + '1' * 101 + '["foo"]')
169170

170171
def test_encode_id_no_data(self):
@@ -258,6 +259,10 @@ def test_decode_too_many_binary_packets(self):
258259
with pytest.raises(ValueError):
259260
pkt.add_attachment(b'123')
260261

262+
def test_decode_attachment_count_too_long(self):
263+
with pytest.raises(ValueError):
264+
packet.Packet(encoded_packet='6' + ('1' * 11) + '-{"a":"123}')
265+
261266
def test_data_is_binary_list(self):
262267
pkt = packet.Packet()
263268
assert not pkt._data_is_binary(['foo'])

tests/common/test_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import json
21
import logging
32
import unittest
43
from unittest import mock
54

5+
from engineio import json
66
import pytest
77

88
from socketio import exceptions

0 commit comments

Comments
 (0)