Skip to content

Commit dd1db2e

Browse files
Configure the JSON decoder for safer parsing
1 parent 845fc62 commit dd1db2e

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

engineio/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from base64 import b64encode
2-
from json import JSONDecodeError
2+
from engineio.json import JSONDecodeError
33
import logging
44
try:
55
import queue

engineio/json.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""JSON-compatible module with sane defaults."""
2+
3+
from json import * # noqa: F401, F403
4+
from json import loads as original_loads
5+
6+
7+
def _safe_int(s):
8+
if len(s) > 100:
9+
raise ValueError('Integer is too large')
10+
return int(s)
11+
12+
13+
def loads(*args, **kwargs):
14+
if 'parse_int' not in kwargs:
15+
kwargs['parse_int'] = _safe_int
16+
return original_loads(*args, **kwargs)

engineio/packet.py

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

44
(OPEN, CLOSE, PING, PONG, MESSAGE, UPGRADE, NOOP) = (0, 1, 2, 3, 4, 5, 6)
55
packet_names = ['OPEN', 'CLOSE', 'PING', 'PONG', 'MESSAGE', 'UPGRADE', 'NOOP']

0 commit comments

Comments
 (0)