{
  "id": 1437288,
  "title": "My security hook silently stopped guarding. The bug was one line of encoding.",
  "url": "https://urgent.news/2026/08/17/my-security-hook-silently-stopped-guarding-the-bug-was-one-line-of",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-17T06:15:30.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/aiq_labs/my-security-hook-silently-stopped-guarding-the-bug-was-one-line-of-encoding-1le8"
  },
  "original_language": "en",
  "account": "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.",
  "summary": "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…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}