-
Notifications
You must be signed in to change notification settings - Fork 85
fix(logging): handle credential redaction in some cases with special characters MONGOSH-2991 #2581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| const hiddenCommands = new RegExp(HIDDEN_COMMANDS, 'g'); | ||
|
|
||
| if (hiddenCommands.test(history[0])) { | ||
| if (shouldRedactCommand(history[0])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just so I understand right, we always redact data from history if it's a redactable command, 'redact-sensitive-data' | 'keep-sensitive-data' only handles the other cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mongosh/packages/cli-repl/src/mongosh-repl.ts
Lines 565 to 573 in f3ff98c
| if (this.redactHistory !== 'keep') { | |
| const history: string[] = (repl as any).history; | |
| changeHistory( | |
| history, | |
| this.redactHistory === 'remove-redact' | |
| ? 'redact-sensitive-data' | |
| : 'keep-sensitive-data' | |
| ); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah cool, it'd be nice to move the whole logic into the function and make that enum include "keep"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates credential redaction functionality by migrating from internal @mongosh/history utilities to the standardized mongodb-redact package (v1.3.0). This improves handling of connection strings with special characters and prevents logging of sensitive commands like authentication operations.
Key changes:
- Replaced
redactURICredentialswithredactConnectionStringandHIDDEN_COMMANDSregex withshouldRedactCommand - Updated
mongodb-redactdependency to v1.3.0 across multiple packages - Added early-return checks in logging to skip sensitive commands entirely rather than just redacting them
Reviewed Changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shell-evaluator/src/shell-evaluator.ts | Switched from HIDDEN_COMMANDS regex to shouldRedactCommand function and redactSensitiveData to redact |
| packages/shell-api/src/shell-instance-state.ts | Updated to use redactConnectionString with empty string fallback |
| packages/shell-api/src/shard.ts | Replaced redactURICredentials with redactConnectionString |
| packages/shell-api/src/replica-set.ts | Replaced redactURICredentials with redactConnectionString |
| packages/shell-api/src/mongo.ts | Updated URI redaction calls to use redactConnectionString |
| packages/shell-api/src/field-level-encryption.ts | Replaced redactURICredentials with redactConnectionString |
| packages/shell-api/src/database.ts | Migrated from HIDDEN_COMMANDS regex to shouldRedactCommand function |
| packages/shell-api/src/collection.ts | Replaced HIDDEN_COMMANDS regex with shouldRedactCommand |
| packages/shell-api/package.json | Updated mongodb-redact to v1.3.0 |
| packages/logging/src/logging-and-telemetry.ts | Added early-return guards for sensitive commands and updated redaction function calls |
| packages/logging/src/logging-and-telemetry.spec.ts | Added comprehensive test coverage for sensitive command filtering |
| packages/logging/package.json | Updated mongodb-redact to v1.3.0 and removed @mongosh/history dependency |
| packages/history/src/index.ts | Removed re-exports of redaction utilities now handled by mongodb-redact |
| packages/history/src/history.ts | Migrated to use shouldRedactCommand and redact from mongodb-redact |
| packages/history/package.json | Updated mongodb-redact to v1.3.0 and removed mongodb-connection-string-url |
| packages/cli-repl/src/smoke-tests.ts | Replaced redactURICredentials with redactConnectionString |
| packages/cli-repl/src/run.ts | Updated to use redactConnectionString |
| packages/cli-repl/src/cli-repl.ts | Replaced both redactURICredentials and redactSensitiveData with new functions |
| packages/cli-repl/package.json | Updated mongodb-redact to v1.3.0 and removed unused dependency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }); | ||
|
|
||
| onBus('mongosh:evaluate-input', (args: EvaluateInputEvent) => { | ||
| // Skip logging sensitive commands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's still log something so that the log file isn't silently incomplete
| }); | ||
|
|
||
| onBus('mongosh:api-call-with-arguments', (args: ApiEventWithArguments) => { | ||
| if (shouldRedactCommand(args.method)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We explicitly decide which args to pass to this event; e.g. for createUser, we do not pass any:
mongosh/packages/shell-api/src/database.ts
Line 569 in e9f6465
| this._emitDatabaseApiCall('createUser', {}); |
If we think that this isn't sufficient protection, then we should similarly here just hide args instead of not logging at all
|
Fully green CI 🥹 |
From updates in mongodb-js/devtools-shared#597 and mongodb-js/devtools-shared#599, this both...