Fix/python apis length validation - #933
Open
onkar0127 wants to merge 4 commits into
Open
Conversation
…ility and test failures
|
@onkar0127 is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
RESOLVES #839
PR Description:
Problem Summary
While the Node.js API gateway strictly enforces a maximum payload length of 5,000 characters on incoming prediction requests, the Python ML APIs (both the Flask and FastAPI servers) had no string length validation checks. This exposed the services to potential denial-of-service (DoS) and Out-of-Memory (OOM) attacks if clients hit the Python services directly.
Additionally, two pre-existing regressions blocked the Python backend test suite from executing cleanly:
/imap/...route handlers frombackend/api.py, causing route-matching failures on incoming internal requests.io.TextIOWrapperon the raw request file stream inbulk_predict.pytriggeredAttributeError: 'SpooledTemporaryFile' object has no attribute 'readable'crashes when uploading files in Python 3.10+ environments.Key Changes
1. Payload Length Validation
backend/api.py):MAX_MESSAGE_LENGTHto5000(down from10000)./predictroute handler which was bypassing the length validation and other processing pipeline components.fastapi_backend/main.py):Fieldconstraints on thePredictInschema to restrict the string length of thetextfield to a maximum of 5,000 characters:2. SpooledTemporaryFile Bulk Predict Fix
backend/bulk_predict.pyio.TextIOWrapperstream wrapper with memory-buffered reading and standardio.StringIOwrapping.3. Restored Missing IMAP Routes
backend/api.py/imap/status,/imap/schedule,/imap/disconnect,/imap/scan-now,/imap/scan-results) with proper request decorators.Verification and Testing