mitmproxy/mitmproxy · error · ValueError

Invalid regular expression {regex!r} ({e})

Error message

Invalid regular expression {regex!r} ({e})

What it means

Error "Invalid regular expression {regex!r} ({e})" thrown in mitmproxy/mitmproxy.

Source

Thrown at mitmproxy/addons/maplocal.py:31

from mitmproxy import flowfilter
from mitmproxy import http
from mitmproxy import version
from mitmproxy.utils.spec import parse_spec


class MapLocalSpec(NamedTuple):
    matches: flowfilter.TFilter
    regex: str
    local_path: Path


def parse_map_local_spec(option: str) -> MapLocalSpec:
    filter, regex, replacement = parse_spec(option)

    try:
        re.compile(regex)
    except re.error as e:
        raise ValueError(f"Invalid regular expression {regex!r} ({e})")

    try:
        path = Path(replacement).expanduser().resolve(strict=True)
    except FileNotFoundError as e:
        raise ValueError(f"Invalid file path: {replacement} ({e})")

    return MapLocalSpec(filter, regex, path)


def _safe_path_join(root: Path, untrusted: str) -> Path:
    """Join a Path element with an untrusted str.

    This is a convenience wrapper for werkzeug's safe_join,
    raising a ValueError if the path is malformed."""
    untrusted_parts = Path(untrusted).parts
    joined = safe_join(root.as_posix(), *untrusted_parts)
    if joined is None:
        raise ValueError("Untrusted paths.")

View on GitHub (pinned to 2ac5b089d9)

When it happens

Trigger: Thrown at mitmproxy/addons/maplocal.py:31 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mitmproxy/mitmproxy@2ac5b089d9 (2026-08-26). Data as JSON: /api/errors/ea63792e42bba85a. Report an issue: GitHub.