toctou

A file checked by its path is then used by the same path, and another process can change it in between.

Group
Code
Runs
On by default
Level
warning
Reads
Every file
Fix
None: which error to handle in place of the check depends on what the code means to do

Why

A call checks a file by its path, as access, os.path.exists, File.exist?, fs.existsSync, or Files.exists do, and a call under that check then opens, creates, removes, or changes the file by the same path. Another process can create, remove, or replace the file between the two, so the use acts on a file the check never saw: it fails, or, where others can write the path, it opens their file. Use the file directly and handle the error it raises when the file is missing or present, or open it once and work through the open handle.

The fix, as Ur suggests it: use the file and handle the error instead of checking it first.

For agents

Never check a file by its path before using it; use it and handle the error, or work through one open handle.

Example

app/cache.py
import os


def clear_cache(path):
    if os.path.exists(path):
        os.remove(path)
What Ur prints
$ ur lint --rule toctou
warning[toctou]: `os.remove` uses `path` after `os.path.exists` checked it, and another process can change the file in between
  --> ./app/cache.py:6:9 function `clear_cache`
  = step 1: ./app/cache.py:5:8 `os.path.exists` checks `path` here
  = step 2: ./app/cache.py:6:9 `os.remove` uses `path` here, under that check
  = hint: use the file and handle the error instead of checking it first
  = see: CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition, MITRE, Common Weakness Enumeration 5.0 (2026-10-28), https://cwe.mitre.org/data/definitions/367.html
0 clone classes and 1 concurrency finding in 1 file

Try it in the playground →

Source

CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition, MITRE, Common Weakness Enumeration 5.0 (2026-10-28).