Skip to content

ROADMAP-03 — P0 — read_file byte cap checked on stat but enforced by a second open (TOCTOU) #95

Closed

Description

@getdownandcode

Series: ROADMAP — filed from the 2026-10-27 whole-project assessment · Backlog task: M14-T03 · Priority: P0 · Effort: extra small

Problem

read_file checks the byte cap with stat().st_size, then re-opens the file with read_text(). Between the check and the read, the file can grow — the grown portion is read unbounded (time-of-check / time-of-use gap). Everything else about the sandbox (path containment, symlink defense, FIFO/device blocking) is solid.

Evidence

  • agentkit/tools/builtin/read_file.py:53–57 — the stat size check
  • agentkit/tools/builtin/read_file.py:60 — the second open() / read_text() call

Suggested fix / acceptance criteria

  • Enforce the cap on the actual read: one open, read(max_bytes + 1), then truncate/validate
  • Unit test covers the grow-between-check-and-read path (mock or two-stage write)

Suggested branch / commit

fix/read-file-post-read-bound · fix(tools): enforce read_file byte cap on the actual read

Activity

  1. added
    bugSomething isn't working
    securitySecurity vulnerability or hardening item
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecuritySecurity vulnerability or hardening item

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions