{"record":{"id":"a1a1789924662d5b","repo":"can1357/oh-my-pi","slug":"ssh-empty-username-in-url-href-drop-the","errorCode":null,"errorMessage":"ssh://: empty username in \"${url.href}\"; drop the leading '@' or provide a username before it","messagePattern":"ssh://: empty username in \"(.+?)\"; drop the leading '@' or provide a username before it","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/internal-urls/ssh-protocol.ts","lineNumber":202,"sourceCode":"\t// host (+ user) catches the empty port, while a percent-encoded alias like\n\t// `prod%3A` (whose decoded host already ends in `:`) reconstructs to `prod::`\n\t// and is left alone.\n\tconst decodeOr = (s: string): string => {\n\t\ttry {\n\t\t\treturn decodeURIComponent(s);\n\t\t} catch {\n\t\t\treturn s;\n\t\t}\n\t};\n\tif (port === undefined && url.rawHost === `${username ? `${decodeOr(username)}@` : \"\"}${decodeOr(bareHost)}:`) {\n\t\tthrow new Error(`ssh://: empty port in \"${url.href}\"; use ssh://host:<1-65535>/<path> or drop the colon`);\n\t}\n\t// A literal but empty userinfo (`ssh://@host`) sets username to \"\" — WHATWG drops\n\t// the `@` from hostname, but rawHost keeps the leading `@`. A percent-encoded\n\t// alias like `%40prod` decodes to `@prod` in rawHost too, but its hostname keeps\n\t// `%40`, so the reconstruction is `@@prod` and is left alone.\n\tif (username === undefined && url.rawHost === `@${decodeOr(bareHost)}${port !== undefined ? `:${port}` : \"\"}`) {\n\t\tthrow new Error(`ssh://: empty username in \"${url.href}\"; drop the leading '@' or provide a username before it`);\n\t}\n\t// Backstop for any remaining stray/empty authority marker the explicit checks\n\t// above do not name — notably an empty password (`ssh://user:@host`, `ssh://:@host`,\n\t// where `url.password === \"\"`). `rawHost` keeps the literal marker, so it differs\n\t// from the canonical decoded `[user@]host[:port]` WHATWG actually parsed. Every\n\t// valid authority — including percent-encoded reserved-char aliases — reconstructs\n\t// to exactly `rawHost`, so only malformed userinfo trips this.\n\tconst canonicalAuthority = `${url.username ? `${decodeOr(url.username)}@` : \"\"}${decodeOr(bareHost)}${port !== undefined ? `:${port}` : \"\"}`;\n\tif (url.rawHost !== canonicalAuthority) {\n\t\tthrow new Error(\n\t\t\t`ssh://: unsupported or malformed authority in \"${url.href}\"; use ssh://[user@]host[:1-65535]/<absolute-path>`,\n\t\t);\n\t}\n\tconst items = await loadConfiguredHosts(cwd);\n\n\t// A literal user/port in the URL is an authority override. A configured alias\n\t// is addressed only by its (percent-encoded) name, never with a separate\n\t// user/port — so reject an override on a configured bare name, else opaque.","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/internal-urls/ssh-protocol.ts#L184-L220","documentation":"A URL like `ssh://@host/path` has empty userinfo — WHATWG drops the `@` from hostname but `rawHost` keeps the leading `@`. Since a user was clearly intended but none provided, the handler rejects it instead of silently connecting without a username.","triggerScenarios":"Resolving an ssh:// URL whose `rawHost` equals `@<decoded host>[:port]` while `url.username` is undefined — i.e. `ssh://@prod/etc/hosts` or `ssh://@prod:2222/etc/hosts`. A percent-encoded `%40prod` alias does NOT trip this (it reconstructs to `@@prod` and is left alone).","commonSituations":"Deleting a username but leaving the `@`; a template `ssh://${user}@${host}/path` where the user variable was empty; hand-edited URLs.","solutions":["Remove the leading `@` to use the default login user: `ssh://prod/path`","Provide a username before the `@`: `ssh://deploy@prod/path`","Fix the template producing `${user}@` when the user variable is empty"],"exampleFix":"// before\nresolve('ssh://@prod.example.com/etc/hosts')\n// after\nresolve('ssh://deploy@prod.example.com/etc/hosts')","handlingStrategy":"validation","validationCode":"const u = new URL(candidate);\nif (u.protocol === 'ssh:' && !u.username && (u.rawHost ?? '').startsWith('@')) throw new Error(`empty userinfo in ${candidate}; drop '@' or add a username`);","typeGuard":"function hasNonEmptySshUserinfo(u: URL): boolean { return !(u.rawHost ?? '').startsWith('@'); }","tryCatchPattern":"try {\n  const res = await handler.resolve(url, ctx);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('empty username in')) {\n    // drop the '@' or supply a username, then retry\n  } else throw e;\n}","preventionTips":["In templates, render `${user}@` only when the user variable is non-empty","Avoid leaving separators behind when deleting credentials from a URL","Prefer ~/.ssh/config-style user defaults over empty userinfo"],"tags":["ssh","url-parsing","malformed-url"],"backgroundTag":"malformed-url-authority","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}