fix(identity): prevent allowlist ID entries from matching usernames
This commit is contained in:
parent
b4d00c631d
commit
331a7cfa6d
2 changed files with 26 additions and 5 deletions
|
|
@ -59,6 +59,9 @@ func MatchAllowed(sender bus.SenderInfo, allowed string) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep track of explicit username format
|
||||||
|
isAtUsername := strings.HasPrefix(allowed, "@")
|
||||||
|
|
||||||
// Strip leading "@" for username matching
|
// Strip leading "@" for username matching
|
||||||
trimmed := strings.TrimPrefix(allowed, "@")
|
trimmed := strings.TrimPrefix(allowed, "@")
|
||||||
|
|
||||||
|
|
@ -75,12 +78,10 @@ func MatchAllowed(sender bus.SenderInfo, allowed string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match against Username
|
// Match against Username only when explicitly requested via "@username"
|
||||||
if sender.Username != "" {
|
if isAtUsername && sender.Username != "" && sender.Username == trimmed {
|
||||||
if sender.Username == trimmed || sender.Username == allowedUser {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Match compound sender format against allowed parts
|
// Match compound sender format against allowed parts
|
||||||
if allowedUser != "" && sender.PlatformID != "" && sender.PlatformID == allowedID {
|
if allowedUser != "" && sender.PlatformID != "" && sender.PlatformID == allowedID {
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,16 @@ func TestMatchAllowed(t *testing.T) {
|
||||||
allowed: "@alice",
|
allowed: "@alice",
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "plain entry does not match username",
|
||||||
|
sender: bus.SenderInfo{
|
||||||
|
Platform: "discord",
|
||||||
|
PlatformID: "999999",
|
||||||
|
Username: "123456",
|
||||||
|
},
|
||||||
|
allowed: "123456",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "@username does not match",
|
name: "@username does not match",
|
||||||
sender: telegramSender,
|
sender: telegramSender,
|
||||||
|
|
@ -123,6 +133,16 @@ func TestMatchAllowed(t *testing.T) {
|
||||||
allowed: "999|alice",
|
allowed: "999|alice",
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "compound matches by ID when username differs",
|
||||||
|
sender: bus.SenderInfo{
|
||||||
|
Platform: "discord",
|
||||||
|
PlatformID: "123456",
|
||||||
|
Username: "not123456",
|
||||||
|
},
|
||||||
|
allowed: "123456|alice",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "compound does not match",
|
name: "compound does not match",
|
||||||
sender: telegramSender,
|
sender: telegramSender,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue