fix: apply upload guards and rate limiting to /api/analyze_stream (#778)#780
fix: apply upload guards and rate limiting to /api/analyze_stream (#778)#780Suyash2527 wants to merge 3 commits into
Conversation
Thanks for creating a PR for your Issue!
|
|
Hi @neeru24 👋 I've pushed the fixes to patch the security bypass on the Since this addresses a critical vulnerability, could you please take a look when you have a moment? Also, as you are the project owner, could you kindly help assign the appropriate labels to this PR (such as Thank you! Let me know if you need any changes made to the code. |
|
Hi @neeru24 👋 We noticed that the CI Here is what's happening:
We pushed a commit to disable Since the |
What does this PR do?
This PR secures the
POST /api/analyze_streamendpoint by applying the same upload guards and rate limiting protections that are currently in place for/api/analyze. Previously, this streaming endpoint was missing these protections, allowing attackers to bypass rate limits, size enforcement, and magic-byte validation while triggering full ML inference.Related Issue
Closes #778
Changes made
@limiter.limitdecorator to enforce theAPI_UPLOAD_RATE_LIMIT(e.g. 10 requests per minute).enforce_request_size(get_upload_max_bytes())to strictly cap the uploaded file size.cv2.imdecodewithread_validated_upload_image()to enforce magic-byte file validation and securely read the file into memory.try/except/finallyblock to ensurecleanup_temp_upload()is called, preventing temporary files from lingering in memory/disk after streaming completes.Checklist