Skip to content

Commit dd9dc38

Browse files
authored
fix(uri): reject repeated deep link parameters (#1196)
A deep link that repeats a query parameter, such as `url=a&url=b`, silently used the first value because `URLSearchParams.get` returns the first match. The handler now shows an error naming the repeated parameter instead.
1 parent 04fd9d8 commit dd9dc38

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
`+`, `(` or `[` are now matched literally instead of mismatching or failing.
1414
- Ping and speed test from an agent in the sidebar now target that agent
1515
instead of the workspace's first agent.
16+
- Deep links that specify a query parameter more than once now show an error
17+
instead of silently using the first value.
1618

1719
## [v1.18.0](https://github.com/coder/vscode-coder/releases/tag/v1.18.0) 2026-11-13
1820

‎src/uri/uriHandler.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ export function registerUriHandler(deps: UriHandlerDeps): vscode.Disposable {
4848
if (!handler) {
4949
throw new Error(`Unknown path ${uri.path}`);
5050
}
51-
await handler({
52-
...deps,
53-
params: new URLSearchParams(uri.query),
54-
});
51+
await handler({ ...deps, params: parseQuery(uri.query) });
5552
} catch (error) {
5653
if (error instanceof UserDeclinedError) {
5754
output.info("URI handling cancelled by the user", summarizeUri(uri));
@@ -80,6 +77,19 @@ export function registerUriHandler(deps: UriHandlerDeps): vscode.Disposable {
8077
});
8178
}
8279

80+
/** `URLSearchParams.get` returns the first of repeated keys; reject them instead. */
81+
function parseQuery(query: string): URLSearchParams {
82+
const params = new URLSearchParams(query);
83+
const seen = new Set<string>();
84+
for (const key of params.keys()) {
85+
if (seen.has(key)) {
86+
throw new Error(`${key} must be specified only once`);
87+
}
88+
seen.add(key);
89+
}
90+
return params;
91+
}
92+
8393
function getRequiredParam(params: URLSearchParams, name: string): string {
8494
const value = params.get(name);
8595
if (!value) {

‎test/unit/uri/uriHandler.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,16 @@ describe("uriHandler", () => {
337337
expectUriError("localWorkspaceFolder must be specified");
338338
});
339339

340+
it("rejects a repeated parameter", async () => {
341+
const t = createTestContext();
342+
343+
await t.open(withUrl("owner=o&workspace=w&url=https://other"));
344+
345+
expectUriError("url must be specified only once");
346+
expect(maybeAskUrl).not.toHaveBeenCalled();
347+
expect(t.commands.open).not.toHaveBeenCalled();
348+
});
349+
340350
it("throws for unknown path", async () => {
341351
const t = createTestContext();
342352

0 commit comments

Comments
 (0)