feat: add proxy template origin field and implement socket utilities for log streaming

This commit is contained in:
gabdevele
2026-05-07 10:54:57 +02:00 Unverified
parent 53dcdafdb1
commit 354ec150bc
32 changed files with 1681 additions and 1214 deletions
@@ -0,0 +1,40 @@
id: http-sanitize-headers-basic
name: Sanitize risky forwarding headers
protocol: http
description: Removes a few risky forwarding headers before the request is sent upstream.
category: http
family: web-hardening
tags:
- rewrite
- headers
- web
action: rewrite
summary: Removes a few risky forwarding headers before the request is sent upstream.
behavior: Deletes selected override or forwarding headers and logs what was rewritten
without blocking the request.
source_url: https://docs.mitmproxy.org/stable/addons/examples/
code: |
import logging
from mitmproxy import http
STRIP_HEADERS = (
"x-forwarded-host",
"x-http-method-override",
"x-original-url",
"x-rewrite-url",
)
def request(flow: http.HTTPFlow) -> None:
removed = []
for header in STRIP_HEADERS:
if header in flow.request.headers:
removed.append(header)
del flow.request.headers[header]
if removed:
logging.info(
"[http-sanitize-headers-basic] stripped headers=%s url=%s",
",".join(removed),
flow.request.pretty_url,
)