Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ AZURE_STORAGE_WORKSPACE_LOGOS_CONTAINER_NAME=workspace-logos

Direct browser uploads require a Blob service CORS rule on the storage account. Allow your exact
Sim origin, `GET` and `PUT`, the `Content-Type` header, and the `x-ms-*` prefix used by signed blob
and metadata headers. Small-file uploads also send `If-None-Match` so a signed URL cannot overwrite
an existing final object. Multipart uploads also read `ETag` from the browser response:
and metadata headers. Small-file uploads also send `If-None-Match`; the signature itself is
create-only, so a signed URL cannot overwrite an existing final object. Multipart uploads also read
`ETag` from the browser response:

```bash
az storage cors add \
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/lib/uploads/providers/blob/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ describe('Azure Blob Storage Client', () => {
'DefaultEndpointsProtocol=https;AccountName=testaccount;AccountKey=testkey;EndpointSuffix=core.windows.net',
}

it('signs a PUT with the required blob and metadata headers', async () => {
mockBlobSASPermissionsParse.mockReturnValueOnce('w')
it('signs a create-only PUT with the required blob and metadata headers', async () => {
mockBlobSASPermissionsParse.mockReturnValueOnce('c')

const result = await getBlobPresignedUploadUrl({
key: 'workspace/workspace-1/file.bin',
Expand All @@ -176,7 +176,7 @@ describe('Azure Blob Storage Client', () => {
expiresIn: 600,
})

expect(mockBlobSASPermissionsParse).toHaveBeenCalledWith('w')
expect(mockBlobSASPermissionsParse).toHaveBeenCalledWith('c')
expect(result).toEqual({
url: expect.stringContaining('?sv=2021-06-08'),
headers: {
Expand Down
13 changes: 11 additions & 2 deletions apps/sim/lib/uploads/providers/blob/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,16 @@ export async function getPresignedUrlWithConfig(
return `${blockBlobClient.url}?${sasToken}`
}

/** Generates a create-only SAS-backed single-object PUT for a caller-selected final key. */
/**
* Generates a create-only SAS-backed single-object PUT for a caller-selected final key.
*
* The permission must stay `c` (create), not `w`: `w` is "create or write
* content" and authorizes overwriting an existing blob, so a still-valid
* signature could replace a completed upload. `If-None-Match` is returned for
* parity with the S3 and GCS signers, but Azure does not cover request headers
* in a service-SAS string-to-sign, so it is advisory and cannot carry this on
* its own.
*/
export async function getBlobPresignedUploadUrl(params: {
key: string
contentType: string
Expand All @@ -301,7 +310,7 @@ export async function getBlobPresignedUploadUrl(params: {
{
containerName: params.customConfig.containerName,
blobName: params.key,
permissions: BlobSASPermissions.parse('w'),
permissions: BlobSASPermissions.parse('c'),
startsOn,
expiresOn,
},
Expand Down
Loading