Skip to content

Commit 759d385

Browse files
Zacharonclaude
andcommitted
fix(shared): reject Azure clone paths containing query or fragment delimiters
The Azure path captures accepted `?` and `#`, so `[email protected]:v3/org?token/project/repo` became `https://dev.azure.com/org?token/project/_git/repo`, whose real path is only `/org`. Exclude both delimiters from each component so such URLs return null instead of a clone URL for the wrong repository. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6b5c112 commit 759d385

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎packages/shared/src/cloneUrl.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ describe("cloneUrlForProtocol", () => {
9090
it("refuses Azure rewrites when the project is missing or a custom port is set", () => {
9191
expect(cloneUrlForProtocol("[email protected]:v3/Fabrikam/fab_repo", "https")).toBeNull();
9292
expect(cloneUrlForProtocol("https://dev.azure.com/Fabrikam/_git/fab_repo", "ssh")).toBeNull();
93+
expect(
94+
cloneUrlForProtocol("[email protected]:v3/Fabrikam?token/Project1/fab_repo", "https"),
95+
).toBeNull();
96+
expect(
97+
cloneUrlForProtocol("https://dev.azure.com/Fabrikam/Project1/_git/fab_repo#main", "ssh"),
98+
).toBeNull();
9399
expect(
94100
cloneUrlForProtocol(
95101
"ssh://[email protected]:2222/v3/Fabrikam/Project1/fab_repo",

‎packages/shared/src/cloneUrl.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export function cloneUrlForProtocol(url: string, protocol: CloneProtocol): strin
3535
// Azure's transports use different hosts and put the repository marker in
3636
// different positions; changing only the scheme produces an invalid clone URL.
3737
if (parsed.protocol === "ssh" && parsed.host.toLowerCase() === "ssh.dev.azure.com") {
38-
const azure = /^v3\/([^/]+)\/([^/]+)\/([^/]+)$/.exec(parsed.path);
38+
const azure = /^v3\/([^/?#]+)\/([^/?#]+)\/([^/?#]+)$/.exec(parsed.path);
3939
return azure ? `https://dev.azure.com/${azure[1]}/${azure[2]}/_git/${azure[3]}` : null;
4040
}
4141
if (parsed.protocol === "https" && parsed.host.toLowerCase() === "dev.azure.com") {
42-
const azure = /^([^/]+)\/([^/]+)\/_git\/([^/]+)$/.exec(parsed.path);
42+
const azure = /^([^/?#]+)\/([^/?#]+)\/_git\/([^/?#]+)$/.exec(parsed.path);
4343
return azure ? `[email protected]:v3/${azure[1]}/${azure[2]}/${azure[3]}` : null;
4444
}
4545
return protocol === "ssh"

0 commit comments

Comments
 (0)