Redact AWS session token from client repr#2803
Open
NguyenCong2k wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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_TOKENinauthMechanismPropertieswhen generating client__repr__. - Move the OIDC
ALLOWED_HOSTSvalidation in_get_authenticatorto 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 on lines
+1306
to
+1307
| for key in redacted: | ||
| if key.upper() == "AWS_SESSION_TOKEN": |
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 on lines
+70
to
+71
| if credentials.cache.data: | ||
| return credentials.cache.data |
Comment on lines
+133
to
+134
| authenticator = _get_authenticator(credentials, ("good.example.com", 27017)) | ||
| self.assertIs(authenticator, credentials.cache.data) |
Comment on lines
+198
to
+199
| "mongodb://AKIA:SECRET@localhost:27017/" | ||
| f"?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:{token}", |
9759aeb to
fd2ade2
Compare
fd2ade2 to
24f74fd
Compare
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.
Summary
Test