Skip to content

Don't let server replay override a response set by an earlier addon - #8563

Open
Thanatos9404 wants to merge 6 commits into
mitmproxy:mainfrom
Thanatos9404:server-replay-keep-addon-response
Open

Thanatos9404 wants to merge 6 commits into
mitmproxy:mainfrom
Thanatos9404:server-replay-keep-addon-response

Conversation

@Thanatos9404

Copy link
Copy Markdown

Description

Fixes #6113.

ServerPlayback.request() ran even when a script or an earlier addon had already answered the flow. With server_replay_extra=kill, the client was disconnected while the flow still showed the script's response, which is the case from the issue. With a status code, the response was silently replaced. If a recorded flow matched, its response replaced the script's too.

It now returns early when the flow already has a response or an error, or isn't live. That is the same guard MapLocal and MapRemote use.

The same applies to default addons that answer earlier: ProxyAuth's 407, BlockList and Onboarding. For example, with a matching recording on main, a client that fails proxy auth gets the recorded response instead of the 407.

One behaviour change to note: when a flow is already answered, a matching recording is no longer used up. Later identical requests in non-reuse mode therefore get the recordings one step earlier than before. If you would rather keep the guard to the server_replay_extra branches, as in your comment on the issue, I can narrow it.

New tests in test_serverplayback.py:

  • a response set before server replay is kept with kill, 204 and 404;
  • it is also kept when a recording matches, and the recording stays available for the next request;
  • a killed flow is left alone (on main, kill raises "Flow is not killable").

All of them fail on main. The full test suite passes, and ruff and mypy are clean. This should rebase cleanly with #8365, since the guard runs before the branch that PR moves.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

Thanatos9404 and others added 6 commits November 3, 2026 01:20
Server replay applied server_replay_extra, or a matching recorded response, to flows that a script or another addon had already answered. With kill, the client was disconnected while the flow still showed the script's response. Skip flows that already have a response or an error, or are not live, as MapLocal and MapRemote do.

Fixes mitmproxy#6113

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant