Fix #448: Enforce /api/metadata upload limits and validate Content-Length - #451
Closed
marioalbu08 wants to merge 1 commit into
Closed
marioalbu08 wants to merge 1 commit into
marioalbu08 wants to merge 1 commit into
Conversation
…rden Content-Length parsing
|
Thanks for the first pull request here. CI needs a maintainer to approve the run before it starts, so it may sit for a bit before anything happens. |
Owner
|
Thanks for this. #449 fixed the same issue about half an hour earlier and is merged now, so I am closing this one as a duplicate. The two were close: both chunk the copy and both fix the Content-Length parsing. #449 also removes the temp file when the write fails for any reason, not only when the size is exceeded, which is what tipped it. To avoid this next time, leave a comment on the issue before you start; I assign within a day and nobody ends up doing the same work twice. There are plenty of open ones under the hacktoberfest label. |
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
Resolves #448 by enforcing the 20MB upload limit on chunked uploads and hardening the
Content-Lengthheader parsing.Changes
check_upload_sizeinweb/security.pyto intercept non-numeric and negativeContent-Lengthheaders and return a clean HTTP 400 instead of causing an unhandled 500 ValueError.shutil.copyfileobjinweb/app.py's_spoolfunction with a chunkedwhile Trueloop that reads 8192 bytes at a time._spoolloop now actively tracksbytes_writtenand aggressively deletes the temporary file and raises an HTTP 413 error if the payload exceedsMAX_UPLOAD_BYTES.test_metadata_upload_size_guard_no_content_lengthandtest_metadata_upload_invalid_content_lengthtotests/test_upload_size_guard.pyusing FastAPI'sTestClientto verify the exact cutoff and HTTP responses.Type of change
Testing
Screenshots
N/A