Repository navigation
Conversation
BaseHTTPMetadataService passed https_allow_insecure straight to the verify argument of requests, so the default (False) turned certificate validation off and setting the option to True turned it on, the opposite of its documented meaning (CWE-295). Return the negated value instead; a configured https_ca_bundle still takes precedence. The existing test asserted on a sentinel rather than on the returned value, so it could not catch this. Replace it with tests for the default, for https_allow_insecure=True, for a CA bundle with and without the option, and for the verify value passed to requests.request. Fixes cloudbase#219 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: gitranks[bot] <198371943+gitranks[bot]@users.noreply.github.com> Signed-off-by: Pham Khanh Tam <84433497+AI-WFox@users.noreply.github.com>
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 #219.
BaseHTTPMetadataService._verify_https_requestreturnedhttps_allow_insecureas theverifyargument ofrequests.request. With the default (False), requests gotverify=Falseand skipped certificate validation; setting the option toTrueturned validation on. That is the opposite of the option's documented meaning ("Whether to disable the validation of HTTPS certificates"), and it means every HTTPS metadata service built on this class (OpenStack HTTP, EC2, GCE, MAAS, CloudStack, Packet, Oracle Cloud) accepted any certificate by default (CWE-295).Change
cloudbaseinit/metadata/services/base.py: returnnot self._https_allow_insecure. A configuredhttps_ca_bundlestill takes precedence, as before. The docstring now says what the method returns.cloudbaseinit/tests/metadata/services/test_base.py: the old test assertedassertTrue(mock.sentinel.allow_insecure), which is always true, so it never checked the returned value. As requested in TLS certificate verification disabled by default in BaseHTTPMetadataService (CWE-295) #219, tests that fail first:True;https_allow_insecure=TruereturnsFalse;https_allow_insecure;_http_requestpassesverify=Truetorequests.requestby default.Tests
python -m unittest cloudbaseinit.tests.metadata.services.test_base: 29 tests, OK.base.pyreverted tomaster, 4 of the new tests fail (test_verify_https_request,test_verify_https_request_default_verifies,test_verify_https_request_allow_insecure,test_http_request_verifies_certificate_by_default).python -m unittest discover -s cloudbaseinit/tests/metadata -t .: 309 tests; the only error istest_maasservicefailing to import a dependency I did not install, andmastergives the same single error.flake8on both files: clean.Run on Windows, Python 3.13.
Compatibility
Deployments that reach an HTTPS metadata endpoint with an untrusted certificate under the default configuration will now fail certificate validation instead of silently accepting it. They should set
https_ca_bundle(preferred) or, knowingly,https_allow_insecure = True. This probably deserves a line in the release notes.This pull request was written by an AI agent (Claude Opus) and reviewed by me before submission.
Made with GitRanks Contribute and Claude Code (Opus) · Reviewed and submitted by @AI-WFox
Something off? Tell us or opt out in one step. Maintainers are always in control.