Skip to content

Script fails while --server-replay-kill-extra is used in --server-replay, mitmproxy reports wrong flow information #6113

Open

Description

@Semnodime

Problem Description

When running a script via -s together with the --server-replay mode and --server-replay-kill-extra, when the script issues a response via flow.response = http.Response.make(…), the response is killed from perspective of the client, but mitmproxy displays the flow as if the response was delivered:

Steps to reproduce the behavior:

  1. Load the script below via -s script.py
  2. Load some previous unrelated capture via --server-replay unrelated.mitm
  3. Use --server-replay-kill-extra
  4. Load a url outside the scope of the script: mitmproxy displays the flow as killed, this is expected
  5. Load a url within the scope of the script: the flow is killed (so the client e.g. chromium) but mitmproxy pretends it was delivered to the client
    image
    image
    image
# script.py
from mitmproxy import http


def request(flow: http.HTTPFlow) -> None:
    if flow.request.pretty_url.endswith("example.com/path"):
        flow.response = http.Response.make(
            200,  # (optional) status code
            b"Hello World",  # (optional) content
            {"Content-Type": "text/html"},  # (optional) headers
        )

System Information

Mitmproxy: 9.0.1
Python:    3.10.6
OpenSSL:   OpenSSL 3.0.7 1 Nov 2022
Platform:  Linux-5.15.0-71-generic-x86_64-with-glibc2.35

Activity

  1. mhils commented on May 8, 2023

    @mhils
    Member

    Would changing this:

    elif ctx.options.server_replay_kill_extra:

    to this:

    elif ctx.options.server_replay_kill_extra:
        has_response_from_other_addon = flow.response is None
        if not has_response_from_other_addon:

    fix your problem? If so, please feel free to submit a PR that fixes this and ideally adds a test so that we don't regress! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions