Skip to content

Nothing stops a put under tenants/ outside AttachmentStorage.AddAsync, so the sweep can delete the object of a row saved later than the grace #536

Closed

Description

@pdevito3

Summary

Nothing stops code from putting an object under tenants/ outside AttachmentStorage.AddAsync. Only AddAsync bounds the time between the put and the save of the row by Attachments:AddTimeout. A put on another path that saves its row later than the grace gets its object deleted by the sweep while the row still names it.

Where

Main at 3b7a3c7122b9a3dd4a18c66c85640be95913ce4a.

  • AttachmentStorage.cs:26-48. AddAsync cancels the put and the save at AddTimeout.
  • ObjectSweepOptions.cs:31. The grace is AddTimeout + Margin, which is correct only for puts that obey AddTimeout.
  • ObjectStorage.PutAsync is public. Today AttachmentStorage.cs:38 is its only caller, so the gap is latent. The rule is only text in docs/backend/attachments.md.

Reproduction steps

  1. Add a handler that calls ObjectStorage.PutAsync with a StoredFile.TenantsPrefix key, then waits longer than AddTimeout + Margin before it saves the row. A test can use a fake TimeProvider and a short Margin.
  2. Run SweepObjects between the put and the save.
  3. Save the row.

Expected

The build or a test refuses a put under tenants/ that does not go through AttachmentStorage.AddAsync, or the sweep cannot delete the object of a put still in progress.

Actual

The code compiles and the tests pass. The sweep deletes the object, and the saved row names an object that is gone.

Impact

Silent data loss in an app built from the template, for example a bulk import or a new upload path that puts the files first and saves the rows in one long transaction.

Source

Finding L3 in the review comment of #526: #526 (comment)

Suggested fix

The review notes that a ban of ObjectStorage.PutAsync with RS0030 would also stop puts outside tenants/, which the sweep does not touch. One option is a separate put method for tenants/ keys that only AttachmentStorage can reach, so that the banned API is only that one.

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions