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.
This commit is contained in:
teknium1 2026-07-24 13:49:16 -07:00 committed by Teknium
parent 7b8a4d74f9
commit cc6e8fa757
3 changed files with 7 additions and 4 deletions

View file

@ -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(

View file

@ -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.")

View file

@ -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"