Skip to content

fix(api): return 400 for an asset upload size that is not a positive whole number - #10394

Open
ashokram-si wants to merge 1 commit into
makeplane:previewfrom
ashokram-si:fix/asset-upload-size
Open

ashokram-si wants to merge 1 commit into
makeplane:previewfrom
ashokram-si:fix/asset-upload-size

Conversation

@ashokram-si

@ashokram-si ashokram-si commented Nov 24, 2026 •

Copy link
Copy Markdown

Description

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.

References

Fixes #10387

Summary by CodeRabbit

  • Bug Fixes
    • Invalid or unsupported file sizes are now rejected with a clear error instead of causing upload failures.
    • File uploads continue to work with valid positive sizes, including numeric strings and requests that omit the size where supported.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.
Endpoint validation and contract tests
apps/api/plane/api/views/asset.py, apps/api/plane/app/views/asset/v2.py, apps/api/plane/app/views/issue/attachment.py, apps/api/plane/space/views/asset.py, apps/api/plane/tests/contract/api/test_asset_upload_size.py, apps/api/plane/tests/contract/app/test_asset_upload_size_app.py
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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • 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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cd06263a-025b-4b6c-ac33-b9157f865b8e
Commits

Reviewing files that changed from the base of the PR and between 723bb17 and 95d31ea.

Files selected for processing: 8

  • apps/api/plane/api/views/asset.py
  • apps/api/plane/app/views/asset/v2.py
  • apps/api/plane/app/views/issue/attachment.py
  • apps/api/plane/space/views/asset.py
  • apps/api/plane/tests/contract/api/test_asset_upload_size.py
  • apps/api/plane/tests/contract/app/test_asset_upload_size_app.py
  • apps/api/plane/tests/unit/utils/test_upload_size.py
  • apps/api/plane/utils/upload.py

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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Asset upload returns 500 when size is not a number, and accepts zero or negative sizes

1 participant