| 1 | import { |
| 2 | type GitServiceName, |
| 3 | isGitServiceName, |
| 4 | } from '../../../git/git.constants.js'; |
| 5 | |
| 6 | export interface GitSshCommand |
| 7 | service: GitServiceName |
| 8 | username: string; |
| 9 | repo: string; |
| 10 | } |
| 11 | |
| 12 | /** `git-upload-pack '/octocat/hello.git'` - the two commands an SSH session may carry, and nothing else. Both the path and its quoting come from the client, so neither is trusted further than this regex. */ |
| 13 | const GIT_COMMAND = |
| 14 | /^(git-upload-pack|git-receive-pack) '? |
| 15 | |
| 16 | /** Returns null for anything that is not one of the two git services; the caller answers those without running a thing. */ |
| 17 | export function parseGitCommand(command |
| 18 | const match = |
| 19 | if (!match) |
| 20 | |
| 21 | const [, service, |
| 22 | if (!isGitServiceName(service |
| 23 | // A name may carry dots, but only as separators: `..` is the one that walks out of the namespace. |
| 24 | if (username.includes |
| 25 | |
| 26 | return { service, |
| 27 | } |