mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Resolve messages as part of policy check
This commit is contained in:
parent
5dee4210eb
commit
61dc01af11
@ -3,7 +3,7 @@ import pprint
|
|||||||
import cStringIO
|
import cStringIO
|
||||||
import copy
|
import copy
|
||||||
from flask import Flask, jsonify, render_template, request, abort, make_response
|
from flask import Flask, jsonify, render_template, request, abort, make_response
|
||||||
import version, language, utils
|
from . import version, language, utils
|
||||||
from netlib import http_uastrings
|
from netlib import http_uastrings
|
||||||
|
|
||||||
logging.basicConfig(level="DEBUG")
|
logging.basicConfig(level="DEBUG")
|
||||||
@ -143,13 +143,12 @@ def make_app(noapi, debug):
|
|||||||
|
|
||||||
s = cStringIO.StringIO()
|
s = cStringIO.StringIO()
|
||||||
safe = r.preview_safe()
|
safe = r.preview_safe()
|
||||||
|
err, safe = app.config["pathod"].check_policy(
|
||||||
c = app.config["pathod"].check_policy(
|
|
||||||
safe,
|
safe,
|
||||||
app.config["pathod"].settings
|
app.config["pathod"].settings
|
||||||
)
|
)
|
||||||
if c:
|
if err:
|
||||||
args["error"] = c
|
args["error"] = err
|
||||||
return render(template, False, **args)
|
return render(template, False, **args)
|
||||||
if is_request:
|
if is_request:
|
||||||
set = copy.copy(app.config["pathod"].settings)
|
set = copy.copy(app.config["pathod"].settings)
|
||||||
|
@ -66,13 +66,13 @@ class PathodHandler(tcp.BaseHandler):
|
|||||||
self.sni = connection.get_servername()
|
self.sni = connection.get_servername()
|
||||||
|
|
||||||
def serve_crafted(self, crafted):
|
def serve_crafted(self, crafted):
|
||||||
c = self.server.check_policy(crafted, self.server.settings)
|
error, crafted = self.server.check_policy(crafted, self.server.settings)
|
||||||
if c:
|
if error:
|
||||||
err = language.make_error_response(c)
|
err = language.make_error_response(error)
|
||||||
language.serve(err, self.wfile, self.server.settings)
|
language.serve(err, self.wfile, self.server.settings)
|
||||||
log = dict(
|
log = dict(
|
||||||
type="error",
|
type="error",
|
||||||
msg=c
|
msg = error
|
||||||
)
|
)
|
||||||
return False, log
|
return False, log
|
||||||
|
|
||||||
@ -333,14 +333,15 @@ class Pathod(tcp.TCPServer):
|
|||||||
A policy check that verifies the request size is withing limits.
|
A policy check that verifies the request size is withing limits.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
req = req.resolve(settings)
|
||||||
l = req.maximum_length(settings)
|
l = req.maximum_length(settings)
|
||||||
except language.FileAccessDenied:
|
except language.FileAccessDenied:
|
||||||
return "File access denied."
|
return "File access denied.", None
|
||||||
if self.sizelimit and l > self.sizelimit:
|
if self.sizelimit and l > self.sizelimit:
|
||||||
return "Response too large."
|
return "Response too large.", None
|
||||||
if self.nohang and any([isinstance(i, language.PauseAt) for i in req.actions]):
|
if self.nohang and any([isinstance(i, language.PauseAt) for i in req.actions]):
|
||||||
return "Pauses have been disabled."
|
return "Pauses have been disabled.", None
|
||||||
return False
|
return None, req
|
||||||
|
|
||||||
def handle_client_connection(self, request, client_address):
|
def handle_client_connection(self, request, client_address):
|
||||||
h = PathodHandler(request, client_address, self)
|
h = PathodHandler(request, client_address, self)
|
||||||
|
Loading…
Reference in New Issue
Block a user