Skip to content

net.tls: handle SSL.Error from set_min/max_proto_version in is_supported_version - #8294

Merged
mhils merged 3 commits into
mitmproxy:mainfrom
gaurav0107:fix/8264-is-supported-version-raises-unhandled-op
Aug 20, 2026
Merged

net.tls: handle SSL.Error from set_min/max_proto_version in is_supported_version#8294
mhils merged 3 commits into
mitmproxy:mainfrom
gaurav0107:fix/8264-is-supported-version-raises-unhandled-op

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

Description

mitmproxy.net.tls.is_supported_version() builds an SSL.Context, sets the
min/max protocol version, then probes support with client_conn.recv(). Only
the recv() probe was wrapped in try/except SSL.Error.

On OpenSSL builds that have dropped a protocol version entirely (e.g. SSLv3
after POODLE / CVE-2014-3566, see pyca/cryptography#9523),
set_min_proto_version(SSL3_VERSION) raises SSL.Error immediately at
context-setup time — before the guarded recv(). The exception then
propagated unhandled and crashed callers. The only production caller,
TlsConfig._warn_unsupported_version, iterates over every Version to build
the "supported versions" list, so on those builds option validation crashed
outright.

This moves the protocol-version setters and connection setup inside the
existing try, so a setup-time SSL.Error is treated the same as a
probe-time one: the version is reported as unsupported (return False) instead
of raising. Behavior for currently-supported versions is unchanged.

A regression test (test_supported_setup_error) monkeypatches
SSL.Context.set_min_proto_version to raise SSL.Error, reproducing the crash
path deterministically on any OpenSSL build (the existing test_supported[SSL3]
only exercises the recv() path on builds that still allow SSL3 context setup).

Closes#8264

Note: #8254 also touches this function but bundles it with an unrelated CRLF
prettifier fix (#8253) across four files. This PR is a focused, single-concern
alternative scoped to #8264 only; happy to defer to whichever the maintainers
prefer.

Checklist

  • I have updated tests where applicable.
  • I have updated the CHANGELOG (## Unreleased: mitmproxy next).

@gaurav0107
gaurav0107 marked this pull request as ready for review June 29, 2026 01:18
@gaurav0107

Copy link
Copy Markdown
ContributorAuthor

Heads up: the only red check is build (ubuntu-latest, linux-x86_64, debian), which failed at the Run apt-get update container-setup step (before checkout) — a transient apt-mirror hiccup unrelated to this change. Every code check is green: lint, mypy, individual_coverage, the full test matrix across Linux/macOS/Windows and Python 3.12–3.14, codecov/patch, and docs. A re-run of that one job should clear it. Happy to adjust anything on request.

@gaurav0107
gaurav0107force-pushed the fix/8264-is-supported-version-raises-unhandled-op branch from f1798a2 to ad5f556CompareJuly 2, 2026 14:14
@gaurav0107

Copy link
Copy Markdown
ContributorAuthor

Update: I squashed the branch to a single commit (ad5f556) and re-pushed to re-trigger CI. The previously-red build (ubuntu-latest, linux-x86_64, debian) job — which had failed at the apt-get update container-setup step, before checkout — is now green, and the check gate passes as well. All checks are green and the code diff is unchanged (still the same net.tls fix + regression test); verified locally with the test/mitmproxy/net/test_tls.py suite, ruff, and mypy. Ready for review whenever you have a moment.

Comment threadtest/mitmproxy/net/test_tls.py Outdated
…ted_version
is_supported_version() built an SSL.Context, set the min/max protocol
version, then probed support with client_conn.recv(). Only the recv()
probe was wrapped in try/except SSL.Error.
On OpenSSL builds that have dropped a protocol version entirely (e.g.
SSLv3 after POODLE / CVE-2014-3566, see pyca/cryptography#9523),
set_min_proto_version(SSL3_VERSION) raises SSL.Error already at
context-setup time, before the guarded recv(). The exception then
propagated unhandled and crashed callers such as
TlsConfig._warn_unsupported_version, which iterates over every Version to
build the "supported versions" list.
Move the protocol-version setters and connection setup inside the
existing try, so a setup-time SSL.Error is treated the same as a
probe-time one: the version is reported as unsupported (return False)
instead of raising. Behavior for currently-supported versions is
unchanged.
Add a regression test that monkeypatches SSL.Context.set_min_proto_version
to raise SSL.Error, reproducing the crash path deterministically on any
OpenSSL build, and clear the is_supported_version LRU cache around it.
Closesmitmproxy#8264
@gaurav0107
gaurav0107force-pushed the fix/8264-is-supported-version-raises-unhandled-op branch from ad5f556 to 324cf78CompareJuly 23, 2026 19:43
@mhils
mhils enabled auto-merge (squash) August 20, 2026 22:52
@mhils
mhils merged commit f384cb7 into mitmproxy:mainAug 20, 2026
28 checks passed
Sign up for freeto 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.

is_supported_version raises unhandled OpenSSL.SSL.Error for disabled TLS versions (e.g. SSL3)

2 participants

@gaurav0107@mhils