Fallback: use sub-python to update a TOML value when tomlkit is unavailable here. Passes key and value as separate argv parameters and JSON-encodes the value. No exec, no string-built code — so a malicious key or value can never reach the Python parser as code.
(dotted_key, value)
| 10675 | # → next attempts rejected for _AUTH_LOCKOUT_WINDOW seconds. |
| 10676 | # Memory only: resets on process restart. Sufficient on a single-Pi deployment. |
| 10677 | _AUTH_LOCKOUT_THRESHOLD = 5 |
| 10678 | _AUTH_LOCKOUT_WINDOW = 60 |
| 10679 | _auth_attempts = {} # ip -> list[timestamp] of failed attempts |
| 10680 | _auth_attempts_lock = threading.Lock() |
| 10681 | |
| 10682 | |
| 10683 | def _auth_client_ip(): |
| 10684 | # Trust X-Forwarded-For only if explicitly configured; otherwise use remote_addr. |
| 10685 | return request.headers.get('X-Real-IP') or request.remote_addr or 'unknown' |
| 10686 | |
| 10687 | |
| 10688 | def _auth_rate_limited(ip): |
| 10689 | now = time.time() |
| 10690 | with _auth_attempts_lock: |
| 10691 | attempts = [t for t in _auth_attempts.get(ip, []) if now - t < _AUTH_LOCKOUT_WINDOW] |
| 10692 | _auth_attempts[ip] = attempts |
| 10693 | if len(attempts) >= _AUTH_LOCKOUT_THRESHOLD: |
| 10694 | retry_after = int(_AUTH_LOCKOUT_WINDOW - (now - attempts[0])) + 1 |
no test coverage detected