Skip to content

fix: call super().__init__() in S3Storage so location is set - #9942

Merged
sriramveeraghanta merged 3 commits into
previewfrom
fix/s3-storage-location
Nov 18, 2026
Merged

sriramveeraghanta merged 3 commits into
previewfrom
fix/s3-storage-location

Conversation

@pablohashescobar

@pablohashescobar pablohashescobar commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Description

S3Storage is configured as STORAGES["default"], but its __init__ never called super().__init__(). As a result django-storages state such as location was never set, and any direct FileField save raised AttributeError: 'S3Storage' object has no attribute 'location'.

This PR calls super().__init__() at the start of S3Storage.__init__ so the base class initialises its own attributes. The existing credential/bucket setup that follows is unchanged.

Making direct saves work again also brings back the three legacy multipart upload routes (FileAssetEndpoint.post, UserAssetsEndpoint.post, IssueAttachmentEndpoint.post), so this PR hardens them the same way the presigned (v2) routes are:

  • S3Storage.default_acl = None: FileField uploads send no canned ACL, whatever AWS_DEFAULT_ACL says. Objects keep the bucket's default access and are read through presigned URLs.
  • FileAssetSerializer and IssueAttachmentSerializer reject an uploaded file whose declared content type is missing or not in ATTACHMENT_MIME_TYPES, or that is larger than FILE_SIZE_LIMIT, with a 400. One shared function, validate_uploaded_file, covers all three routes. It only runs on upload input; read responses and the v2 routes are unaffected.
  • Merged preview and kept both TestS3StorageDefaultStorage and TestS3StorageObjectMetadata in test_storage.py.

Notes for review:

  • ATTACHMENT_MIME_TYPES includes image/svg+xml, text/xml and application/xml, as it does for the v2 routes. The protection for those is that the object is not publicly readable and downloads are forced to attachment.
  • AWS_DEFAULT_ACL = "public-read" in settings/common.py no longer has any effect and can be removed in a follow-up.
  • The size check stops an oversize file being stored, but Django has already received the body by then.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

  • Unit: TestS3StorageDefaultStorage asserts S3Storage().location == "", that _normalize_name works, and that _get_write_parameters carries no ACL even with AWS_DEFAULT_ACL = "public-read".
  • Contract: test_legacy_upload_validation_app.py covers each of the three legacy routes: text/html and an empty declared type return 400, an oversize file returns 400, image/png returns 201.
  • Run: docker compose -f docker-compose-test.yml run --rm api-tests pytest plane/tests/unit/settings/test_storage.py plane/tests/contract/app/test_legacy_upload_validation_app.py (56 passed together with the existing legacy-route tests; full API suite 1711 passed).
  • Not tested against a real AWS bucket.

References

N/A


Created with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue that could prevent files from uploading to S3 storage.
    • Uploads with unsupported or missing content types, or files exceeding the size limit, are now rejected.
    • S3 uploads no longer apply a default access control setting, even when one is configured.

- `S3Storage` never called `super().__init__()`, so django-storages
  state such as `location` and `bucket_name` was never set up.
- Because `S3Storage` is `STORAGES["default"]`, every direct FileField
  upload failed with `AttributeError: 'S3Storage' object has no
  attribute 'location'`.
- Add a unit test checking that the base attributes are initialised.
Copilot AI balanced review requested due to automatic review settings October 4, 2026 18:02
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Upload serializers now reject files with unsupported declared content types or sizes above the configured limit. S3Storage sets its default ACL to None and initializes its parent storage class. Tests cover both changes.

Changes: Upload validation

Layer / File(s) Summary
Validate uploaded files
apps/api/plane/app/serializers/asset.py, apps/api/plane/app/serializers/issue.py, apps/api/plane/tests/contract/app/test_legacy_upload_validation_app.py
A shared validator checks declared content type and file size. Both serializers use it. Contract tests cover accepted and rejected uploads on legacy routes.

S3 storage initialization

Layer / File(s) Summary
Initialize S3 storage
apps/api/plane/settings/storage.py, apps/api/plane/tests/unit/settings/test_storage.py
S3Storage calls its parent initializer and sets default_acl to None. Tests check storage attributes and confirm that write parameters omit ACL even when AWS_DEFAULT_ACL is set.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: 🛡️security

Merge Risk: Minimal · up to 63411

This fixes FileField saves through the default S3 storage and adds upload type and size validation on the legacy routes. No concrete merge-blocking defect was established. One unverified question remains: deployments using a region-strict S3-compatible endpoint should confirm that AWS_S3_REGION_NAME is set alongside AWS_REGION.

Security architecture risk: Low · up to 7c7a6

The initialization fix is small and leaves custom presigned operations unchanged. However, restored direct file saves may inherit a public-read upload policy. Actual public exposure depends on callers and bucket controls that were not fully established.

