# Time-of-Check Time-of-Use (TOCTOU) Race Condition - ID: python-toctou-race-condition - Severity: MEDIUM - CWE: CWE-367 (CWE-367) - Languages: Python ## Description Detects potential race conditions where a resource is checked (exists, permissions) and then used later. Between check and use, the resource state can change, leading to security issues. Use atomic operations or proper locking instead. ## Remediation Use atomic operations instead of check-then-use patterns. ```python def read_file_safely(filename): try: with open(filename, 'r') as f: return f.read() except FileNotFoundError: return None def create_file_safely(filename, content): with open(filename, 'x') as f: # 'x' mode is atomic f.write(content) ``` Learn more: https://shoulder.dev/learn/python/cwe-367/race-condition ## Documentation [object Object]