-
Notifications
You must be signed in to change notification settings - Fork 8
Feat: Add URL-encoding detection and retry logic for cluster authentication #454
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
base: rel/release-0.7.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -225,17 +225,84 @@ export class DocumentDBClusterItem extends ClusterItemBase implements TreeElemen | |||||||||||||||
| } catch (error) { | ||||||||||||||||
| ext.outputChannel.appendLine(l10n.t('Error: {error}', { error: (error as Error).message })); | ||||||||||||||||
|
|
||||||||||||||||
| void vscode.window.showErrorMessage( | ||||||||||||||||
| // URL-Encoding checks | ||||||||||||||||
| let decodedPassword: string | undefined; | ||||||||||||||||
| try { | ||||||||||||||||
| decodedPassword = password ? decodeURIComponent(password) : undefined; | ||||||||||||||||
| } catch { | ||||||||||||||||
| decodedPassword = undefined; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const retryButton = l10n.t('Retry with Decoded Password'); | ||||||||||||||||
| const buttons: string[] = []; | ||||||||||||||||
|
|
||||||||||||||||
| let detailMessage: string = | ||||||||||||||||
| l10n.t('Revisit connection details and try again.') + | ||||||||||||||||
| '\n\n' + | ||||||||||||||||
| l10n.t('Error: {error}', { error: (error as Error).message }); | ||||||||||||||||
|
|
||||||||||||||||
|
||||||||||||||||
| // Heuristic: detect presence of URL-encoded-looking sequences in the password. | |
| // This does not guarantee that the entire password is URL-encoded or that the | |
| // encoding is valid; some legitimate passwords may contain sequences like "%20" | |
| // and will still trigger this hint. We rely on a successful decode and a changed | |
| // value (password !== decodedPassword) before offering the retry. |
Copilot
AI
Jan 27, 2026
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.
The retry logic doesn't verify that authMethod is specifically NativeAuth before offering to decode the password. While the condition on line 259 checks that username and password exist (which implicitly suggests native auth), it's possible for other auth methods to have these values set. Consider adding an explicit check authMethod === AuthMethodId.NativeAuth to the shouldOfferRetry condition on line 244 to ensure this feature only applies to native authentication where passwords are actually used.
| password && /%[0-9A-Fa-f]{2}/.test(password) && decodedPassword && password !== decodedPassword; | |
| authMethod === AuthMethodId.NativeAuth && | |
| password && | |
| /%[0-9A-Fa-f]{2}/.test(password) && | |
| decodedPassword && | |
| password !== decodedPassword; |
Copilot
AI
Jan 27, 2026
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.
The variable name 'result' shadows the outer variable 'result' from the callWithTelemetryAndErrorHandling callback function scope. This can lead to confusion and potential bugs. Consider renaming this variable to something more specific like 'userResponse' or 'dialogResult' to avoid shadowing.
Copilot
AI
Jan 27, 2026
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.
The URL-encoding detection and retry logic lacks test coverage. This new feature introduces complex conditional logic, user interaction flows, and credential management that should be validated with automated tests. Consider adding tests for: (1) detection of URL-encoded passwords, (2) successful retry with decoded password, (3) failed retry with decoded password, (4) user declining the retry offer, and (5) edge cases like malformed encoding or passwords with legitimate percent sequences.
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.
The error handling uses
(error as Error).messagewithout verifying the error is actually an Error instance. While this works in most cases, it could fail if the caught error is not an Error object. For consistency with the retry error handling (line 289 which usesretryErr instanceof Error), consider using the same defensive pattern to ensure robust error message extraction.