Retained concerns

  • Medium · security · inferred: Restored inherited FileField writes may apply the existing public-read upload default to application files. If the bucket accepts that ACL, those objects could be readable outside application authorization. The configuration is observed, but direct-save caller reachability and effective anonymous access remain unverified; this is not a verified disclosure finding.
Security review details

Security Blast Radius

  • inferred — The relevant confidentiality scope is objects written through the restored inherited default-storage path into its configured bucket. No evidence establishes newly gained IAM authority or exposure across other buckets or environments. Effective anonymous readability remains dependent on deployed bucket controls.

Security Findings and Attack Paths

  • inferred — A conditional disclosure path is a successful direct FileField write followed by anonymous retrieval if the existing public-read default is applied and accepted. A concrete sensitive-file caller, accepted object ACL, and anonymous retrieval were not established, so this remains an architecture concern rather than a verified attack path.

Trust Boundaries and Controls

  • observed — The inspected presigned user-upload handler validates entity and MIME types and associates the asset with request.user. Its completion handler selects the asset by both asset ID and user ID. These controls are counterevidence for those handlers, but do not establish authorization or confidentiality for every direct FileField writer.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change: S3Storage.init now calls super().init() so the location attribute is set. The raw summary and objectives confirm this is the main fix. The title is 60 chara…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is thorough and covers the template's required sections. It explains the root cause (S3Storage.init never called super().init(), leaving location unset) and the fix. It lists t…
Full details: Title check

Explanation

The title names the primary change: S3Storage.init now calls super().init() so the location attribute is set. The raw summary and objectives confirm this is the main fix. The title is 60 characters, which is concise and specific. It does not mention the extra ACL override or the upload validation changes, but those are secondary to the bug fix.

Full details: Description check

Explanation

The description is thorough and covers the template's required sections. It explains the root cause (S3Storage.init never called super().init(), leaving location unset) and the fix. It lists the hardening changes for the legacy multipart routes (default_acl = None, shared validate_uploaded_file for MIME type and size). It marks the change as a Bug fix, gives unit and contract test scenarios, a run command with results, and notes what was not tested (real AWS bucket). The Description, Type of Change, and Test Scenarios sections are complete. The Screenshots section keeps a placeholder comment, and the References section says N/A. Both are acceptable for this change. The description also covers scope beyond the title's stated fix (the legacy route validation), which reviewers should be aware of, but it documents that scope clearly.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • 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: ac049576-8058-414a-a832-e962aaa24f37
Commits

Reviewing files that changed from the base of the PR and between 7c7a67e and 6341194.

Files selected for processing: 5

  • apps/api/plane/app/serializers/asset.py
  • apps/api/plane/app/serializers/issue.py
  • apps/api/plane/settings/storage.py
  • apps/api/plane/tests/contract/app/test_legacy_upload_validation_app.py
  • apps/api/plane/tests/unit/settings/test_storage.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The targeted fix correctly initializes inherited storage state and includes focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Initializes the django-storages base class so S3Storage works with Django FileField operations.

Changes:

  • Calls super().__init__() to initialize inherited storage state.
  • Adds regression coverage for location and path normalization.
File Description
apps/​api/​plane/​settings/​storage.py Initializes the base S3 storage implementation.
apps/​api/​plane/​tests/​unit/​settings/​test_storage.py Verifies required inherited attributes and normalization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ation

# Conflicts:
#	apps/api/plane/tests/unit/settings/test_storage.py
With super().__init__() in place, S3Storage works as the default FileField
storage again, so the legacy multipart routes (workspace and user
file-assets, issue-attachments) accept uploads.

- S3Storage sets default_acl = None, so a FileField upload sends no canned
  ACL whatever AWS_DEFAULT_ACL says.
- FileAssetSerializer and IssueAttachmentSerializer reject an uploaded file
  whose declared content type is missing or outside ATTACHMENT_MIME_TYPES,
  or that is larger than FILE_SIZE_LIMIT, as the presigned routes do.

@sriramveeraghanta sriramveeraghanta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now. The legacy multipart POSTs validate against ATTACHMENT_MIME_TYPES and FILE_SIZE_LIMIT, and default_acl = None takes precedence over AWS_DEFAULT_ACL (django-storages only fills in settings the class doesn't define). Unit tests pass locally (13/13). Note: the legacy attachment DELETE now really removes the S3 object, which seems right.

@sriramveeraghanta
sriramveeraghanta merged commit 18bdefa into preview Nov 18, 2026
17 checks passed
@sriramveeraghanta
sriramveeraghanta deleted the fix/s3-storage-location branch November 18, 2026 13:05
Pawel-Kranzberg added a commit to OSM-Piatnica/pi-plane that referenced this pull request Nov 18, 2026
fix(api): port makeplane#9942 (S3Storage super init, legacy upload validation) and eight-digit sign-up and email-change codes
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.

3 participants