id: http-block-suspicious-methods name: Block suspicious HTTP methods protocol: http description: Denies uncommon or dangerous HTTP methods. category: http family: web-hardening tags: - method-filter - web - block action: block summary: Denies uncommon or dangerous HTTP methods. behavior: Returns 405 Method Not Allowed for methods outside the allowlist and logs the blocked method and target URL. source_url: https://docs.mitmproxy.org/stable/addons/examples/ code: | import logging from mitmproxy import http ALLOWED_METHODS = {"GET", "POST", "HEAD"} def request(flow: http.HTTPFlow) -> None: if flow.request.method not in ALLOWED_METHODS: logging.warning( "[http-block-suspicious-methods] blocked method=%s url=%s", flow.request.method, flow.request.pretty_url, ) flow.response = http.Response.make( 405, b"", {"allow": "GET, POST, HEAD"}, )