RACE01 Race Condition (TOCTOU)
What this means
SiteShadow flagged a "time-of-check / time-of-use" pattern where the code checks something (like file existence/permissions) and then uses it later, giving an attacker a window to swap or modify the target.
Why it matters
Attackers can change the file between check and use.
- File overwrite/read: attackers can redirect writes/reads to unintended paths via symlinks or path swaps.
- Privilege escalation: race conditions can bypass authorization checks in edge cases.
- These bugs are hard to reproduce, which often means they survive into production.
Safer examples
1) Use atomic file operations
Open/create with flags that guarantee the check and the use happen together (library/OS dependent).
2) Avoid "check then act" on paths you don't control
Prefer working with file descriptors/handles, not re-resolving paths repeatedly.
3) Use safe temp file patterns
Use platform helpers that create unique files securely rather than manual naming.
How SiteShadow detects it (high level)
- Looks for pairs like
exists()→open(),access()→read/write,stat()→use, especially with user-controlled paths. - Flags risky file patterns commonly associated with TOCTOU.
References
- CWE-362: https://cwe.mitre.org/data/definitions/362.html
---