Skip to content

fix(s3): enforce content-length-range in presigned POST policies - #1449

Merged
ferhatelmas merged 2 commits into
supabase:masterfrom
IslamElsayed:feat/post-policy-content-length-range
Sep 28, 2026
Merged

ferhatelmas merged 2 commits into
supabase:masterfrom
IslamElsayed:feat/post-policy-content-length-range

Conversation

@IslamElsayed

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

S3 compatibility fix: follow-up to the TODO left in #1211.

What is the current behavior?

content-length-range in a presigned POST policy is recognized but ignored (policy.ts: "recognized but NOT enforce yet"). Uploads of any size up to the bucket or global limit are accepted, even when the signed policy allows only 10–100 bytes.

What is the new behavior?

  • The policy's range narrows the upload's size limit. A file over the maximum is rejected with the existing EntityTooLarge (413), through the same ByteLimitTransformStream that already enforces the bucket limit.
  • A file under the minimum is rejected with a new EntityTooSmall error (400, as S3 returns). The check runs in the stream's _flush, so the upload fails before the object is stored.
  • Several ranges narrow to their intersection. A malformed range (negative, min > max, non-integer, or a missing bound) is rejected as InvalidSignature, like other unsupported conditions.

Tests

  • Unit (policy.test.ts): range extraction, intersection, and each malformed shape.
  • Integration (s3-protocol.test.ts), presigned POST with ['content-length-range', 10, 100]: 50 bytes → 200; 101 bytes → 413 and nothing stored; 9 bytes → 400 EntityTooSmall and nothing stored. Without the change, the 101-byte and 9-byte cases fail.
  • The full s3-protocol.test.ts (129 tests) and the full unit suite (2476) pass locally. Lint and tsc are clean.

I use AI assistance when working on patches, and I check and test everything before submitting.

@IslamElsayed
IslamElsayed requested a review from a team as a code owner September 28, 2026 08:26
IslamElsayed and others added 2 commits September 28, 2026 20:38
A signed POST policy's content-length-range condition was recognized but not
enforced, so an upload of any size up to the bucket limit was accepted. The
range now narrows the upload's size limit, and a file below its minimum is
rejected with EntityTooSmall before it is stored. Malformed ranges are rejected
as invalid policies.
@ferhatelmas
ferhatelmas force-pushed the feat/post-policy-content-length-range branch from 5edb691 to b219e87 Compare September 28, 2026 18:48

@ferhatelmas ferhatelmas 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.

Good initial implementation but updated to include:

  • don't parse policy again, use from signature
  • similarly snapshot for multipart
  • use last range if multiple as s3
  • use coercion as s3
  • some test hardening

@ferhatelmas
ferhatelmas merged commit c5a4155 into supabase:master Sep 28, 2026
29 checks passed
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 36467765022

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.02%) to 83.659%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 29 of 29 lines across 5 files are fully covered (100%).
  • 17 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

17 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/internal/http/agent.ts 17 32.56%

Coverage Stats

Coverage Status
Relevant Lines: 14270
Covered Lines: 12357
Line Coverage: 86.59%
Relevant Branches: 8758
Covered Branches: 6908
Branch Coverage: 78.88%
Branches in Coverage %: Yes
Coverage Strength: 770.97 hits per line

💛 - Coveralls

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