fix(server): render uploads need Edit; chunks keep their upload's size

POST /sequences/{id}/renders and its complete call accepted the Upload
permission, so an upload-only account could file render outputs, which count
against no quota, into any sequence. Client renders are sent by the sync of
an editor's copy: both calls now require Edit (SRV-4).

The chunk endpoint capped the body at the current chunk size, while an
upload keeps the size it started with; after an administrator lowered the
setting, every chunk of an upload in flight got 413 until the upload expired.
The service now raises the limit to that upload's own chunk size before it
reads the body (SRV-5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 09:40:03 +00:00
1 parent eeee99694b
commit 23308c77dd
4 files changed
+61 -8

No files matched your search

@@ -96,6 +96,55 @@ public sealed class UploadTests(TestContext context)
Assert.Equal(frame.FrameId, again.FrameId);
}
[Test]
public async Task AnUploadKeepsItsChunkSizeWhenTheSettingShrinks()
{
await using var server = await TestServer.StartAsync(context, o => o.ChunkSizeBytes = Chunk * 2);
var (uploader, _, _) = await server.UserAsync("roof-cam", "uploader");
var data = Uploads.Photo(Chunk * 3, 14);
var start = await Uploads.StartAsync(uploader, data);
var id = Assert.NotNull(start.UploadId);
Assert.Equal(Chunk * 2, start.ChunkSize);
// An administrator lowers the chunk size; the upload resumes with the size it started with.
server.Options.ChunkSizeBytes = Chunk;
var resumed = await Uploads.StartAsync(uploader, data);
Assert.Equal((id, Chunk * 2), (resumed.UploadId!.Value, resumed.ChunkSize));
for (var i = 0; i < 2; i++)
{
using var put = await Uploads.PutChunkAsync(uploader, id, i, Uploads.Chunk(data, Chunk * 2, i));
await put.ExpectAsync(HttpStatusCode.OK);
}
using var complete = await uploader.PostAsync($"/api/v1/uploads/{id}/complete", null);
await complete.ExpectAsync(HttpStatusCode.OK);
// A new upload takes the new size, and a body above it is refused.
var next = Uploads.Photo(Chunk * 2, 15);
var small = await Uploads.StartAsync(uploader, next);
Assert.Equal(Chunk, small.ChunkSize);
using var oversized = await Uploads.PutChunkAsync(uploader, small.UploadId!.Value, 0, next);
await oversized.ExpectErrorAsync(HttpStatusCode.BadRequest, "chunk_size");
}
[Test]
public async Task RenderUploadsNeedTheEditPermission()
{
await using var server = await TestServer.StartAsync(context, o => o.ChunkSizeBytes = Chunk);
var (uploader, _, _) = await server.UserAsync("roof-cam", "uploader");
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var frame = await Uploads.UploadAsync(uploader, Uploads.Photo(5000, 16), sessionKey: "roof");
var output = Uploads.Photo(3000, 17);
var request = new RenderUploadRequest(Guid.CreateVersion7(), "Roof.mp4", output.Length, Uploads.Sha(output), "4K HEVC", "hevc", 3840, 2160, 30, 10, null);
// Render outputs count against no quota: an upload-only account cannot add them to any sequence.
using (var refused = await uploader.PostAsJsonAsync($"/api/v1/sequences/{frame.SequenceId}/renders", request, ProtocolJson.Default.RenderUploadRequest))
await refused.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
using (var complete = await uploader.PostAsync($"/api/v1/sequences/{frame.SequenceId}/renders/{Guid.CreateVersion7()}/complete", null))
await complete.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
using var accepted = await editor.PostAsJsonAsync($"/api/v1/sequences/{frame.SequenceId}/renders", request, ProtocolJson.Default.RenderUploadRequest);
await accepted.ExpectAsync(HttpStatusCode.Created);
}
[Test]
public async Task TheProtocolClientUploadsAndDownloadsLikeTheUploader()
{