Skip to content

Require patched Brotli versions for br decoding - #1297

Closed
HJJung8 wants to merge 5 commits into
pydantic:mainfrom
HJJung8:fix-brotli-output-buffer-limit
Closed

HJJung8 wants to merge 5 commits into
pydantic:mainfrom
HJJung8:fix-brotli-output-buffer-limit

Conversation

@HJJung8

@HJJung8 HJJung8 commented Oct 23, 2026 •

Copy link
Copy Markdown

Summary

Closes #1296.

BrotliDecoder calls process() / decompress() with output_buffer_limit, which only exists in Brotli >= 1.2.0 and brotlicffi >= 1.2.0.0. The brotli extra declares minimum versions, but packages that depend on plain httpx2 (for example huggingface_hub) can end up with an older Brotli that happens to be installed already. In that case any br response crashes with TypeError: process() takes no keyword arguments.

This PR checks the importable binding's __version__ once at import time and requires brotli>=1.2.1 or brotlicffi>=1.2.1.0. Earlier releases are vulnerable to CVE-2026-111497 (GHSA-9v8h-qqgm-4m35), as noted in #1311. A binding below the minimum is treated like a missing Brotli install: br is removed from SUPPORTED_DECODERS, so it is no longer advertised in Accept-Encoding. If brotli is too old, brotlicffi is tried next.

The brotli extra is raised to the same minimums, and the missing-decoder error now names them.

Checked against an installed Brotli:

  • Brotli==1.1.0 before: TypeError: process() takes no keyword arguments
  • Brotli==1.2.0 after: br is not supported, and BrotliDecoder() raises Using 'BrotliDecoder', but neither 'brotli>=1.2.1' nor 'brotlicffi>=1.2.1.0' is installed.
  • Brotli==1.2.1 after: br decodes normally

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing HJJung8:fix-brotli-output-buffer-limit (5284c1d) with main (cd6416f)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread tests/httpx2/test_decoders.py Resolved
Comment thread src/httpx2/httpx2/_decoders.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/httpx2/httpx2/_decoders.py Resolved
@mbeijen

mbeijen commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

So the problem with 1.2.0 is that it's vulnerable for CVE-2026-111497 'Node2Shell'. (see #1311, this happened AFTER your PR). So it probably would be better to test for minimum version 1.2.1 instead.

Also, the error ""neither of the 'brotlicffi' or 'brotli' packages have been installed". should be improved/changed to reflect the version number.

Check `brotli>=1.2.1` and `brotlicffi>=1.2.1.0` instead of probing for
`output_buffer_limit`, since earlier releases are vulnerable to
CVE-2026-111497 (GHSA-9v8h-qqgm-4m35). Raise the `brotli` extra to the same
minimums and name them in the missing-decoder error.
@HJJung8 HJJung8 changed the title Treat Brotli without output_buffer_limit support as unavailable Require patched Brotli versions for br decoding Nov 6, 2026
@HJJung8

HJJung8 commented Nov 6, 2026

Copy link
Copy Markdown
Author

Thanks, done in 5284c1d. The import-time check now requires brotli>=1.2.1 / brotlicffi>=1.2.1.0 by __version__ instead of probing output_buffer_limit, the brotli extra uses the same minimums, and the error now reads: "Using 'BrotliDecoder', but neither 'brotli>=1.2.1' nor 'brotlicffi>=1.2.1.0' is installed." I also merged main to pick up #1311.

@Viicos

Viicos commented Nov 7, 2026

Copy link
Copy Markdown
Member

Closing as per #1296 (comment).

@Viicos Viicos closed this Nov 7, 2026
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.

Brotli decoder crashes with Brotli < 1.2.0 when installed without the [brotli] extra (TypeError: process() takes no keyword arguments)

3 participants