From cc6e8fa75726b7b67dc6d5368aa57421bbdf9fa1 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Fri, 24 Jul 2026 13:49:16 -0700 Subject: [PATCH] fix(gateway): extend the utf-8 file-I/O guard to google_chat + whatsapp Follow-up to the salvaged #38985: guard the 4 bare read_text/write_text sites its allowlist missed (google_chat thread-count store + oauth JSON) and add whatsapp/google_chat to the AST guard test's file list. --- plugins/platforms/google_chat/adapter.py | 4 ++-- plugins/platforms/google_chat/oauth.py | 4 ++-- tests/gateway/test_gateway_utf8_encoding.py | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/platforms/google_chat/adapter.py b/plugins/platforms/google_chat/adapter.py index 540f9bf84566..0b73968d92fa 100644 --- a/plugins/platforms/google_chat/adapter.py +++ b/plugins/platforms/google_chat/adapter.py @@ -558,7 +558,7 @@ class _ThreadCountStore: self._counts = {} return try: - raw = self._path.read_text() + raw = self._path.read_text(encoding="utf-8") data = json.loads(raw) if raw.strip() else {} except json.JSONDecodeError as exc: logger.warning( @@ -613,7 +613,7 @@ class _ThreadCountStore: try: self._path.parent.mkdir(parents=True, exist_ok=True) tmp = self._path.with_suffix(self._path.suffix + ".tmp") - tmp.write_text(json.dumps(self._counts, separators=(",", ":"))) + tmp.write_text(json.dumps(self._counts, separators=(",", ":")), encoding="utf-8") os.replace(tmp, self._path) except OSError as exc: logger.warning( diff --git a/plugins/platforms/google_chat/oauth.py b/plugins/platforms/google_chat/oauth.py index b66b0829f29d..1b8c89cb2e4b 100644 --- a/plugins/platforms/google_chat/oauth.py +++ b/plugins/platforms/google_chat/oauth.py @@ -427,7 +427,7 @@ def store_client_secret(path: str) -> None: sys.exit(1) try: - data = json.loads(src.read_text()) + data = json.loads(src.read_text(encoding="utf-8")) except json.JSONDecodeError: print("ERROR: File is not valid JSON.") sys.exit(1) @@ -467,7 +467,7 @@ def _load_pending_auth(email: Optional[str] = None) -> dict: print("ERROR: No pending OAuth session found. Run --auth-url first.") sys.exit(1) try: - data = json.loads(pending.read_text()) + data = json.loads(pending.read_text(encoding="utf-8")) except Exception as exc: print(f"ERROR: Could not read pending OAuth session: {exc}") print("Run --auth-url again to start a fresh session.") diff --git a/tests/gateway/test_gateway_utf8_encoding.py b/tests/gateway/test_gateway_utf8_encoding.py index c900d09d9319..2ecc559e6ad1 100644 --- a/tests/gateway/test_gateway_utf8_encoding.py +++ b/tests/gateway/test_gateway_utf8_encoding.py @@ -15,6 +15,9 @@ UPDATE_RESPONSE_FILES = ( REPO_ROOT / "plugins/platforms/discord/adapter.py", REPO_ROOT / "plugins/platforms/telegram/adapter.py", REPO_ROOT / "plugins/platforms/feishu/adapter.py", + REPO_ROOT / "plugins/platforms/whatsapp/adapter.py", + REPO_ROOT / "plugins/platforms/google_chat/adapter.py", + REPO_ROOT / "plugins/platforms/google_chat/oauth.py", ) METHODS = {"read_text", "write_text"} SUPPRESSION = "# gateway-utf8: ok"