Fix strict_cert proxy bypass and loopback SO_REUSEADDR on Windows - #336
Open
Flerpharos wants to merge 1 commit into
Open
Fix strict_cert proxy bypass and loopback SO_REUSEADDR on Windows#336Flerpharos wants to merge 1 commit into
Flerpharos wants to merge 1 commit into
Conversation
… on Windows _313HTTPAdapter only overrode init_poolmanager, so strict_cert=False had no effect for requests routed through an HTTPS proxy (proxy_manager_for built a pool manager with default strict SSL verification). Store the relaxed ssl_context on the adapter and reuse it in proxy_manager_for too. The loopback auth callback server unconditionally set allow_reuse_address = True. On POSIX this is benign (TIME_WAIT reuse), but on Windows SO_REUSEADDR lets an unrelated process bind the same port while the listener is up, letting it race for the auth_code/email callback. On Windows, disable allow_reuse_address and set SO_EXCLUSIVEADDRUSE instead; POSIX behavior is unchanged. Fixes #327
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.
Fixes #327
Two low-severity networking fixes in
src/labapi/client.py:Proxy TLS bypass:
_313HTTPAdapteronly overrodeinit_poolmanager, so the relaxed SSL context (strict_cert=False, which dropsVERIFY_X509_STRICT) was never applied to requests routed through an HTTPS proxy —proxy_manager_forbuilt its pool manager with default strict verification, silently ignoring the setting. Fixed by storing the builtssl_contexton the adapter and overridingproxy_manager_forto pass the same context through to the parent implementation.Loopback callback SO_REUSEADDR on Windows: the auth callback
TCPServerunconditionally setallow_reuse_address = True. On POSIX this is the benign TIME_WAIT-reuse behavior. On Windows,SO_REUSEADDRinstead permits another local process to bind the same127.0.0.1:<port>while the listener is up, letting it race for theauth_code/emailcallback. Fixed with a platform conditional: on Windows,allow_reuse_addressstaysFalseand aserver_bindoverride setsSO_EXCLUSIVEADDRUSEinstead; POSIX behavior is unchanged.Testing
test_strict_cert_false_relaxes_ssl_for_direct_and_proxied_requests, which asserts the adapter storesssl_contextand thatproxy_manager_forinjects the same context into its pool manager.test_collect_auth_response_blocks_concurrent_bind_on_windows(skipped off Windows), which binds the loopback listener viaclient.collect_auth_response()and asserts a second socket (even withSO_REUSEADDRset) cannot bind the same port. Verified this reproduces the pre-fix vulnerability directly at the socket level (twoSO_REUSEADDRsockets can share a port on Windows) and that the fix blocks it (PermissionError/WinError 10013).uv run pytest --ignore=tests/test_integration.py) five times in a row on Windows to check for rebind flakiness from disablingSO_REUSEADDR: consistently 432 passed, 1 skipped, no flakes.uv run ruff check .anduv run ruff format --check .pass; pre-commit's pyright hook passes on the changed files.🤖 Generated with Claude Code