Skip to content

Dataset max file size limit can be bypassed (frontend-only check) #4058

Closed as not planned

Description

@carloea2

What happened?

Issue description

When uploading a file in a dataset, right now the file size limit is only checked in the frontend.

When a file is dropped, fileDropped() checks the size like this:

if (droppedFile.fileEntry.isFile) {
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
fileEntry.file(file => {
// Check the file size here
if (file.size > this.singleFileUploadMaxSizeMiB * 1024 * 1024) {
// If the file is too large, reject the promise
this.notificationService.error(
`File ${file.name}'s size exceeds the maximum limit of ${this.singleFileUploadMaxSizeMiB}MiB.`
);
reject(null);
} else {

Because this check lives only in the built JS (e.g. main.js), a user can change or remove it on the client side and then upload files that are larger than the intended limit.

The backend does not enforce the same size limit, so these larger files are accepted successfully.

Expected

  • File size limit is enforced on the server.
  • Changing the frontend code does not allow uploads larger than singleFileUploadMaxSizeMiB.

Actual

  • File size is only checked in the frontend.
  • Users who change the client-side code can upload files bigger than the configured limit without any server-side rejection.

How to reproduce?

Steps to reproduce

  1. Log in to Texera Hub.

  2. Go to Your Work → Datasets and open any dataset.

  3. Open the browser developer tools and go to the Sources tab.

  4. Open main.js (the bundled frontend file).

  5. Search for the string "the maximum limit" to locate the file size check in fileDropped().

  6. Note the current configured limit in this.singleFileUploadMaxSizeMiB (for example, 20 MiB / 10 GiB).

  7. In the devtools editor, change the condition from:

    if (file.size > this.singleFileUploadMaxSizeMiB * 1024 * 1024) {

    to something larger, for example:

    if (file.size > this.singleFileUploadMaxSizeMiB * 1024 * 1024 * 1024) {
  8. With this modified code, drag and drop a file whose size is above the real limit but below the modified limit.

  9. The upload succeeds even though it exceeds the intended max size.

    • In the attached screenshot, a testtexera.zip file of 12.92 GB was uploaded while the limit was 10 GB.
Image

Version

1.1.0-incubating (Pre-release/Master)

Commit Hash (Optional)

No response

What browsers are you seeing the problem on?

No response

Relevant log output


Proposed design

We propose to enforce the file size limit on the server side for multipart uploads, while keeping the parallelism and good UX of the current client-driven multipart flow.

Key ideas:

  • The client still splits the file into parts and uploads them concurrently.

  • Instead of uploading parts directly to LakeFS/S3 via presigned URLs, the client sends each part to DatasetResource.

  • DatasetResource:

    • Buffers each part fully in memory.
    • Keeps a global byte counter per upload in a ConcurrentHashMap-backed session store.
    • Forwards the part to LakeFS using existing presigned URLs.
    • Aborts the upload as soon as the cumulative size exceeds maxSingleFileUploadBytes.
  • Sessions (upload state) are tracked on the backend using a ConcurrentHashMap[uploadToken → UploadSession], not in the frontend.

Below are diagrams of the current and new designs.


Current design (client → LakeFS directly via presigned URLs)

sequenceDiagram
    title Current multipart upload flow (direct to LakeFS)

    participant B as Browser / Angular UI
    participant F as DatasetService.ts
    participant S as DatasetResource (backend)
    participant L as LakeFS
    participant O as S3

    B->>F: Select file, split into parts
    F->>S: POST /dataset/multipart-upload?type=init<br/>{ ownerEmail, datasetName, filePath, numParts }
    S->>L: initiatePresignedMultipartUploads(repoName, filePath, numParts)
    L-->>S: { uploadId, presignedUrls[], physicalAddress }
    S-->>F: { uploadId, presignedUrls[], physicalAddress }
    F-->>B: presignedUrls[], uploadId

    par For each part (in parallel)
        B->>O: PUT part to presignedUrl[i]
        O-->>B: 200 + ETag
    end

    B->>F: All parts uploaded, collected {PartNumber, ETag}
    F->>S: POST /dataset/multipart-upload?type=finish<br/>{ parts[], physicalAddress, uploadId }
    S->>L: completePresignedMultipartUploads(repoName, filePath, uploadId, parts[], physicalAddress)
    L-->>S: objectStats(sizeBytes)
    S-->>F: 200 OK
    F-->>B: Final result (success / error)
Loading

Limitations:
All data flows directly from browser to S3/LakeFS. DatasetResource only learns the final size during finish, so a malicious client can bypass the size limit until after the object is fully stored.


New design (server-proxied multipart with ConcurrentHashMap sessions)

sequenceDiagram
    title New multipart upload flow (proxied via DatasetResource)

    participant B as Browser / Angular UI
    participant F as DatasetService.ts
    participant S as DatasetResource (backend)
    participant SS as SessionStore<br/>(ConcurrentHashMap)
    participant L as LakeFS
    participant O as S3

    Note over B,F: Client still splits file into parts<br/>and shows progress & concurrency

    B->>F: Select file, split into parts
    F->>S: POST /dataset/multipart-upload?type=init<br/>{ ownerEmail, datasetName, filePath, numParts, totalSizeBytes? }

    S->>S: Validate dataset + user access
    S->>L: initiatePresignedMultipartUploads(repoName, filePath, numParts)
    L-->>S: { uploadId, presignedUrls[], physicalAddress }

    S->>SS: Put(uploadToken → {uploadId, presignedUrls[],<br/>filePath, totalBytes=0, maxBytes, physicalAddress, status='active', parts=[]})
    S-->>F: { uploadToken, partSize, maxBytes }
    F-->>B: { uploadToken, partSize }

    par For each part (in parallel)
        B->>F: Next chunk
        F->>S: POST /dataset/multipart-upload/part?<br/>uploadToken=&partNumber= (body=chunk)

        S->>SS: Get session by uploadToken
        S->>S: Buffer chunk in memory,<br/>session.totalBytes += chunk.size

        alt totalBytes > maxBytes
            S->>L: abortPresignedMultipartUploads(repoName, filePath, uploadId, physicalAddress)
            S->>SS: Mark session as aborted
            S-->>F: 413 Payload Too Large
            F-->>B: Stop remaining parts, show error
        else Within size limit
            S->>O: PUT chunk to presignedUrl[partNumber]
            O-->>S: 200 + ETag
            S->>SS: Update session totalBytes,<br/>parts += {partNumber, ETag}
            S-->>F: 200 OK (part success)
            F-->>B: Update progress bar
        end
    end

    B->>F: All parts reported as uploaded
    F->>S: POST /dataset/multipart-upload?type=finish<br/>{ uploadToken }

    S->>SS: Get & remove session by uploadToken
    alt session.aborted
        S-->>F: 410 Upload aborted (size limit)
        F-->>B: Show "upload aborted due to size limit"
    else session active
        S->>L: completePresignedMultipartUploads(repoName, filePath, uploadId, parts, physicalAddress)
        L-->>S: objectStats(sizeBytes)
        S-->>F: 200 OK
        F-->>B: Upload finished successfully
    end
Loading

Benefits of the new design:

  • The file must pass through the backend; size checks cannot be bypassed by modifying the frontend.
  • The backend can cut the stream early (returning 413) as soon as totalBytes > maxSingleFileUploadBytes.
  • Clients retain parallel multipart uploads and progress tracking.
  • No DB schema changes are required; upload sessions are kept in-memory via ConcurrentHashMap (with the usual caveats about multi-instance deployments and cleanup).

Activity

  1. added theissue type on Nov 16, 2025
  2. Yicong-Huang commented on Nov 17, 2025

    @Yicong-Huang
    Contributor

    If we only did frontend limit, it is for sure easily bypass-able. Did we have limit on the backend api? @bobbai00 @aicam

  3. carloea2 commented on Nov 25, 2025

    @carloea2
    ContributorAuthor

    After talking with @chenlica I realized that even with backend checks added for uploadOneFileToDataset, the multipart + presigned URL path still has a gap: a user could already have uploaded e.g. 1 TB to lakeFS/S3, and we only notice at multipartUpload?type=finish, which is too late from a bandwidth / resource perspective.

    Why we can’t enforce inline like single-file upload

    For single-file uploads, the HTTP body streams through DatasetResource and we can do:

    totalBytesRead += read
    if (totalBytesRead > maxLimit) throw 413

    For multipart uploads with presigned PUTs:

    • The browser talks directly to S3/lakeFS (S3 multipart API: initiate → upload part → complete).

    • Our backend only:

      • Creates presigned URLs (type=init), and
      • Gets metadata on type=finish.
    • The data stream never passes our JVM, so we have no byte counter to increment and no way to send a 413 mid-stream.

    • S3/lakeFS don’t expose an app-specific size cap inside presigned PUT URLs; POST policies with content-length-range don’t apply to our current multipart flow.

    So an “inline” limit identical to uploadOneFileToDataset is fundamentally impossible with presigned multipart PUTs.

    Proposed direction: server-side watcher

    Idea (not fully implemented yet; looking for feasibility feedback):

    • Add a small DB table tracking active multipart uploads: (upload_id, did, uid, repository_name, file_path, physical_address, status, bytes_uploaded, max_bytes, timestamps).

    • On multipart-upload?type=init, insert a row with status = ACTIVE and max_bytes = single_file_upload_max_size_mib.

    • Background watcher:

      • Periodically (e.g. every 10–60s) calls ListParts (or lakeFS equivalent) for each ACTIVE upload and sums real part sizes from the object store.
      • Updates bytes_uploaded.
      • If bytes_uploaded > max_bytes, calls abortPresignedMultipartUploads and marks status = LIMIT_EXCEEDED.
    • On type=finish, if status is LIMIT_EXCEEDED or ABORTED we fail immediately instead of completing the upload.

    This does not trust any client-supplied sizes; it only trusts lakeFS/S3 metadata.

    Downsides / tradeoffs

    • Overshoot is still possible: if a client uploads many small parts quickly between watcher ticks, we only detect after the interval. The overshoot is bounded by:

      • part size × “parts uploaded between checks” + watcher latency.
      • Shorter intervals reduce overshoot but increase control-plane calls (ListParts per active upload).
    • Extra complexity: background job, DB tracking, and a dependency on S3/lakeFS metadata being available and fast.

    • Failure modes: if the watcher is down, we still catch oversized uploads at finish (object size check + rollback), but we can’t avoid bandwidth cost.

    Future benefit

    If we go this route, the same table + watcher make it much easier later to add per-user / per-dataset quotas (e.g., total in-flight bytes, per-user caps). I haven’t started coding this yet because I’d like feedback on whether this approach sounds acceptable from a design / ops standpoint.

    Tiny diagram

    sequenceDiagram
        participant Client
        participant Texera as DatasetResource
        participant Watcher
        participant LakeFS
    
        Client->>Texera: multipart-upload?type=init
        Texera->>LakeFS: initiateMultipart
        LakeFS-->>Texera: uploadId + presigned URLs
        Texera->>DB: INSERT upload (ACTIVE, max_bytes)
        Texera-->>Client: uploadId + URLs
    
        Client->>LakeFS: PUT parts (direct)
    
        loop every N seconds
          Watcher->>DB: SELECT ACTIVE uploads
          Watcher->>LakeFS: ListParts(uploadId)
          LakeFS-->>Watcher: part sizes
          Watcher->>DB: UPDATE bytes_uploaded
          alt bytes_uploaded > max_bytes
            Watcher->>LakeFS: abortMultipartUpload()
            Watcher->>DB: status = LIMIT_EXCEEDED
          end
        end
    
        Client->>Texera: multipart-upload?type=finish
        Texera->>DB: read status
        alt LIMIT_EXCEEDED
          Texera-->>Client: 413 Payload Too Large
        else
          Texera->>LakeFS: completeMultipartUpload()
          LakeFS-->>Texera: final size
          Texera-->>Client: 200 OK
        end
    
    Loading

    @xuang7 @bobbai00 @Yicong-Huang

  4. chenlica commented on Nov 25, 2025

    @chenlica
    Contributor

    @carloea2 Given the complexity of this description, please schedule a meeting with me, and we will report the results here.

  5. aglinxinyuan commented on Nov 25, 2025

    @aglinxinyuan
    Contributor

    Could you think through the following questions before our meeting?
    1. Can you provide evidence that a user can exceed the size limit when using multipart uploads with a pre-signed URL? Right now this is an assumption without concrete proof. Please describe in detail how a user could bypass the limit.
    2. Why can’t we use pre-signed POST uploads so that we can leverage the S3 API to enforce a strict size limit?
    3. What potential issues could occur if a user exceeds the size limit during a multipart upload? Since we don’t have quotas implemented yet, what risks or system impact should we be aware of?
    4. The proposed design feels overly complex. This feature shouldn’t require such a complex solution. It’s surprising that S3—given how widely used it is—would not support file size limits. Could you clarify why the simpler approaches wouldn’t work?

  6. carloea2 commented on Nov 25, 2025

    @carloea2
    ContributorAuthor

    1. Concrete bypass evidence
    On hub.texera.io with singleFileUploadMaxSizeMiB = 10 GiB, I patched the JS size check in devtools and uploaded a 12.92 GB testtexera.zip. The upload used multipart + presigned PUTs, multipartUpload?type=finish returned 200, and the dataset shows Version Size: 12.92 GB. So a user who bypasses the frontend can exceed the configured limit today.

    2. POST, part limits, and URL count
    Presigned POST content-length-range only protects a single request, while our large-file path uses multipart PUTs. lakeFS/S3 enforce only per-part bounds (e.g., 5 MiB–5 GiB, up to 10,000 parts). Because parts can vary in size, limiting the number of presigned URLs alone does not enforce a total max size. Relying on a “final size” header from the client would again trust the frontend.

    3. FixedSize / MaxSize parts
    As far as I can see, we can’t tell lakeFS/S3 “every part must be exactly X bytes”; they only enforce min/max per part. So a “fixed-size parts = enforced limit” scheme isn’t reliable without extra server logic. So yes, using FixedSize/MaxSize parts alone doesn’t seem feasible.

    4. Finish-time check (simple backend fix)
    First step I propose: on multipartUpload?type=finish, read the object size from lakeFS/S3 and reject anything over singleFileUploadMaxSizeMiB (and optionally delete/abort). This trusts only object-store metadata. Downside: we discover violations after all bytes are uploaded, so bandwidth and temporary storage are still consumed.

    5. Watcher approach (pros/cons)
    A watcher that periodically ListParts and aborts when bytes_uploaded > limit would:

    • Pros: detect oversize uploads earlier; natural place for future per-user/dataset quotas.
    • Cons: extra DB table + background job, more control-plane calls, new failure modes.
  7. aglinxinyuan commented on Nov 25, 2025

    @aglinxinyuan
    Contributor

    I understand that we can bypass singleFileUploadMaxSizeMiB for now. After we add a backend check for singleFileUploadMaxSizeMiB, will multipart uploads still be able to exceed that size limit?

    I don’t have a question about your first post, but I don’t see supporting evidence for your second one. It seems to me that the “finish-time check (simple backend fix)” should be sufficient on its own, and I’m not sure why we would need a “watcher.”

  8. carloea2 commented on Nov 26, 2025

    @carloea2
    ContributorAuthor

    After we add a backend finish-time check on multipartUpload?type=finish that reads the final size from lakeFS/S3 and rejects anything over singleFileUploadMaxSizeMiB, multipart uploads can no longer produce a dataset file larger than the limit, the API-side limit can’t be bypassed.

    What can still happen is that a client uploads more than the limit in raw bytes to lakeFS/S3 before we reject, so the remaining risk is bandwidth/storage waste, not correctness.

    The “watcher” idea is only an optional optimization to detect obviously over-limit uploads earlier to save those resources, it doesn’t change the limit semantics.

  9. aglinxinyuan commented on Nov 26, 2025

    @aglinxinyuan
    Contributor

    Ok. I fully understand and agree with it. I think it's a separate issue.

  10. chenlica commented on Nov 26, 2025

    @chenlica
    Contributor

    @carloea2 After we finish our in-person discussion, please update this issue with our final design.

  11. carloea2 commented on Dec 2, 2025

    @carloea2
    ContributorAuthor

    @carloea2 After we finish our in-person discussion, please update this issue with our final design.

    @chenlica done, thank you

  12. carloea2 commented on Dec 6, 2025

    @carloea2
    ContributorAuthor

    This was closed to simplify the review process and split the work into two steps:

    1. Handle this issue first: task(dataset): Redirect multipart upload through File Service #4110

    2. Once that is completed, I’ll create a new issue to enforce the actual max file size in the new architecture.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions