vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Bind a session token to the connection, not to a field order
16a92c6f424836fdaf267be21e6acff022655300 · Keenan Nemetz · 16d ago · parent bca53bda
Bind a session token to the connection, not to a field order The front door refused every session on a real host. sshd's %C and SSH_CONNECTION carry the same four endpoint values in opposite order — on OpenSSH 9.6p1 %C is server-first, SSH_CONNECTION is client-first, and the man page describes %C the client-first way — so comparing the first two fields compared a server address with a client address. NormalizeClient now sorts the four values. The binding depends on what identifies the connection, which both sides agree on, rather than on an order that is neither documented consistently nor stable. Fewer than four values is refused, so a format change fails closed instead of silently weakening the check to two fields. The regression test uses the pair of strings captured from the host, and pins that a different client port does not canonicalize to the same value. No test caught this because every one of them fed the same string to both sides. A consistent assumption is not a test of the assumption. Closes #313.
forge/sshsession/sshsession.go +20−9
| @@ -23,6 +23,7 @@ import ( | |||
| 23 | 23 | "encoding/hex" | |
| 24 | 24 | "errors" | |
| 25 | 25 | "fmt" | |
| 26 | "sort" | ||
| 26 | 27 | "strings" | |
| 27 | 28 | "time" | |
| 28 | 29 | ||
| @@ -55,8 +56,8 @@ type Token struct { | |||
| 55 | 56 | // Repo and RunID scope a credential session to the job it was minted for. | |
| 56 | 57 | Repo string | |
| 57 | 58 | RunID string | |
| 58 | // Client is the client endpoint the token was minted for, normalized to | ||
| 59 | // "address port". A token presented from anywhere else is refused: the value | ||
| 59 | // Client is the connection the token was minted for, canonicalized by | ||
| 60 | // NormalizeClient. A token presented from anywhere else is refused: the value | ||
| 60 | 61 | // is visible in the forced command's argv, and another local user reading | |
| 61 | 62 | // /proc must not be able to spend it. | |
| 62 | 63 | Client string | |
| @@ -202,16 +203,26 @@ func (s *Store) Prune(now time.Time) (int64, error) { | |||
| 202 | 203 | return res.RowsAffected() | |
| 203 | 204 | } | |
| 204 | 205 | ||
| 205 | // NormalizeClient reduces sshd's %C token or SSH_CONNECTION to the client half: | ||
| 206 | // the address and the port it connected from. The server half is left out | ||
| 207 | // deliberately — it is the same accept either way, and a difference there (NAT, a | ||
| 208 | // second listener) must not turn a good token into a refused one. | ||
| 206 | // NormalizeClient canonicalizes the connection a token is bound to. sshd's %C | ||
| 207 | // token and the SSH_CONNECTION environment variable describe the same TCP | ||
| 208 | // connection with the same four values, but not in the same order: on OpenSSH | ||
| 209 | // 9.6p1, %C expands to "server address, server port, client address, client | ||
| 210 | // port" while SSH_CONNECTION is "client address, client port, server address, | ||
| 211 | // server port" — and sshd_config(5) describes %C the second way, which the | ||
| 212 | // binary does not do. Sorting makes the binding depend on the values, which | ||
| 213 | // identify the connection, rather than on an order that is neither documented | ||
| 214 | // consistently nor stable. | ||
| 215 | // | ||
| 216 | // Four values are required, and a caller that cannot produce them gets a refusal | ||
| 217 | // rather than a weaker check. | ||
| 209 | 218 | func NormalizeClient(s string) (string, error) { | |
| 210 | 219 | fields := strings.Fields(s) | |
| 211 | if len(fields) < 2 { | ||
| 212 | return "", fmt.Errorf("sshsession: %q is not a client endpoint", s) | ||
| 220 | if len(fields) != 4 { | ||
| 221 | return "", fmt.Errorf("sshsession: %q is not a connection's four endpoints", s) | ||
| 213 | 222 | } | |
| 214 | return fields[0] + " " + fields[1], nil | ||
| 223 | sorted := append([]string(nil), fields...) | ||
| 224 | sort.Strings(sorted) | ||
| 225 | return strings.Join(sorted, " "), nil | ||
| 215 | 226 | } | |
| 216 | 227 | ||
| 217 | 228 | func hash(token string) string { | |