diff options
Diffstat (limited to 'mitmproxy/builtins/stickyauth.py')
-rw-r--r-- | mitmproxy/builtins/stickyauth.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/mitmproxy/builtins/stickyauth.py b/mitmproxy/builtins/stickyauth.py new file mode 100644 index 00000000..1309911c --- /dev/null +++ b/mitmproxy/builtins/stickyauth.py @@ -0,0 +1,28 @@ +from __future__ import absolute_import, print_function, division + +from mitmproxy import filt +from mitmproxy import exceptions + + +class StickyAuth: + def __init__(self): + # Compiled filter + self.flt = None + self.hosts = {} + + def configure(self, options): + if options.stickyauth: + flt = filt.parse(options.stickyauth) + if not flt: + raise exceptions.OptionsError( + "stickyauth: invalid filter expression: %s" % options.stickyauth + ) + self.flt = flt + + def request(self, flow): + host = flow.request.host + if "authorization" in flow.request.headers: + self.hosts[host] = flow.request.headers["authorization"] + elif flow.match(self.flt): + if host in self.hosts: + flow.request.headers["authorization"] = self.hosts[host] |