You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(api): return 400 for an asset upload size that is not a positive whole number - #10394
Seven upload endpoints read the declared size with int(request.data.get("size", settings.FILE_SIZE_LIMIT)), so "size": "abc" or null raised and returned a 500, and 0 or a negative size went on to the presigned upload. The space upload endpoint caught text but not 1e400 (an OverflowError), and clamped zero or negative sizes to 1. A small helper, parse_upload_size in plane/utils/upload.py, returns the size as a whole number of at least 1, or None for anything else (text, null, booleans, fractions, infinity, zero or less), and each endpoint answers None with a 400 ({"error": "Invalid size."}, the space endpoint's existing message). A missing size still defaults to FILE_SIZE_LIMIT, and numbers and numeric strings still work.
Changed: user, workspace and project assets in app/views/asset/v2.py, the three upload endpoints in api/views/asset.py, app/views/issue/attachment.py and space/views/asset.py. The public API work item attachment endpoint already handled this and is unchanged.
Type of Change
Bug fix (non-breaking change which fixes an issue)
Test Scenarios
tests/unit/utils/test_upload_size.py: the helper on numbers, numeric strings, fractions, booleans, infinity, NaN and values below 1.
tests/contract/app/test_asset_upload_size_app.py: user and workspace assets reject abc, null, -5, 0, 1.5 and true with a 400, and a number, a numeric string or a missing size still return 200.
tests/contract/api/test_asset_upload_size.py: the public API user asset endpoint rejects the same values and accepts "2048".
The invalid cases fail on preview (500, or 200 for zero and negative sizes). The existing asset tests still pass.
No actionable comments were generated in the recent review.
Walkthrough
Upload endpoints now use a shared parser to validate requested sizes. Invalid sizes return HTTP 400, and valid sizes continue through the existing upload-size limits and upload flow.
Changes: Upload size validation
Layer / File(s)
Summary
Parser and accepted-size rules apps/api/plane/utils/upload.py, apps/api/plane/tests/unit/utils/test_upload_size.py
parse_upload_size accepts positive whole-number values and returns None for invalid values, including booleans, non-positive numbers, and non-integral floats. Unit tests cover these cases.
The listed asset and issue-attachment endpoints use the parser and return HTTP 400 when parsing fails. Contract tests check invalid sizes and valid or omitted sizes on the tested asset routes.
makeplane/plane#9911: Updates issue-attachment upload-size handling with validation for invalid, non-positive, and non-finite sizes.
Suggested reviewers:sriramveeraghanta
Merge Risk: Minimal · up to 95d31
Invalid upload sizes now return a 400 response instead of a server error or an accepted zero or negative size. Valid and omitted sizes behave as before, so merge risk is minimal.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title states the main change: asset upload endpoints now return HTTP 400 for sizes that are not positive whole numbers. This matches the raw summary, which describes parse_upload_size returning No…
Description check
The description follows the repository template. It gives a detailed explanation of the bug and the fix, marks the Bug fix type, lists test scenarios, and includes a reference to issue #10387. The tem…
Linked Issues check
Issue #10387 requires that malformed or null upload sizes return a client error instead of a 500, and that zero or negative sizes are rejected. At head, parse_upload_size in `apps/api/plane/utils/up…
Out of Scope Changes check
All changed files map to the issue scope or to its tests. The changes are: the new helper in plane/utils/upload.py; size parsing in the user, workspace, and project asset endpoints in `app/views/ass…
Full details: Title check
Explanation
The title states the main change: asset upload endpoints now return HTTP 400 for sizes that are not positive whole numbers. This matches the raw summary, which describes parse_upload_size returning None and endpoints answering with 400 for invalid sizes. The title follows the conventional commit format and is specific, though it omits the scope of endpoints covered.
Full details: Description check
Explanation
The description follows the repository template. It gives a detailed explanation of the bug and the fix, marks the Bug fix type, lists test scenarios, and includes a reference to issue #10387. The template's Screenshots and Media section is absent, but it applies only if relevant to this backend change, so the description is mostly complete.
Full details: Linked Issues check
Explanation
Issue #10387 requires that malformed or null upload sizes return a client error instead of a 500, and that zero or negative sizes are rejected. At head, parse_upload_size in apps/api/plane/utils/upload.py returns None for booleans, non-integral floats (including NaN and infinity), non-numeric text, None, and values below 1. It catches TypeError, ValueError, and OverflowError. Numeric strings such as "2048" and whole numbers parse to integers. The helper is called in the endpoints named by the issue: apps/api/plane/space/views/asset.py (EntityAssetEndpoint.post, which I read directly), the user, workspace, and project endpoints in app/views/asset/v2.py, the three endpoints in api/views/asset.py, and app/views/issue/attachment.py. Per the PR summary, each returns HTTP 400 when the helper returns None. A missing size still defaults to FILE_SIZE_LIMIT. Contract and unit tests cover the invalid and valid cases. I did not read the v2.py, api/views/asset.py, or attachment.py hunks directly. Their behavior rests on the PR summary and the shared helper. The public API work item attachment endpoint is unchanged, as the issue requests.
Full details: Out of Scope Changes check
Explanation
All changed files map to the issue scope or to its tests. The changes are: the new helper in plane/utils/upload.py; size parsing in the user, workspace, and project asset endpoints in app/views/asset/v2.py; the three endpoints in api/views/asset.py; app/views/issue/attachment.py; space/views/asset.py; and the unit and contract tests for these paths. The PR does not change the public API work item attachment endpoint, which the issue excludes. No unrelated refactoring or feature work appears in the summary.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
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
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.
Description
Seven upload endpoints read the declared size with
int(request.data.get("size", settings.FILE_SIZE_LIMIT)), so"size": "abc"ornullraised and returned a 500, and0or a negative size went on to the presigned upload. The space upload endpoint caught text but not1e400(anOverflowError), and clamped zero or negative sizes to 1. A small helper,parse_upload_sizeinplane/utils/upload.py, returns the size as a whole number of at least 1, orNonefor anything else (text,null, booleans, fractions, infinity, zero or less), and each endpoint answersNonewith a 400 ({"error": "Invalid size."}, the space endpoint's existing message). A missing size still defaults toFILE_SIZE_LIMIT, and numbers and numeric strings still work.Changed: user, workspace and project assets in
app/views/asset/v2.py, the three upload endpoints inapi/views/asset.py,app/views/issue/attachment.pyandspace/views/asset.py. The public API work item attachment endpoint already handled this and is unchanged.Type of Change
Test Scenarios
tests/unit/utils/test_upload_size.py: the helper on numbers, numeric strings, fractions, booleans, infinity, NaN and values below 1.tests/contract/app/test_asset_upload_size_app.py: user and workspace assets rejectabc,null,-5,0,1.5andtruewith a 400, and a number, a numeric string or a missing size still return 200.tests/contract/api/test_asset_upload_size.py: the public API user asset endpoint rejects the same values and accepts"2048".The invalid cases fail on
preview(500, or 200 for zero and negative sizes). The existing asset tests still pass.References
Fixes #10387
Summary by CodeRabbit