Repository navigation
Conversation
Flask had no MAX_CONTENT_LENGTH configured, so POST /predict-image buffered unbounded request bodies. A crafted multi-GB upload or tiny decompression bomb could exhaust RAM/CPU and OOM-kill gunicorn workers. - Set app.config['MAX_CONTENT_LENGTH'] to ML_MAX_UPLOAD_MB (default 10 MB) - Set Image.MAX_IMAGE_PIXELS to 100M to reject decompression bombs before Pillow fully decodes them - Add @app.errorhandler(413) returning structured JSON instead of Flask's default HTML error page - Catch DecompressionBombError in predict_image and return 413 with details - Import DecompressionBombError from PIL
|
@Kirtan-pc is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel. A member of the Team first needs to authorize it. |
Nitya-003
approved these changes
Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes Issue #1233:
ml-service/app.pynever setsapp.config["MAX_CONTENT_LENGTH"], so Flask buffers unbounded request bodies.POST /predict-imagecallsImage.open()on attacker-controlled bytes; a crafted multi-GB upload or a tiny decompression bomb exhausts RAM/CPU and can OOM-kill the gunicorn workers.Changes
ml-service/app.py(lines 16-22): Setapp.config["MAX_CONTENT_LENGTH"]toML_MAX_UPLOAD_MB(default 10 MB, configurable via env var) so Flask rejects oversized request bodies before buffering them.ml-service/app.py(line 22): SetImage.MAX_IMAGE_PIXELS = 100_000_000(100 megapixels) so Pillow raisesDecompressionBombErrorbefore fully decoding a malicious image.ml-service/app.py(lines 238-243): Added@app.errorhandler(413)returning structured JSON ({"error": "Payload too large", "details": "..."}) instead of Flask's default HTML error page.ml-service/app.py(lines 284-288): CatchDecompressionBombErrorinpredict_imageand return a 413 with a clear message including the pixel limit.ml-service/app.py(line 12): ImportDecompressionBombErrorfrom PIL.Fixes #1233
Copilot Review Feedback
Other suggestions were evaluated but intentionally left unchanged because they are pre-existing issues outside the scope of Issue #1233:
MAX_CONTENT_LENGTHoverridesImage.open()on a stream still reads the full image for dimension validation