Skip to content

fix: validate Amazon Q SSO connection command inputs - #241

Open
XiaowenMaoA wants to merge 1 commit into
Amazon-Q-Developer:mainfrom
XiaowenMaoA:fix/validate-amazon-q-sso-command
Open

XiaowenMaoA wants to merge 1 commit into
Amazon-Q-Developer:mainfrom
XiaowenMaoA:fix/validate-amazon-q-sso-command

Conversation

@XiaowenMaoA

@XiaowenMaoA XiaowenMaoA commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Validate Amazon Q SSO connection inputs.
  • Require confirmation before connecting.
  • Add unit tests for input validation.

Testing

  • TypeScript compile
  • ESLint and Prettier
  • Unit tests

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@XiaowenMaoA
XiaowenMaoA requested a review from a team as a code owner November 17, 2026 18:32
@XiaowenMaoA
XiaowenMaoA force-pushed the fix/validate-amazon-q-sso-command branch 9 times, most recently from 98ea1f5 to 8def5d7 Compare November 18, 2026 02:08
@XiaowenMaoA
XiaowenMaoA force-pushed the fix/validate-amazon-q-sso-command branch from 8def5d7 to a19e5e8 Compare November 18, 2026 02:32

@XiaowenMaoA XiaowenMaoA left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Validated SSO connection inputs and added unit tests.

@dungdong-aws dungdong-aws left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes. Reviewed at a19e5e8, comparing behavior against main (f1ef1f1). I ran the real modules with a small harness for each case below, on both commits.

Blocking

  1. Existing connections are rejected instead of reused. validateIsNewSsoUrlAsync in the command returns "A connection for this start URL already exists" when a connection to the same host with Amazon Q scopes exists. AuthUtil.connectToEnterpriseSso is built to reuse, add scopes to, or reauthenticate that connection. On this PR, these work on main but fail here:

    • re-running the command while connected;
    • reconnecting an expired connection;
    • selecting a customization (customizationArn / prefix) while signed in;
    • connecting to a second identitycenter.amazonaws.com/ssoins-… instance. The check compares only the host, so a different instance counts as a match.

    Suggest dropping that check from the command (the format check is enough) and adding a test with an existing connection plus a customizationArn.

  2. The region check in OidcClient.create() runs for every stored profile. Auth.getSsoTokenProvider calls it from list, restore, validate, reauthenticate, getSsoAccessToken and sign-out. A stored profile whose region doesn't match the new pattern (for example US-EAST-1, which main accepted, or a future ap-southeast-10) makes Auth.listConnections() throw for all connections. Signing out of that profile also throws and leaves it stored, and the start URL prompter fails. Please validate the region where a new profile is created, or in authorize() and on the connect path, rather than in the shared factory. A stored profile that fails validation should still be listable and removable.

  3. The new modal confirmation breaks programmatic callers. The internal E2E auth suite calls aws.codeWhisperer.connect(source, startUrl, region) and expects a connection. In the extension test host, VS Code refuses modal dialogs, so the command errors without connecting; if nothing answers the dialog, the command never returns. The E2E suite needs a way to skip the prompt, or the prompt should be handled differently for callers that pass arguments. Please coordinate with the E2E owners before merging.

Non-blocking

  • ssoRegionFormatRegex (-\d$) rejects two-digit suffixes and uppercase input. Consider -\d+$ and normalizing case.
  • The command now hard-fails URLs that main accepted and the other sign-in paths only warn on. These include the documented ssoins-….portal.<region>.app.aws and ssoins-….<region>.portal.amazonaws.com portal formats, URLs with a trailing #/ copied from the browser, uppercase hosts, and custom redirect start URLs.
  • The getRegions() check depends on the region provider's state. With only the bundled endpoints it rejects some current regions (e.g. ap-southeast-7), and with an empty provider it rejects everything.
  • The prompt says "This replaces your current Amazon Q connection" even when there is no connection.
  • Tests to add: existing valid/expired connection, dismissed dialog, customization arguments, stored profile with a non-matching region, valid URL variants (alias subdomain, trailing slash, ssoins), and a caller that passes arguments without UI.
  • Please use neutral names in the tests (e.g. "rejects malformed region", example.invalid). Please also edit the earlier PR comment to remove the internal tracking reference.

The checks that reject a path, fragment, userinfo or backslash in the start URL, and a region that changes the host, look good. Calling the command with no arguments behaves the same as before.

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