Skip to content

Validate map-remote replacement templates during configuration - #8529

Closed
hakarrr wants to merge 5 commits into
mitmproxy:mainfrom
hakarrr:fix/validate-map-remote-replacements
Closed

hakarrr wants to merge 5 commits into
mitmproxy:mainfrom
hakarrr:fix/validate-map-remote-replacements

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Description

map_remote validates the URL regex during configuration, but not its replacement template. Rules such as |example.org|\2, |example.org|\g<missing>, or |example.org|\q are accepted and later raise re.error or IndexError from the request hook.

Validate the replacement with the compiled pattern and an empty input before accepting the rule. This uses the same replacement parser as re.sub, preserves valid numbered/named backreferences and empty replacements, and reports invalid templates as OptionsError with the offending rule and reason.

Five regression cases fail on unchanged main. After the fix:

  • 13 map-remote tests pass, including four valid replacement controls.
  • Addons suite: 548 passed, 1 skipped.
  • Core suite: 2027 passed, 2 skipped, 1 environment failure creating a TUN device. The TUN-device failure also reproduces on unchanged main.
  • uv run --no-sync tox -e lint passes; changed Python files pass the format check.

Checklist

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

hakarrr and others added 5 commits October 26, 2026 02:26
Reject invalid backreferences and malformed escapes before the request hook runs.

Co-authored-by: generaltony007 <[email protected]>
Cover invalid numeric and named groups, malformed escapes, and valid numbered/named/empty/nonmatching replacements.

Co-authored-by: generaltony007 <[email protected]>
Add the configuration-time validation fix to the unreleased changelog.

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

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer review the map-remote replacement-template validation fix and let me know the next step? Please point out any changes needed before it can move forward, or let me know if you'd prefer it closed. Thanks.

@hakarrr hakarrr closed this Nov 17, 2026
@hakarrr
hakarrr deleted the fix/validate-map-remote-replacements 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.

1 participant