fix(shared): clone URL rewrite survives passwords that contain @ #27845
Closedsamkelly880(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/27845/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- @@ -2,13 +2,16 @@2233 const SCP_LIKE_URL = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/)(.+)$/;44 const SSH_URL = /^ssh:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;5-const HTTPS_URL = /^https?:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;6576 function parseCloneUrl(87 url: string,98 ): { protocol: CloneProtocol; host: string; path: string; customPort: boolean } | null {109 const trimmed = url.trim();1110 const ssh = SSH_URL.exec(trimmed);1211 if (ssh) return { protocol: "ssh", host: ssh[1]!, path: ssh[3]!, customPort: !!ssh[2] };13- const https = HTTPS_URL.exec(trimmed);14- if (https) return { protocol: "https", host: https[1]!, path: https[3]!, customPort: !!https[2] };12+ // URL() keeps userinfo past an @ in the password; a regex that stops at the first @13+ // would treat that remainder as the host.14+ try {15+ const https = new URL(trimmed);16+ if (https.protocol === "http:" || https.protocol === "https:") {17+ const path = https.pathname.replace(/^\/+/, "");
- packages/shared/src/cloneUrl.ts lines 15 to 16OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2,13 +2,15 @@2233 const SCP_LIKE_URL = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/)(.+)$/;44 const SSH_URL = /^ssh:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;5-const HTTPS_URL = /^https?:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;6576 function parseCloneUrl(87 url: string,98 ): { protocol: CloneProtocol; host: string; path: string; customPort: boolean } | null {109 const trimmed = url.trim();1110 const ssh = SSH_URL.exec(trimmed);1211 if (ssh) return { protocol: "ssh", host: ssh[1]!, path: ssh[3]!, customPort: !!ssh[2] };13- const https = HTTPS_URL.exec(trimmed);14- if (https) return { protocol: "https", host: https[1]!, path: https[3]!, customPort: !!https[2] };12+ // URL() keeps userinfo past an @ in the password; a regex that stops at the first @13+ // would treat that remainder as the host.14+ try {15+ const https = new URL(trimmed);16+ if (https.protocol === "http:" || https.protocol === "https:") {packages/shared/src/cloneUrl.ts line 17OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2,13 +2,16 @@2233 const SCP_LIKE_URL = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/)(.+)$/;44 const SSH_URL = /^ssh:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;5-const HTTPS_URL = /^https?:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;6576 function parseCloneUrl(87 url: string,98 ): { protocol: CloneProtocol; host: string; path: string; customPort: boolean } | null {109 const trimmed = url.trim();1110 const ssh = SSH_URL.exec(trimmed);1211 if (ssh) return { protocol: "ssh", host: ssh[1]!, path: ssh[3]!, customPort: !!ssh[2] };13- const https = HTTPS_URL.exec(trimmed);14- if (https) return { protocol: "https", host: https[1]!, path: https[3]!, customPort: !!https[2] };12+ // URL() keeps userinfo past an @ in the password; a regex that stops at the first @13+ // would treat that remainder as the host.14+ try {15+ const https = new URL(trimmed);16+ if (https.protocol === "http:" || https.protocol === "https:") {17+ const path = https.pathname.replace(/^\/+/, "");packages/shared/src/cloneUrl.ts line 23OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -6,9 +5,19 @@6576 function parseCloneUrl(87 url: string,98 ): { protocol: CloneProtocol; host: string; path: string; customPort: boolean } | null {109 const trimmed = url.trim();1110 const ssh = SSH_URL.exec(trimmed);1211 if (ssh) return { protocol: "ssh", host: ssh[1]!, path: ssh[3]!, customPort: !!ssh[2] };13- const https = HTTPS_URL.exec(trimmed);14- if (https) return { protocol: "https", host: https[1]!, path: https[3]!, customPort: !!https[2] };12+ // URL() keeps userinfo past an @ in the password; a regex that stops at the first @13+ // would treat that remainder as the host.14+ try {15+ const https = new URL(trimmed);16+ if (https.protocol === "http:" || https.protocol === "https:") {17+ const path = https.pathname.replace(/^\/+/, "");18+ if (https.hostname.length === 0 || path.length === 0) return null;19+ return {20+ protocol: "https",21+ host: https.hostname,22+ path,23+ customPort: https.port !== "",
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:gate-failed
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
- @@ -2,4 +2,4 @@2233 const SCP_LIKE_URL = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/)(.+)$/;44 const SSH_URL = /^ssh:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;5-const HTTPS_URL = /^https?:\/\/(?:[^@/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;5+const HTTPS_URL = /^https?:\/\/(?:[^/\s]+@)?([^:/\s]+)(:\d+)?\/(.+)$/;
juliusmarminge removed labelspr:gate-failed
juliusmarminge closed this
Sign in to join this conversation.





macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed