From 5ed893aae79a8acde0fcac2a3f0fe66f6ff6dcc5 Mon Sep 17 00:00:00 2001 From: Milky Date: Mon, 16 Nov 2026 20:30:01 +0100 Subject: [PATCH] Send random_tls_extension_order for custom TLS profiles withRandomTLSExtensionOrder was only added to the request payload in the preset branch (client_identifier set). With client_identifier=None and a ja3_string, the option was silently dropped, so the extension order stayed fixed on every connection. Send it for both branches and cover the custom profile with a test. --- tests/unit/test_sessions.py | 8 ++++++++ tls_client/sessions.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index 8a93084..08ae312 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -544,6 +544,14 @@ def test_preset_is_sent_by_name(self, fake_lib): assert fake_lib.sent["withRandomTLSExtensionOrder"] is True assert "customTlsClient" not in fake_lib.sent + def test_random_extension_order_is_sent_with_a_custom_profile(self, fake_lib): + ja3 = "771,4865-4866-4867,0-23-65281-10-11-35-16-5-13-18-51-45-43-27,29-23-24,0" + with Session(client_identifier=None, ja3_string=ja3, random_tls_extension_order=True) as session: + session.get(URL) + + assert "tlsClientIdentifier" not in fake_lib.sent + assert fake_lib.sent["withRandomTLSExtensionOrder"] is True + def test_custom_settings_are_sent_under_the_keys_the_library_expects(self, fake_lib): ja3 = "771,4865-4866-4867,0-23-65281-10-11-35-16-5-13-18-51-45-43-27,29-23-24,0" priority_frames = [{"streamID": 3, "priorityParam": {"weight": 201, "streamDep": 0, "exclusive": False}}] diff --git a/tls_client/sessions.py b/tls_client/sessions.py index 4ccf38f..600ff66 100644 --- a/tls_client/sessions.py +++ b/tls_client/sessions.py @@ -498,6 +498,7 @@ def execute_request( } if certificate_pinning: request_payload["certificatePinningHosts"] = certificate_pinning + request_payload["withRandomTLSExtensionOrder"] = self.random_tls_extension_order if self.client_identifier is None: request_payload["customTlsClient"] = { "ja3String": self.ja3_string, @@ -517,7 +518,6 @@ def execute_request( } else: request_payload["tlsClientIdentifier"] = self.client_identifier - request_payload["withRandomTLSExtensionOrder"] = self.random_tls_extension_order # Sends the request, then with allow_redirects each request a redirect asks for, like requests does. history: list[Response] = []