From 61dc01af119af79db2ee892770bc51b079d560f9 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 22 Apr 2015 16:38:54 +1200 Subject: [PATCH] Resolve messages as part of policy check --- libpathod/app.py | 9 ++++----- libpathod/pathod.py | 17 +++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libpathod/app.py b/libpathod/app.py index 10f7c148d..a6853ad44 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -3,7 +3,7 @@ import pprint import cStringIO import copy 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 logging.basicConfig(level="DEBUG") @@ -143,13 +143,12 @@ def make_app(noapi, debug): s = cStringIO.StringIO() safe = r.preview_safe() - - c = app.config["pathod"].check_policy( + err, safe = app.config["pathod"].check_policy( safe, app.config["pathod"].settings ) - if c: - args["error"] = c + if err: + args["error"] = err return render(template, False, **args) if is_request: set = copy.copy(app.config["pathod"].settings) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 7b3f74d1a..7fe8e39fd 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -66,13 +66,13 @@ class PathodHandler(tcp.BaseHandler): self.sni = connection.get_servername() def serve_crafted(self, crafted): - c = self.server.check_policy(crafted, self.server.settings) - if c: - err = language.make_error_response(c) + error, crafted = self.server.check_policy(crafted, self.server.settings) + if error: + err = language.make_error_response(error) language.serve(err, self.wfile, self.server.settings) log = dict( type="error", - msg=c + msg = error ) return False, log @@ -333,14 +333,15 @@ class Pathod(tcp.TCPServer): A policy check that verifies the request size is withing limits. """ try: + req = req.resolve(settings) l = req.maximum_length(settings) except language.FileAccessDenied: - return "File access denied." + return "File access denied.", None 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]): - return "Pauses have been disabled." - return False + return "Pauses have been disabled.", None + return None, req def handle_client_connection(self, request, client_address): h = PathodHandler(request, client_address, self)