mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 14:58:38 +00:00
Protect against exceptions thrown by third-party view libraries.
This commit is contained in:
parent
a7e64a1a03
commit
c4426952ad
@ -234,12 +234,7 @@ def view_urlencoded(hdrs, content, limit):
|
|||||||
def view_javascript(hdrs, content, limit):
|
def view_javascript(hdrs, content, limit):
|
||||||
opts = jsbeautifier.default_options()
|
opts = jsbeautifier.default_options()
|
||||||
opts.indent_size = 2
|
opts.indent_size = 2
|
||||||
try:
|
res = jsbeautifier.beautify(content[:limit], opts)
|
||||||
res = jsbeautifier.beautify(content[:limit], opts)
|
|
||||||
except: # pragma: no cover
|
|
||||||
# Bugs in jsbeautifier mean that it
|
|
||||||
# can throw arbitrary errors.
|
|
||||||
return None # pragma: no cover
|
|
||||||
return "JavaScript", _view_text(res, len(content), limit)
|
return "JavaScript", _view_text(res, len(content), limit)
|
||||||
|
|
||||||
|
|
||||||
@ -320,7 +315,11 @@ def get_content_view(viewmode, hdrItems, content, limit):
|
|||||||
content = decoded
|
content = decoded
|
||||||
msg.append("[decoded %s]"%enc[0])
|
msg.append("[decoded %s]"%enc[0])
|
||||||
func = get_view_func(viewmode, hdrs, content)
|
func = get_view_func(viewmode, hdrs, content)
|
||||||
ret = func(hdrs, content, limit)
|
try:
|
||||||
|
ret = func(hdrs, content, limit)
|
||||||
|
# Third-party viewers can fail in unexpected ways...
|
||||||
|
except:
|
||||||
|
ret = None
|
||||||
if not ret:
|
if not ret:
|
||||||
viewmode = VIEW_RAW
|
viewmode = VIEW_RAW
|
||||||
ret = view_raw(hdrs, content, limit)
|
ret = view_raw(hdrs, content, limit)
|
||||||
|
Loading…
Reference in New Issue
Block a user