fix: handle dict config in is_allowed() and _validate_allow_from()

getattr() on a dict never finds custom keys — it only searches
object attributes, not dict keys. When channel config is loaded as
a Pydantic extra field (which is a plain dict), getattr(config,
'allow_from', []) always returns the default [], causing all access
to be denied regardless of the allowFrom configuration.

Fix both is_allowed() and _validate_allow_from() to use isinstance
checks, falling back to dict.get() for dict configs while preserving
getattr() for object-style configs.
This commit is contained in:
samy
2026-04-15 01:26:51 +08:00
committed by Xubin Ren
parent 89bf5d29d1
commit 73cf9a220b
2 changed files with 10 additions and 2 deletions
+4 -1
View File
@@ -116,7 +116,10 @@ class BaseChannel(ABC):
def is_allowed(self, sender_id: str) -> bool:
"""Check if *sender_id* is permitted. Empty list → deny all; ``"*"`` → allow all."""
allow_list = getattr(self.config, "allow_from", [])
if isinstance(self.config, dict):
allow_list = self.config.get("allow_from") or self.config.get("allowFrom") or []
else:
allow_list = getattr(self.config, "allow_from", [])
if not allow_list:
logger.warning("{}: allow_from is empty — all access denied", self.name)
return False