Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

My security hook silently stopped guarding. The bug was one line of encoding.

This is a submission for DEV's Summer Bug Smash: Clear the Lineup powered by Sentry . Project Overview I run a set of local policy guards around an AI coding agent. They are ordinary PreToolUse hooks: before the agent is allowed to perform an action, the proposed tool call is handed to a small Python script as JSON on stdin . The contract is two exit codes. exit 0 → allow exit 2 → block, and send…

The bug in a security hook, which ensured an AI coding agent followed strict guidelines, went unnoticed for weeks. This hook examined tool calls before they were executed, returning an exit code of 0 to permit or 2 to block access. One hook protected the agent from reading files with corrupted tool call syntax. This particular hook, malformed-read-guard.py, failed to perform its duty for specific files.

When encountering files with non-ASCII paths, the hook erroneously blocked the agent's access, while files with ASCII paths were permitted access without issue. The root cause lay in how the hook processed JSON data from stdin. On Windows, sys.stdin defaulted to using the locale encoding (cp932), leading the hook to decode UTF-8 data as cp932.

This resulted in corrupted paths being misinterpreted as actual files, bypassing the security guard. The fix was a simple one-line adjustment: reading the data as bytes and explicitly decoding it as UTF-8. This ensured that all paths, regardless of their encoding, were accurately handled by the hook.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Monday 17 August →