@@ -45,8 +45,8 @@ import (
4545// set conn.Permissions from serverAuthenticate
4646// sessionHandler(conn)
4747//
48- // Then sessionHandler should only use the "verified keyID" from the conn.
49- // Otherwise, if a users provides 2 keys A and B, if A succeeds to authenticate, sessionHandler will see B's keyID
48+ // Then sessionHandler should only use the "verified keyID" from the original ssh conn, but not the ctx one .
49+ // Otherwise, if a user provides 2 keys A and B, if A succeeds to authenticate, sessionHandler will see B's keyID
5050
5151const giteaPermissionExtensionKeyID = "gitea-perm-ext-key-id"
5252
@@ -75,7 +75,7 @@ func getExitStatusFromError(err error) int {
7575}
7676
7777// sessionPartial is the private struct from "gliderlabs/ssh/session.go"
78- // we need to read the original "conn" field from "ssh.Session interface" which contains the "*session pointer"
78+ // We need to read the original "conn" field from "ssh.Session interface" which contains the "*session pointer"
7979// https://github.com/gliderlabs/ssh/blob/d137aad99cd6f2d9495bfd98c755bec4e5dffb8c/session.go#L109-L113
8080// If upstream fixes the problem and/or changes the struct, we need to follow.
8181// If the struct mismatches, the builtin ssh server will fail during integration tests.
@@ -96,7 +96,8 @@ func ptr[T any](intf any) *T {
9696}
9797
9898func sessionHandler (session ssh.Session ) {
99- // it can't use session.Permissions() because it only use the ctx one, so we must use the original ssh conn
99+ // it can't use session.Permissions() because it only use the value from ctx, which might not be the authenticated one.
100+ // so we must use the original ssh conn, which always contains the correct (verified) keyID.
100101 sshConn := ptr [sessionPartial ](session )
101102 keyID := sshConn .conn .Permissions .Extensions [giteaPermissionExtensionKeyID ]
102103
0 commit comments