One-Line Encoding Bug Silently Disabled Python Security Hook on Non-ASCII Paths
A developer running Python-based security hooks to guard an AI coding agent discovered that one hook had been silently failing for an unknown period of time. The bug caused the hook to allow file reads it was supposed to block whenever the file path contained non-ASCII characters, such as Japanese folder names. On Windows, Python defaults to reading stdin using the system locale encoding (cp932), which silently corrupted the incoming UTF-8 path string instead of raising an error. The corrupted path then failed an existence check, triggering a fail-open safety valve that exited with code 0, indistinguishable from a normal allow decision. Fixing the issue required just one line — explicitly opening stdin with UTF-8 encoding — after which the hook correctly blocked reads across both ASCII and non-ASCII paths.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in