Skip to content

Redact AWS session token from client repr#2803

Open
NguyenCong2k wants to merge 1 commit into
mongodb:masterfrom
NguyenCong2k:fix-redact-aws-session-token-repr
Open

Redact AWS session token from client repr#2803
NguyenCong2k wants to merge 1 commit into
mongodb:masterfrom
NguyenCong2k:fix-redact-aws-session-token-repr

Conversation

@NguyenCong2k
Copy link
Copy Markdown

Summary

  • redact AWS session tokens in auth mechanism properties before rendering client repr
  • keep existing username/password redaction behavior unchanged
  • add sync and async regression coverage

Test

python -m pytest test\\test_client.py::ClientUnitTest::test_repr_redacts_aws_session_token test\\asynchronous\\test_client.py::AsyncClientUnitTest::test_repr_redacts_aws_session_token -q

Copilot AI review requested due to automatic review settings May 14, 2026 04:36
@NguyenCong2k NguyenCong2k requested a review from a team as a code owner May 14, 2026 04:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR addresses two security/privacy concerns: redacting the AWS session token in MongoClient __repr__ output, and ensuring the OIDC ALLOWED_HOSTS check is performed before reusing a cached authenticator.

Changes:

  • Redact AWS_SESSION_TOKEN in authMechanismProperties when generating client __repr__.
  • Move the OIDC ALLOWED_HOSTS validation in _get_authenticator to run before returning a cached authenticator.
  • Add corresponding tests in both sync and async test suites.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pymongo/synchronous/mongo_client.py Adds redaction helper for AWS session token in _repr_helper.
pymongo/asynchronous/mongo_client.py Mirrors the sync redaction logic for async client.
pymongo/synchronous/auth_oidc.py Reorders allowed-hosts check to occur before cache reuse.
pymongo/asynchronous/auth_oidc.py Mirrors the sync OIDC change for the async path.
test/test_client.py Adds test for AWS session token redaction in repr.
test/asynchronous/test_client.py Async counterpart for repr redaction test.
test/test_auth_oidc.py Tests allowed-hosts check happens before cache reuse.
test/asynchronous/test_auth_oidc.py Async counterpart for allowed-hosts cache test.

Comment thread pymongo/synchronous/mongo_client.py Outdated
Comment on lines +1306 to +1307
for key in redacted:
if key.upper() == "AWS_SESSION_TOKEN":
Comment thread pymongo/synchronous/mongo_client.py Outdated
Comment on lines +1303 to +1310
def redact_auth_mechanism_properties(value: Any) -> Any:
if isinstance(value, dict):
redacted = value.copy()
for key in redacted:
if key.upper() == "AWS_SESSION_TOKEN":
redacted[key] = "<redacted>"
return redacted
return value
Comment thread pymongo/synchronous/auth_oidc.py Outdated
Comment on lines +70 to +71
if credentials.cache.data:
return credentials.cache.data
Comment thread test/test_auth_oidc.py Outdated
Comment on lines +133 to +134
authenticator = _get_authenticator(credentials, ("good.example.com", 27017))
self.assertIs(authenticator, credentials.cache.data)
Comment thread test/test_client.py
Comment on lines +198 to +199
"mongodb://AKIA:SECRET@localhost:27017/"
f"?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:{token}",
@NguyenCong2k NguyenCong2k force-pushed the fix-redact-aws-session-token-repr branch from 9759aeb to fd2ade2 Compare May 14, 2026 04:38
@NguyenCong2k NguyenCong2k force-pushed the fix-redact-aws-session-token-repr branch from fd2ade2 to 24f74fd Compare May 14, 2026 17:06
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.

2 participants