| 1 | import { |
| 2 | type GitServiceName, |
| 3 | isGitServiceName, |
| 4 | } from '../protocol/git-service.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 | } |
| 28 | |
| 29 | export interface LfsAuthenticateCommand |
| 30 | username: string; |
| 31 | repo: string; |
| 32 | operation: 'download |
| 33 | } |
| 34 | |
| 35 | const LFS_AUTHENTICATE = |
| 36 | /^git-lfs-authenticate '?\/?( |
| 37 | |
| 38 | /** `git-lfs-authenticate octocat/hello.git upload` - how git-lfs asks an SSH remote for HTTPS credentials. */ |
| 39 | export function parseLfsAuthenticateCommand( |
| 40 | command: string, |
| 41 | ): LfsAuthenticateCommand | |
| 42 | const match = |
| 43 | if (!match) |
| 44 | |
| 45 | const [, username, |
| 46 | if (username.includes |
| 47 | return { username, |
| 48 | } |