@@ -13,6 +13,7 @@ import (
1313 "errors"
1414 "fmt"
1515 "io"
16+ "maps"
1617 "net"
1718 "os"
1819 "os/exec"
@@ -39,7 +40,7 @@ import (
3940// serverHandshake+serverAuthenticate:
4041// PublicKeyCallback:
4142// PublicKeyHandler (our code):
42- // clear (ctx.Permissions) and set ctx.Permissions.giteaKeyID = keyID
43+ // reset (ctx.Permissions) and set ctx.Permissions.giteaKeyID = keyID
4344// pubKey.Verify
4445// return ctx.Permissions // only reaches here, the pub key is really authenticated
4546// set conn.Permissions from serverAuthenticate
@@ -205,6 +206,13 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
205206 // It does NOT really verify here, so we could only record the related information here.
206207 // After authentication (Verify), the "Permissions" will be assigned to the ssh conn,
207208 // then we can use it in the "session handler"
209+
210+ // first, reset the ctx permissions (just like https://github.com/gliderlabs/ssh/pull/243 does)
211+ // it shouldn't be reused across different ssh conn (sessions)
212+ ctxPerm := ctx .Permissions ().Permissions
213+ ctx .Permissions ().Permissions = & gossh.Permissions {}
214+ ctx .Permissions ().Permissions .CriticalOptions = maps .Clone (ctxPerm .CriticalOptions )
215+
208216 setPermExt := func (keyID int64 ) {
209217 ctx .Permissions ().Permissions .Extensions = map [string ]string {
210218 giteaPermissionExtensionKeyID : fmt .Sprint (keyID ),
0 commit comments