mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-04 04:34:07 +09:00
policy/v2: map no numeric email local part to a login
The client looks a numeric login up as a UID, so 0@domain reached root under a localpart rule, and another number someone else's account.
This commit is contained in:
1 parent
f786ae33cd
commit
6647cb2e05
2 files changed
+19
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -659,6 +660,13 @@ func resolveLocalparts(
|
||||
continue
|
||||
}
|
||||
|
||||
// The client looks a numeric login up as a UID, so 0@domain would
|
||||
// reach root and another number someone else's account.
|
||||
_, notNumeric := strconv.ParseUint(localpart, util.Base10, 32)
|
||||
if notNumeric == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
result[user.ID] = localpart
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3112,6 +3112,17 @@ func TestResolveLocalparts(t *testing.T) {
|
||||
},
|
||||
want: map[uint]string{1: "dave+ssh"},
|
||||
},
|
||||
{
|
||||
name: "numeric local part is not a login",
|
||||
entries: []SSHUser{"localpart:*@example.com"},
|
||||
users: types.Users{
|
||||
{Name: "zero", Email: "0@example.com", ID: 1},
|
||||
{Name: "zeros", Email: "00@example.com", ID: 2},
|
||||
{Name: "employee", Email: "1042@example.com", ID: 3},
|
||||
{Name: "mixed", Email: "1042a@example.com", ID: 4},
|
||||
},
|
||||
want: map[uint]string{4: "1042a"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in new issue
Block a user