pythondotorg icon indicating copy to clipboard operation
pythondotorg copied to clipboard

Incorrect Content-Encoding header on .bz2 files breaks proxy downloads

Open JacobCoffee opened this issue 7 months ago • 7 comments

Summary

.bz2 files served from downloads.python.org incorrectly set Content-Encoding: bzip2 in response headers. bzip2 is not a valid HTTP content-encoding value, causing SSL-inspecting proxies to drop the connection with an empty HTTP response.

Current behavior

HTTP/2 200
content-type: application/x-tar
content-encoding: bzip2

The file is not transfer-encoded — it's a .tar.bz2 archive. Setting Content-Encoding: bzip2 tells intermediaries the payload uses bzip2 at the transport layer, which they don't support and may reject per RFC 9110.

Expected behavior

Serve with Content-Type: application/x-bzip2 (or application/x-tar) and no Content-Encoding header. This matches how Apache serves .bz2 files (e.g., downloads.apache.org).

Impact

Users behind SSL-inspecting proxies (corporate/government networks) cannot download .bz2 files from downloads.python.org. Reported via webmaster@ on 2026-04-09.

Likely fix

Update the nginx configuration on the downloads CDN to stop setting Content-Encoding: bzip2 for .bz2 files.

JacobCoffee avatar Apr 09 '26 17:04 JacobCoffee

PYORG-2972

linear[bot] avatar Apr 09 '26 17:04 linear[bot]

imported from an email to webmasters

JacobCoffee avatar Apr 09 '26 17:04 JacobCoffee

I hit this recently with a .tar.gz as well:

$ curl -H 'Accept-Encoding: identity'  -L --head https://downloads.python.org/pypy/pypy3.11-v7.3.23-macos_x86_64.tar.gz
HTTP/2 200
server: nginx
content-type: application/x-tar
content-encoding: gzip
last-modified: Wed, 08 Jul 2026 07:59:51 GMT
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
referrer-policy: strict-origin-when-cross-origin
via: 1.1 varnish, 1.1 varnish
cache-control: max-age=365000000, immutable, public
accept-ranges: bytes
age: 100980
date: Thu, 09 Jul 2026 14:52:31 GMT
x-served-by: cache-fra-eddf8230084-FRA, cache-nyc-kteb1890097-NYC
x-cache: HIT, HIT
x-cache-hits: 7, 0
x-timer: S1783608751.128281,VS0,VE1
strict-transport-security: max-age=31557600
content-length: 28585257

IMO this is a layering violation: the origin should probably be serving octet-stream as the content type, not instructing clients to decompress the tarball into its underlying tar, given that it's verbatim file content.

(This bit us on uv when switching to the tar.gz variants of PyPy distributions: https://github.com/astral-sh/uv/pull/20265. The TL;DR there is that we were silently ignoring the old bzip2 hint since reqwest didn't support it, but as soon as we switched to gzip we began transparently decompressing it and silently corrupting our expected download.)

woodruffw avatar Jul 09 '26 14:07 woodruffw

The backend here is buildbot.pypy.org, so the headers here are coming from their origin:

% curl -H 'Accept-Encoding: identity'  -L --head https://buildbot.pypy.org/pypy/pypy3.11-v7.3.23-macos_x86_64.tar.gz
HTTP/2 200 
server: nginx
date: Thu, 09 Jul 2026 16:09:11 GMT
content-type: application/x-tar
content-length: 28585257
accept-ranges: bytes
content-encoding: gzip
last-modified: Wed, 08 Jul 2026 07:59:51 GMT
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
referrer-policy: strict-origin-when-cross-origin

I think this could be filed with the pypy team to resolve.

ewdurbin avatar Jul 09 '26 16:07 ewdurbin

Fix is live in buildbot.pypy.org is deployed and validated. I've issued a purge all for the CDN, so this should be resolve!

ewdurbin avatar Jul 09 '26 19:07 ewdurbin

Confirmed on my end as well!

curl -H 'Accept-Encoding: identity'  -L --head https://downloads.python.org/pypy/pypy3.11-v7.3.23-macos_x86_64.tar.gz
HTTP/2 200
server: nginx
content-type: application/octet-stream
last-modified: Wed, 08 Jul 2026 07:59:51 GMT
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
referrer-policy: strict-origin-when-cross-origin
via: 1.1 varnish, 1.1 varnish
cache-control: max-age=365000000, immutable, public
accept-ranges: bytes
age: 20346
date: Fri, 10 Jul 2026 01:26:20 GMT
x-served-by: cache-fra-etou8220146-FRA, cache-nyc-kteb1890034-NYC
x-cache: HIT, HIT
x-cache-hits: 4, 0
x-timer: S1783646781.725751,VS0,VE2
strict-transport-security: max-age=31557600
content-length: 28585257

woodruffw avatar Jul 10 '26 01:07 woodruffw

This looks resolved and closeable.

@ewdurbin deployed the fix at the buildbot.pypy.org origin and purged the CDN, and @woodruffw confirmed it at the time. I re-checked just now, on the .tar.gz from the thread and on a .bz2, since that is the file type in the title:

$ curl -H 'Accept-Encoding: identity' -L --head https://downloads.python.org/pypy/pypy3.11-v7.3.23-macos_x86_64.tar.gz
HTTP/2 200
content-type: application/octet-stream
content-length: 28585257

$ curl -H 'Accept-Encoding: identity' -L --head https://downloads.python.org/pypy/pypy2.7-v7.3.17-linux64.tar.bz2
HTTP/2 200
content-type: application/octet-stream

No content-encoding header on either, which is the correct behaviour for an already-compressed archive and what proxies need in order not to double-decode.

Worth noting for anyone finding this later: the cause was upstream at the origin rather than anything in pythondotorg, so there is no code change here to point at.

Flagging rather than closing since I am not a maintainer.

opensource-joe avatar Aug 17 '26 04:08 opensource-joe