fix: do not negotiate TLS 1.3 when only TLS 1.2 ciphers are supplied#303
Merged
zookzook merged 1 commit intoMay 27, 2026
Merged
Conversation
When the caller passes `ssl_opts.ciphers` without an explicit `ssl_opts.versions`, Erlang's `:ssl` will still attempt TLS 1.3 negotiation if the OTP build supports it. If none of the supplied ciphers match a TLS 1.3 suite, the handshake fails with no automatic fallback to TLS 1.2. In practice this surfaces when the MongoDB server starts negotiating TLS 1.3 (e.g. after a cluster upgrade) and the user's `:ciphers` list only contains TLS-1.2-era suites. `Mongo.MongoDBConnection.Utils.maybe_restrict_versions/1` detects the mismatch and pins `:versions` to `[:"tlsv1.2"]` when the supplied ciphers do not include any TLS 1.3 suite. Callers who explicitly set `:versions` are left untouched. The override is logged at `Logger.warning` so operators see it in production where info-level logs are typically filtered. Also normalizes `opts[:ssl_opts]` to `[]` on the IP-address branch of `defp ssl/2`; previously that branch could pass `nil` to `:ssl.connect/3` if the caller omitted `:ssl_opts`. Unit tests cover charlist / atom / binary / map cipher shapes, mixed TLS 1.2 + TLS 1.3 lists, and the no-op cases (`:ciphers` nil/empty, `:versions` already set). Tests skip cleanly on OTP builds without TLS 1.3.
Owner
|
Thanks for this nice PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the caller passes
ssl_opts.cipherswithout an explicitssl_opts.versions, Erlang's:sslwill still attempt TLS 1.3 negotiation if the OTP build supports it. If none of the supplied ciphers match a TLS 1.3 suite, the handshake fails with no automatic fallback to TLS 1.2.In practice this surfaces when the MongoDB server starts negotiating TLS 1.3 (e.g. after a cluster upgrade) and the user's
:cipherslist only contains TLS-1.2-era suites.Mongo.MongoDBConnection.Utils.maybe_restrict_versions/1detects the mismatch and pins:versionsto[:"tlsv1.2"]when the supplied ciphers do not include any TLS 1.3 suite. Callers who explicitly set:versionsare left untouched. The override is logged atLogger.warningso operators see it in production where info-level logs are typically filtered.Also normalizes
opts[:ssl_opts]to[]on the IP-address branch ofdefp ssl/2; previously that branch could passnilto:ssl.connect/3if the caller omitted:ssl_opts.Unit tests cover charlist / atom / binary / map cipher shapes, mixed TLS 1.2 + TLS 1.3 lists, and the no-op cases (
:ciphersnil/empty,:versionsalready set).