aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hydrilla/proxy/addon.py20
-rw-r--r--src/hydrilla/proxy/policies/__init__.py3
-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