diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-10-10 15:01:08 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-10-10 15:01:08 +0200 |
commit | b880bdc779b800ebde810279d1cf5b9e530000de (patch) | |
tree | bdf867969da926b38c021e964d06c0052a6bc28c /src/hydrilla/proxy | |
parent | 39ba8a202f4010286b99c3ac34003ffa329153c5 (diff) | |
download | haketilo-hydrilla-b880bdc779b800ebde810279d1cf5b9e530000de.tar.gz haketilo-hydrilla-b880bdc779b800ebde810279d1cf5b9e530000de.zip |
[proxy] make it possible to access http://mitm.it magical domain
Diffstat (limited to 'src/hydrilla/proxy')
-rw-r--r-- | src/hydrilla/proxy/addon.py | 20 | ||||
-rw-r--r-- | src/hydrilla/proxy/policies/__init__.py | 3 | ||||
-rw-r--r-- | src/hydrilla/proxy/policies/misc.py (renamed from src/hydrilla/proxy/policies/fallback.py) | 22 |
3 files changed, 38 insertions, 7 deletions
diff --git a/src/hydrilla/proxy/addon.py b/src/hydrilla/proxy/addon.py index 2185bcb..b8ad819 100644 --- a/src/hydrilla/proxy/addon.py +++ b/src/hydrilla/proxy/addon.py @@ -34,6 +34,7 @@ from addon script. from __future__ import annotations import sys +import re import typing as t import dataclasses as dc import traceback as tb @@ -91,6 +92,10 @@ class FlowHandlingData: policy: policies.Policy +magical_mitm_it_url_reg = re.compile(r'^http://mitm.it(/.*)?$') +dummy_url = parse_url('http://dummy.replacement.url') + + @dc.dataclass class HaketiloAddon: """ @@ -142,11 +147,16 @@ class HaketiloAddon: handling_data = self.flows_data.get(id(flow)) if handling_data is None: - try: - parsed_url = parse_url(flow.request.url) - policy = self.state.select_policy(parsed_url) - except HaketiloException as e: - policy = policies.ErrorBlockPolicy(builtin=True, error=e) + parsed_url = dummy_url + + if magical_mitm_it_url_reg.match(flow.request.url): + policy = policies.DoNothingPolicy() + else: + try: + parsed_url = parse_url(flow.request.url) + policy = self.state.select_policy(parsed_url) + except HaketiloException as e: + policy = policies.ErrorBlockPolicy(builtin=True, error=e) handling_data = FlowHandlingData(parsed_url, policy) diff --git a/src/hydrilla/proxy/policies/__init__.py b/src/hydrilla/proxy/policies/__init__.py index 062ec56..448420a 100644 --- a/src/hydrilla/proxy/policies/__init__.py +++ b/src/hydrilla/proxy/policies/__init__.py @@ -12,6 +12,7 @@ from .payload_resource import PayloadResourcePolicyFactory from .rule import RuleBlockPolicyFactory, RuleAllowPolicyFactory -from .fallback import FallbackAllowPolicy, FallbackBlockPolicy, ErrorBlockPolicy +from .misc import FallbackAllowPolicy, FallbackBlockPolicy, ErrorBlockPolicy, \ + DoNothingPolicy from .web_ui import WebUIPolicyFactory diff --git a/src/hydrilla/proxy/policies/fallback.py b/src/hydrilla/proxy/policies/misc.py index f5c9b16..bc3b08f 100644 --- a/src/hydrilla/proxy/policies/fallback.py +++ b/src/hydrilla/proxy/policies/misc.py @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-3.0-or-later -# Policies for blocking and allowing JS when no other policies match. +# Miscellaneous policies. # # This file is part of Hydrilla&Haketilo. # @@ -39,6 +39,7 @@ import enum from abc import ABC, abstractmethod from .. import state +from .. import http_messages from . import base from .rule import AllowPolicy, BlockPolicy @@ -59,3 +60,22 @@ class ErrorBlockPolicy(BlockPolicy): error: Exception builtin: bool = True + +class DoNothingPolicy(base.Policy): + """ + A special policy class for handling of the magical mitm.it domain. It causes + request and response not to be modified in any way, and also (unlike + FallbackAllowPolicy) prevents them from being streamed. + """ + _process_request: t.ClassVar[bool] = True + _process_response: t.ClassVar[bool] = True + anticache: t.ClassVar[bool] = False + + def consume_request(self, request_info: http_messages.RequestInfo) -> None: + return None + + def consume_response(self, response_info: http_messages.ResponseInfo) \ + -> None: + return None + + builtin: bool = True |