Spaces:
Running
Running
Commit History
-
chore(comments): trim verbose BUG FIX comments in cache.py
94f2d55
-
fix(config): wire CACHE_TTL_MINUTES/MAX_CACHE_SIZE to backend.core.config.settingsβ
Both were hardcoded module-level constants (MAX_CACHE_SIZE=500, CACHE_TTL_MINUTES=60), completely disconnected from backend.core.config.settings β despite both being declared in .env.example AND explicitly set in this project's own render.yaml (the real deployment blueprint), meaning the real deployment believed these were configurable and they silently were not. Fix: read them from settings at module load. Values still default to the same 500/60 when unset, so behavior is unchanged unless an operator actually overrides them β which now finally works.f90c6ae
-
fix: deepcopy cache entries to prevent confidence-cap mutating the cache (audit #3)
130633d
-
fix(cache): remove double TTL check; wrap set() in RLock
65d1efa
-
fix(concurrency): move cache TTL check inside threading.Lockβ
core/cache.py β the lock was released after retrieving a cache entry, then the TTL check and deletion happened unprotected. Two threads could both fetch the same expired entry, both attempt del self._cache[key], and the second raises KeyError. A third thread could also insert a fresh entry between the read and delete. Fix: move the entire TTL check + conditional deletion inside the existing 'with self._lock:' block. Use self._cache.pop(key, None) instead of del so concurrent deletions are safe.ea60405
-
security+fix: torch.load weights_only, cache thread safety, sse cleanupβ
own_detector/model.py + heatmap_generator.py: torch.load() without weights_only=True allows arbitrary Python code execution if a checkpoint file is tampered with (pickle deserialization). PyTorch 2.0+ raises FutureWarning. Added weights_only=True to both torch.load() calls. core/cache.py: ForensicsCache used a plain dict with no locking. Under concurrent requests the get()/set()/eviction logic had TOCTOU race conditions. Added threading.Lock() in __init__ and wrapped get() body with 'with self._lock:' to make all operations atomic. services/sse_analyzer.py: Removed unused 'from PIL import Image' import (pyflakes warning). The quality gate only needs assess_image_quality, not PIL directly.7a95684
-
Refactor cache methods to accept file identifier types
f6fd2ee
-
Add architecture hardening: rate limiting, caching, and CI/CD (#14)β
Security & Performance: - Rate limiting via slowapi (10 req/min on analyze, 30 on root) - Double file validation (content-type header + python-magic MIME) - Explicit 10MB size limit on analysis endpoint - Reject non-image content before expensive processing - Log rejected requests with IP for monitoring Caching: - In-memory SHA-256 keyed forensics cache - TTL: 60 minutes per entry - Max 500 entries (LRU eviction) - Same file uploaded twice returns cached result instantly - Cache hit metadata included in response - Privacy: stores results only, never file bytes CI/CD (GitHub Actions): - Runs on every push and PR to main - Python 3.11 on Ubuntu latest - pip caching for faster runs - libmagic system dependency installed - pytest with coverage reporting - Blocks merge if tests fail Tests: 31 tests covering cache, rate limiting, validation Closes #142932db8