aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/cmdline.py20
-rw-r--r--libpathod/pathod.py14
-rw-r--r--libpathod/test.py3
-rw-r--r--libpathod/utils.py5
4 files changed, 27 insertions, 15 deletions
diff --git a/libpathod/cmdline.py b/libpathod/cmdline.py
index 2279262d..af1b1c3d 100644
--- a/libpathod/cmdline.py
+++ b/libpathod/cmdline.py
@@ -8,6 +8,7 @@ from netlib import http_uastrings
from . import pathoc, pathod, version, utils, language
+
def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
preparser = argparse.ArgumentParser(add_help=False)
preparser.add_argument(
@@ -234,13 +235,17 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
action="append",
metavar="ANCHOR",
help="""
- Add an anchor. Specified as a string with the form pattern=pagespec, or
- pattern=filepath
+ Add an anchor. Specified as a string with the form
+ pattern=spec or pattern=filepath, where pattern is a regular
+ expression.
"""
)
parser.add_argument(
- "-c", dest='craftanchor', default="/p", type=str,
- help='Anchorpoint for URL crafting commands. (/p)'
+ "-c", dest='craftanchor', default=pathod.DEFAULT_ANCHOR, type=str,
+ help="""
+ Regular expression specifying anchor point for URL crafting
+ commands. (%s)
+ """%pathod.DEFAULT_ANCHOR
)
parser.add_argument(
"--confdir",
@@ -394,6 +399,13 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
return parser.error(v)
args.sizelimit = sizelimit
+ try:
+ args.craftanchor = re.compile(args.craftanchor)
+ except re.error:
+ return parser.error(
+ "Invalid regex in craft anchor: %s" % args.craftanchor
+ )
+
anchors = []
for patt, spec in args.anchors:
if os.path.isfile(spec):
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index b8df2eff..839b5406 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -4,6 +4,8 @@ import os
import sys
import threading
import urllib
+import re
+
from netlib import tcp, http, wsgi, certutils, websockets
from . import version, app, language, utils, log
@@ -15,6 +17,7 @@ DEFAULT_CERT_DOMAIN = "pathod.net"
CONFDIR = "~/.mitmproxy"
CERTSTORE_BASENAME = "mitmproxy"
CA_CERT_NAME = "mitmproxy-ca.pem"
+DEFAULT_ANCHOR = r"/p/?"
logger = logging.getLogger('pathod')
@@ -246,10 +249,9 @@ class PathodHandler(tcp.BaseHandler):
nexthandler, retlog["response"] = self.serve_crafted(i[1])
return nexthandler, retlog
- if not self.server.nocraft and utils.matchpath(
- path,
- self.server.craftanchor):
- spec = urllib.unquote(path)[len(self.server.craftanchor) + 1:]
+ m = utils.MemBool()
+ if m(self.server.craftanchor.match(path)):
+ spec = urllib.unquote(path)[len(m.v.group()):]
websocket_key = websockets.check_client_handshake(headers)
self.settings.websocket_key = websocket_key
if websocket_key and not spec:
@@ -323,7 +325,7 @@ class Pathod(tcp.TCPServer):
addr,
ssl=False,
ssloptions=None,
- craftanchor="/p",
+ craftanchor=re.compile(DEFAULT_ANCHOR),
staticdir=None,
anchors=(),
sizelimit=None,
@@ -380,6 +382,8 @@ class Pathod(tcp.TCPServer):
"""
A policy check that verifies the request size is withing limits.
"""
+ if self.nocraft:
+ return "Crafting disabled.", None
try:
req = req.resolve(settings)
l = req.maximum_length(settings)
diff --git a/libpathod/test.py b/libpathod/test.py
index 596fea9c..6a15182a 100644
--- a/libpathod/test.py
+++ b/libpathod/test.py
@@ -1,8 +1,9 @@
import threading
import Queue
+
import requests
import requests.packages.urllib3
-import pathod
+from . import pathod
requests.packages.urllib3.disable_warnings()
diff --git a/libpathod/utils.py b/libpathod/utils.py
index 1475500a..9bd2812e 100644
--- a/libpathod/utils.py
+++ b/libpathod/utils.py
@@ -127,8 +127,3 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # pra
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
-
-
-def matchpath(path, spec):
- if path == spec or path.startswith(spec + "/"):
- return True