Skip to content

MLE-34235: [Python Client][Security] Cloud token bootstrap bypasses session settings and can use plaintext HTTP - #158

Merged
ngodugu-marklogic merged 1 commit into
developfrom
MLE-34235
Nov 20, 2026
Merged

ngodugu-marklogic merged 1 commit into
developfrom
MLE-34235

Conversation

@ngodugu-marklogic

Copy link
Copy Markdown

This PR hardens cloud token bootstrap for security and reliability.

Summary:

  1. Enforces HTTPS when cloud API key auth is used, including when base_url is provided directly, and raises ValueError for non-HTTPS URLs.
  2. Uses the existing Session for token bootstrap instead of requests.post, so session transport settings (for example proxies/cert) are honored.
  3. Adds an explicit timeout to cloud token requests to avoid unbounded waits.
  4. Emits a warning when verify=False is used with cloud auth.

Tests:

  1. Added targeted security regression tests for HTTPS enforcement, timeout propagation, and verify=False warning.
  2. New tests pass: 3 passed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cloud authentication has two critical defects: configured base paths corrupt token endpoints, and token responses reset the renewal guard, allowing repeated 401 responses to trigger recursion instead of stopping after one retry.

2 open issues
What changed in this PR

This PR hardens cloud API-key authentication in the Python client by enforcing HTTPS and using the existing session for token requests.

Changes:

  • Rejects non-HTTPS cloud base URLs and warns when certificate verification is disabled.
  • Routes token requests through the session with a 30-second timeout.
  • Adds targeted security regression tests and a Code Sight configuration.
File Description
tests/​test_cloud_auth_security.py Tests HTTPS enforcement, token timeout, and the verification warning.
marklogic/​cloud_auth.py Uses session-based token requests, adds a timeout, and warns about disabled verification.
marklogic/​client.py Rejects non-HTTPS base URLs when cloud API-key authentication is enabled.
.codesight/​default.json Adds local Code Sight/Polaris scan configuration.

Review effort: Balanced

Comment thread marklogic/cloud_auth.py Resolved
Comment thread marklogic/cloud_auth.py Outdated
Comment on lines +65 to +69
response = self._session.post(
urljoin(self._base_url, "/token"),
data={"grant_type": "apikey", "key": self._api_key},
verify=self._session.verify,
params=params,
timeout=DEFAULT_TOKEN_REQUEST_TIMEOUT,
@ngodugu-marklogic ngodugu-marklogic changed the title MLE-34235: [[Python Client][Security] Cloud token bootstrap bypasses session settings and can use plaintext HTTP MLE-34235: [Python Client][Security] Cloud token bootstrap bypasses session settings and can use plaintext HTTP Nov 19, 2026
@ngodugu-marklogic
ngodugu-marklogic force-pushed the MLE-34235 branch 2 times, most recently from 4aa1839 to 310eca6 Compare November 19, 2026 08:20
Comment thread .codesight/default.json Resolved
Comment thread marklogic/cloud_auth.py Resolved
@ngodugu-marklogic
ngodugu-marklogic merged commit 0e30926 into develop Nov 20, 2026
4 checks passed
Sign up for free to 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.

4 participants