Skip to content

Preserve caller value lists in MultiDict.set_all - #8521

Merged
mhils merged 6 commits into
mitmproxy:mainfrom
hakarrr:fix/preserve-multidict-input-values
Oct 25, 2026
Merged

mhils merged 6 commits into
mitmproxy:mainfrom
hakarrr:fix/preserve-multidict-input-values

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Description

MultiDict.set_all() consumes its caller's list with pop(0). This also affects MultiDictView, including Request.query and request cookies.

For example, an addon applying the same query values to two flows silently drops the parameter from the second flow:

values = ["one", "two"]
first.query.set_all("id", values)
second.query.set_all("id", values)

The first call empties values, so the second call removes id rather than assigning it. Copy the list before consuming it. Existing field order, duplicate-key handling, capitalization and removal behavior stay unchanged. This does not change Headers.set_all(), which already materializes its own list.

Tests cover empty, single and multiple replacement values against absent, single and case-insensitive duplicate keys, plus reuse through two real Request.query views while preserving an unrelated parameter. Seven new cases fail on unchanged base 9125647; all ten pass with the fix.

Validation in a separate current-main tree, without the changes from #8518 or #8520:

  • 267 coretype, HTTP helper and HTTP model tests pass.
  • Broader Python run excluding the tools directory: 1877 passed, 1 skipped, one failure creating a TUN device. The same TUN test fails against unchanged source in this environment.
  • Repository-wide Ruff checks pass; changed Python files are formatted.
  • Mypy: no issues in 253 source files.

No full tools test suite, live proxy session or Windows/macOS run was performed.

Checklist

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

@mhils mhils left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mhils
mhils enabled auto-merge (squash) October 25, 2026 18:50
@mhils
mhils merged commit 3f81168 into mitmproxy:main Oct 25, 2026
28 checks passed
@hakarrr

hakarrr commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and merging this and the cookie expiry fix!

lups2000 pushed a commit to lups2000/mitmproxy that referenced this pull request Oct 31, 2026
* fix: preserve caller value lists in MultiDict.set_all

Co-authored-by: generaltony007 <[email protected]>

* test: preserve reusable MultiDict input lists

Co-authored-by: generaltony007 <[email protected]>

* test: reuse query values across requests

Co-authored-by: generaltony007 <[email protected]>

* docs: note preserved MultiDict input values

Co-authored-by: generaltony007 <[email protected]>

* [autofix.ci] apply automated fixes

---------

Co-authored-by: generaltony007 <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Maximilian Hils <[email protected]>
@hakarrr
hakarrr deleted the fix/preserve-multidict-input-values branch November 25, 2026 06:25
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.

2 participants