Skip to content

mitmweb fails to decode br content when editing. #4809

Closed

Description

@matthewhughes934

Problem Description

EDIT: Actually this looks like a me (read: browser) issue, works fine on Chrome

mitmweb fails to decode br content when editing. The content the editing box is the encoded response content

Steps to reproduce the behavior:

  1. Run mitmproxy

  2. Make a request with a Brotli encoded response using the proxy. For me this works visiting e.g. https://www.google.com/ or https://www.facebook.com/ in Firefox, perhaps a more reproducable example would be with curl:

$ curl --output /dev/null --silent \
    --cacert ~/.mitmproxy/mitmproxy-ca-cert.pem \
    --header 'Accept-Encoding: br' \
    --proxy 127.0.0.1:8080 \
    https://www.facebook.com

(requires curl to be compiled with brotli support)

  1. View the request in the webserver started by mitmproxy. The response should render HTML as expected

  2. Click edit on the response body. The response body is now the encoded request content

System Information

Paste the output of "mitmproxy --version" here.

$ mitmproxy --version
Mitmproxy: 8.0.0.dev (+103, commit 7a1c8b9)
Python:    3.8.6
OpenSSL:   OpenSSL 1.1.1l  24 Aug 2021
Platform:  Linux-5.10.0-0.bpo.8-amd64-x86_64-with-glibc2.28

More Details

In my browser I see the request to get the content data: http://127.0.0.1:8081/flows/<flow-id>/response/content.data is made with Accept-Encoding: gzip, deflate though my browser supports Brotli.

Activity

  1. mhils commented on Sep 16, 2021

    @mhils
    Member

    Yeah, this is a good point! It's usually not a problem because the are few encodings used in practice that are not supported by modern browsers, but the way we currently handle things is less than ideal.

    This dance we do here is stupid:

    content_encoding = message.headers.get("Content-Encoding", None)
    if content_encoding:
    content_encoding = re.sub(r"[^\w]", "", content_encoding)
    self.set_header("Content-Encoding", content_encoding)

    Instead we should just use .content instead of .raw_content and let mitmproxy handle the decompression server-side.

  2. added and removed
    kind/triage
    on Sep 16, 2021
  3. matthewhughes934 commented on Sep 16, 2021

    @matthewhughes934
    ContributorAuthor

    Yeah, this is a good point! It's usually not a problem because the are few encodings used in practice that are not supported by modern browsers

    👍 I was confused in my case, since Firefox does support Brotli encoding, but I think it's due to https://bugzilla.mozilla.org/show_bug.cgi?id=1218924 i.e. Brotli only supported on HTTPS requests and I was accessing mitmweb over http

    Instead we should just use .content instead of .raw_content and let mitmproxy handle the decompression server-side.

    I'd be interested in attempting this

  4. mhils commented on Sep 16, 2021

    @mhils
    Member

    Please, go ahead! If you have any questions please don't hesistate to ask here or ping me on Slack. 😃

  5. matthewhughes934 commented on Sep 18, 2021

    @matthewhughes934
    ContributorAuthor

    Please, go ahead! If you have any questions please don't hesistate to ask here or ping me on Slack. smiley

    Thanks, I had a shot at this with #4811

  6. matthewhughes934 commented on Sep 24, 2021

    @matthewhughes934
    ContributorAuthor

    Resolved with #4811

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions