fix: harden Flask REST API uploads#13760
Conversation
Automated security fix generated by Orbis Security AI
|
👋 Hello @orbisai0security, thank you for submitting a To ensure a seamless integration of your work, please review the following checklist:
For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀 |
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review
Made with ❤️ by Ultralytics Actions
Good security-focused cleanup overall: the extension allowlist, image verification, and localhost default all move this example in the right direction. The two gaps to address are that invalid images currently bubble up as 500s, and the 16 MB limit is not enforced early enough to stop oversized multipart requests from being accepted.
💬 Posted 2 inline comments
|
Thanks for the security hardening PR; before review, please add or point to a focused regression test for rejected non-image or oversized uploads and note the localhost bind behavior change in the PR description, as outlined in the Development Workflow. |
|
Thanks, I’ve added focused Flask test-client regression coverage. |
|
Thanks for adding the regression tests; please also update the PR description with the local validation you ran and explicitly call out the default bind change to |
glenn-jocher
left a comment
There was a problem hiding this comment.
Reviewed the final diff and follow-up maintainer commit. The upload hardening now catches malformed images as 400s, enforces Flask-level request size limits with JSON 413 responses, documents the localhost default bind behavior, and includes focused Flask test-client regression coverage. Local validation passed for the focused pytest file, py_compile, and ruff on touched files; CI is green.
|
@orbisai0security thanks for the security hardening contribution. I merged this after adding one small maintainer follow-up so Flask-level oversized multipart rejections return the same JSON 413 response as the handler path, tightening the oversized-upload regression test, resolving the review threads, and updating the PR description with the local validation and |
Summary
Hardens the demo Flask REST API upload path by rejecting unsupported, malformed, and oversized image uploads before inference.
Vulnerability
V-001utils/flask_rest_api/restapi.py:25The endpoint previously accepted uploaded files without type or size validation before passing them to image parsing and inference.
Changes
PIL.Image.verify()validation for uploaded files.0.0.0.0to127.0.0.1to avoid exposing the demo API on all interfaces by default.Behavior Change
The demo server now binds to
127.0.0.1by default. Users who previously accessed it remotely via the default all-interface bind will need to make an intentional host/proxy configuration change.Validation
PYTHONPATH=$PWD pytest -q -c /dev/null -p no:cacheprovider tests/test_flask_rest_api.py(4 passed)python -m py_compile utils/flask_rest_api/restapi.py tests/test_flask_rest_api.pyruff check utils/flask_rest_api/restapi.py tests/test_flask_rest_api.pyAutomated security fix by OrbisAI Security