Fix data leak between mux.cool connections (#3718)

Fix #116
This commit is contained in:
mmmray 2024-08-25 21:02:01 +02:00 committed by GitHub
parent c0c23fdfeb
commit 3dd3bf94d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 144 additions and 1 deletions

View file

@ -40,6 +40,22 @@ func ContextWithOutbounds(ctx context.Context, outbounds []*Outbound) context.Co
return context.WithValue(ctx, outboundSessionKey, outbounds)
}
func ContextCloneOutbounds(ctx context.Context) context.Context {
outbounds := OutboundsFromContext(ctx)
newOutbounds := make([]*Outbound, len(outbounds))
for i, ob := range outbounds {
if ob == nil {
continue
}
// copy outbound by value
v := *ob
newOutbounds[i] = &v
}
return ContextWithOutbounds(ctx, newOutbounds)
}
func OutboundsFromContext(ctx context.Context) []*Outbound {
if outbounds, ok := ctx.Value(outboundSessionKey).([]*Outbound); ok {
return outbounds