Skip to content

The agent that grows with you

fix(line): a non-string channel secret or token reads as unset

kshitijk4poorb278d6528f7a
diff --git a/plugins/platforms/line/adapter.py b/plugins/platforms/line/adapter.py
index eebe3a7f0f1..916714ea95a 100644
--- a/plugins/platforms/line/adapter.py
+++ b/plugins/platforms/line/adapter.py
@@ -342,10 +342,14 @@ def _truthy_env(name: str, default: bool = False) -> bool:
def _credentials(config) -> Tuple[str, str]:
"""Return ``(channel_access_token, channel_secret)`` from scoped secrets, then ``extra``."""
extra = getattr(config, "extra", {}) or {}
- # Stripped: a whitespace-only secret must read as unset, not key the HMAC with blanks.
- return (
- str(_get_scoped_secret("LINE_CHANNEL_ACCESS_TOKEN") or extra.get("channel_access_token") or "").strip(),
- str(_get_scoped_secret("LINE_CHANNEL_SECRET") or extra.get("channel_secret") or "").strip())
+
+ def read(env: str, key: str) -> str:
+ # A whitespace-only or non-string value (YAML ``true``/``0``/null) reads as unset: it must
+ # not key the HMAC with blanks or a guessable str() form such as "True".
+ value = _get_scoped_secret(env) or extra.get(key)
+ return value.strip() if isinstance(value, str) else ""
+
+ return read("LINE_CHANNEL_ACCESS_TOKEN", "channel_access_token"), read("LINE_CHANNEL_SECRET", "channel_secret")
def _coerce(cast: Callable[[Any], Any], value: Any, default: Any) -> Any:
diff --git a/tests/gateway/test_line_plugin.py b/tests/gateway/test_line_plugin.py
index 8f6f74851f8..34fe4a8ce24 100644
--- a/tests/gateway/test_line_plugin.py
+++ b/tests/gateway/test_line_plugin.py
@@ -418,8 +418,8 @@ class TestAdapterInit:
assert ad.channel_access_token == "tok"
assert ad.channel_secret == "sec"
# A whitespace-only secret reads as unset, so connect fails closed instead of keying HMAC with blanks.
- # So does an explicit null (an empty YAML value), which must not become the string "None".
- for blank in (" ", None):
+ # So do null and other non-strings, which must not become guessable keys like "None" or "True".
+ for blank in (" ", None, True, 0):
assert LineAdapter(PlatformConfig(enabled=True, extra={"channel_access_token": "tok",
"channel_secret": blank})).channel_secret == ""
assert LineAdapter(PlatformConfig(enabled=True, extra={"channel_access_token": blank,