Skip to content

Error: ERR_INSUFFICIENT_RESOURCES when using mitmproxy with Brave browser on macOS #7974

@Diwannist

Description

@Diwannist

Problem Description

We may sometimes get the following error in Brave browser on macOS after browsing the web and using language models for hours/days with mitmproxy running through the following command.

Restarting mitmproxy (including turning off and on the Network Extension under Mitmproxy Redirector Extensions in System Settings > General > Login Items and Extensions > Extensions - By App > Mitmproxy Redirector - Network Extension) works to solve the issue.

Error:

ERR_INSUFFICIENT_RESOURCES

Command:

sudo mitmweb \           
  --mode local:Brave\ Browser \
  --set stream_large_bodies=0 \                          
  -s /Users/a/Documents/rewrite_cookies.py

/Users/a/Documents/rewrite_cookies.py:

from mitmproxy import http

def requestheaders(flow: http.HTTPFlow) -> None:
    # Remove Sec-Fetch-Storage-Access header if present
    if "sec-fetch-storage-access" in flow.request.headers:
        flow.request.headers.pop("sec-fetch-storage-access")

def responseheaders(flow: http.HTTPFlow) -> None:
    url = flow.request.pretty_url

    if not any(
        domain in url
        for domain in [
            "chatgpt.com",
            "openai.com",
            "claude.ai",
            "anthropic.com",
            "marginalia-search.com",
            "grok.com",
            "x.ai",
            "chatnoir.eu",
            "peekr.org",
            "qwen.ai",
            "mistral.ai",
            "chat.falconllm.tii.ae",
            "chat.deepseek.com",
            "yandex.com",
            "bing.com",
            "google.com",
            "rightdao.com",
            "clew.se",
            "microsoft.com",
            "prodregistryv2.org",
            "z.ai",
            "stepfun.ai"
        ]
    ):
        return

    # Grab and remove all existing Set-Cookie headers
    cookies = flow.response.headers.get_all("set-cookie")
    if not cookies:
        return
    flow.response.headers.pop("set-cookie")

    for raw in cookies:
        # Split into the name=value pair and attributes
        parts = [p.strip() for p in raw.split(";")]
        name_val = parts[0]
        attrs = {}

        # Parse existing attributes
        for attr in parts[1:]:
            if "=" in attr:
                k, v = attr.split("=", 1)
                attrs[k.lower()] = v
            else:
                attrs[attr.lower()] = None

        # Enforce SameSite=None (replacing any existing setting)
        attrs["samesite"] = "None"
        # Enforce Secure flag
        attrs["secure"] = None

        # Rebuild the Set-Cookie header
        new_cookie = name_val
        for k, v in attrs.items():
            # Capitalize attribute name for output
            k_out = k.capitalize()
            if v is None:
                new_cookie += f"; {k_out}"
            else:
                new_cookie += f"; {k_out}={v}"

        flow.response.headers.add("set-cookie", new_cookie)

Steps to reproduce the behavior:

  1. create the script
  2. use the command
  3. browser for hours/days while using llms

System Information

Mitmproxy: 12.2.0 binary
Python:    3.14.0
OpenSSL:   OpenSSL 3.5.4 30 Sep 2025
Platform:  macOS-26.0.1-arm64-arm-64bit-Mach-O

Checklist

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