Skip to content

Validate deployment URLs and reject ambiguous workspace links - #390

Merged
fioan89 merged 17 commits into
mainfrom
fix/deployment-link-parsing
Nov 20, 2026
Merged

fioan89 merged 17 commits into
mainfrom
fix/deployment-link-parsing

Conversation

@fioan89

@fioan89 fioan89 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Toolbox currently decodes the full URI query before splitting it into parameters, then decodes values again. This can change the meaning of a link: folder=notes%26drafts becomes folder=notes plus an unintended drafts parameter, and %252F becomes / instead of the literal %2F.

Deployment URLs also pass validation with components that Toolbox later discards when it selects the deployment. This can make the supplied address differ from the address used for the connection.

This PR:

  • Splits the raw query before decoding each name and value once, so encoded separators stay inside their values. Repeated parameter names are accepted, and the first value wins, including an empty first value.
  • Matches supported link routes exactly, so paths such as /com.coder.toolbox/auth-extra are not treated as OAuth callbacks.
  • Validates deployment URLs before normalization and requires workspace links to specify an HTTP(S) origin: scheme, host, and optional port. Unsupported paths, credentials, queries, and fragments are rejected.
  • Preserves a safe saved deployment base path for the same origin and validates saved addresses before restoring credentials. Invalid or declined links also leave the initial session-restoration state intact.

Toolbox can show the connection step more than once during startup. A
second CLI login could fail after the first succeeded and send the user
back to token entry.

The wizard now starts one connection attempt at a time. A retry waits
for the cancelled attempt to finish, and only the active attempt can
publish a session or report a failure.

Saved sessions restore behind the workspace list. If restoration fails,
the wizard opens the sign-in form so the user can reconnect.
A workspace link for another deployment could leave the previous setup
page visible until Toolbox regained focus.

The provider now displays the replacement wizard as soon as it handles
the link, so setup can continue while Toolbox stays in focus.
The HTTP clients follow redirects automatically, and the CLI downloader attaches deployment headers to configured mirrors. A request can therefore carry credentials outside the intended origin.

Toolbox follows same-origin redirects for reads and scopes authentication headers to the deployment. For CLI versions that support redirect control, Toolbox disables redirects for authenticated commands and generated SSH connections.
Toolbox decodes the URI query before it separates fields and accepts repeated names. It also accepts URL components that it later drops when it selects a deployment.

The URI handler now matches the route exactly, decodes each field once, and rejects duplicate names. Workspace links select an HTTP or HTTPS origin. Toolbox keeps safe configured base paths and validates saved addresses before restoring credentials.
An OAuth credential update can fail after the provider accepts the
session. Treating that error as a failed sign-in sends the user back
to setup even though the workspace connection is active.

The wizard now logs the error and keeps the signed-in session open.
A regression test covers a credential store that rejects the update.
Setup logs the CLI in with the current OAuth token. Calling the token
refresh handler again after sign-in repeats that login and can leave
the CLI and the saved session out of sync.

The wizard now saves the OAuth session directly after setup. The
refresh handler still updates credentials when a running session
receives a new token. A test checks the login count and saved token.
The provider tests use short deployment names and repeat the setup for
several credential choices. This makes it hard to see which deployment
receives a link and which credentials the wizard should use.

The tests name the source and target deployments and cover the restore
choices in a table. Their assertions identify when the CLI signs in
and which workspace page the provider opens.
Setup assumes a token exists when it hands credentials to the CLI.
If the user switches from certificate to token authentication during
setup, a missing token can produce an error with no explanation.

The HTTP client and CLI now use the same token check. The wizard
reports a missing token and skips CLI login for certificate sessions.
Tests cover both paths.
Looking up a page to display can start a CLI sign-in. The wizard also
uses a separate step and a flag to track how the connection started.

The router now starts a saved-session restore when it registers the
wizard. Looking up the page only selects what Toolbox displays. The
wizard records the origin of the connection so a failed restore can
show the sign-in form and repeated callbacks reuse the active job.
The redirects branch predates the latest sign-in fixes. It carries an
older setup wizard and a separate change to the HTTP client.

The merge brings in the reviewed wizard changes and preserves the
redirect restrictions. Session restore uses the updated sign-in flow
when the HTTP client connects to a deployment.
The link parsing branch predates the latest sign-in fixes on its
parent branch. Its workspace links still use the older setup wizard.

The merge brings in the updated redirects branch and preserves the
link validation changes. Valid workspace links use the updated wizard
when they connect to a deployment.
When a link launches Toolbox, the URI handler can run before the
workspace page opens. The handler marks startup complete even if it
rejects the link. The workspace page then prompts the user to sign in
to the deployment that already has a saved session.

The provider now marks startup complete when it accepts a workspace
sign-in or finishes the OAuth exchange. A rejected link leaves the
saved session available for the workspace page to restore.
Base automatically changed from fix/deployment-redirects to main November 13, 2026 21:48
The deployment link parsing branch predates the setup, redirect, and CLI signature updates on main.

The merge keeps those updates and preserves strict link parsing and saved-session restoration. The tests now use the current wizard state model, and the parsing changelog entry remains under Unreleased.

The unit tests and Detekt check pass.
@fioan89
fioan89 requested review from code-asher and untra November 20, 2026 19:56
The link parser rejects repeated parameter names, while production code
uses null assertions that can fail without a useful explanation.

The parser now keeps the first value of each decoded parameter name,
including an empty value. It still splits fields before decoding and
rejects malformed encoding. The replacement character has a named
constant, and readSavedDeploymentUrl describes the store operation.

Workspace filters and TLS reloads use checked local values instead of
null assertions. Relay metrics validate required fields and report clear
errors when data is incomplete. Tests and the changelog describe the
updated behavior.

Validation: 565 tests passed, 10 were skipped, and Detekt completed with
existing warnings.
Several tests qualify assertion and file utility calls even though the
symbols are imported or can be imported without a name conflict.

The tests now call imported assertions, Files, and Paths directly. The
protocol handler tests consistently use Kotlin assertions, so package
qualifiers no longer obscure the checks. Test behavior is unchanged.

Validation: the full suite passed with 565 tests and 10 skips.
Several Kotlin declarations and test cases have inconsistent wrapping,
indentation, or import order.

The affected files now use consistent formatting. Runtime behavior and
test expectations are unchanged.

Validation: the formatting diff was reviewed and git diff --check passed.
The URL validator embeds several checks directly in its when branches,
which makes the conditions harder to read and inspect while debugging.

The validator now gives each condition a descriptive name and keeps the
result branches compact. It handles a missing raw path before evaluating
the conditions, so opaque URIs still return an invalid result.

The validation order and error messages are unchanged. The URL tests now
include an opaque HTTPS URI. URL parser and link-handler tests passed,
and the final style adjustments preserve that behavior.
@fioan89
fioan89 merged commit 4177b30 into main Nov 20, 2026
8 checks passed
@fioan89
fioan89 deleted the fix/deployment-link-parsing branch November 20, 2026 21:12
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.

3 participants