Skip to content

fix(security): close Content-Length bypass in multipart upload size g… - #1117

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
AbuJulaybeeb:feat/close-content-length-bypass
Jul 28, 2026
Merged

fix(security): close Content-Length bypass in multipart upload size g…#1117
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
AbuJulaybeeb:feat/close-content-length-bypass

Conversation

@AbuJulaybeeb

Copy link
Copy Markdown
Contributor

Fixes #989

**: Closes a security bypass in the multipart upload size guard where missing, unparseable, or manipulated Content-Length headers would allow arbitrarily large files to be uploaded into memory.

Security Mitigations & Changes

  1. src/main.ts Guard Refactor:
    • Instead of trusting the client-provided Content-Length claim, we now enforce a stream-level counting guard that intercepts data chunks in real-time as they are consumed.
    • If the actual bytesRead exceed the configured FILE_UPLOAD_MAX_BYTES limit, the request is immediately aborted via req.destroy(), completely stopping the flow and preserving process memory.
    • Requests omitting Content-Length that lack Transfer-Encoding: chunked are immediately rejected with 411 Length Required.
  2. src/media/validation/upload-validation.util.ts Update:
    • Modified the Multer limits configuration (MEDIA_UPLOAD_INTERCEPTOR_OPTIONS) to dynamically parse and enforce the environment variable FILE_UPLOAD_MAX_BYTES directly, ensuring consistency between Express middleware and Multer.
  3. E2E Tests (test/security/upload-bypass.e2e-spec.ts):
    • Added integration tests covering a chunked multipart upload exceeding the limit.
    • Added tests rejecting uploads attempting to understate their Content-Length.

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@AbuJulaybeeb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…uard

- Refactored the file size guard in main.ts to enforce stream-level byte counting.
- Missing or unparseable Content-Length requests without chunked encoding are now rejected with 411 Length Required.
- Added a counting stream guard that destroys the request if actual payload bytes exceed the limit.
- Updated multer config in upload-validation.util.ts to dynamically read FILE_UPLOAD_MAX_BYTES.
- Added e2e tests for chunked upload bypassing and understated Content-Length scenarios.
Closes rinafcode#989
@AbuJulaybeeb
AbuJulaybeeb force-pushed the feat/close-content-length-bypass branch from 9e1f4ca to 7a8dab6 Compare July 28, 2026 16:52
@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 56aba40 into rinafcode:main Jul 28, 2026
3 checks passed
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.

Close the Content-Length bypass in the multipart upload size guard in main.ts

2 participants