Skip to content

Fix FilterBlobs crash when where clause is omitted#2636

Open
qbradley wants to merge 3 commits intoAzure:mainfrom
qbradley:blobqueryfilter
Open

Fix FilterBlobs crash when where clause is omitted#2636
qbradley wants to merge 3 commits intoAzure:mainfrom
qbradley:blobqueryfilter

Conversation

@qbradley
Copy link

Service_FilterBlobs and Container_FilterBlobs crashed with HTTP 500 when the optional 'where' query parameter was not provided. The response object used 'options.where!' (non-null assertion) which set the required 'where' field to undefined, causing serialization to fail.

Replace 'options.where!' with 'options.where || ""' so that a missing where clause produces an empty string instead of undefined. The handler now returns 200 with an empty blob list when no filter expression is given.

Add regression test that sends a raw HTTP FilterBlobs request without a where parameter and asserts both service-level and container-level endpoints return 200.

qbradley and others added 2 commits March 17, 2026 13:19
Service_FilterBlobs and Container_FilterBlobs crashed with HTTP 500
when the optional 'where' query parameter was not provided. The
response object used 'options.where!' (non-null assertion) which
set the required 'where' field to undefined, causing serialization
to fail.

Replace 'options.where!' with 'options.where || ""' so that a
missing where clause produces an empty string instead of undefined.
Both handlers now return 200 with an empty blob list when no filter
expression is given.

Add regression test that sends a raw HTTP FilterBlobs request
without a where parameter and asserts both service-level and
container-level endpoints return 200.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace inline account name and key literals with the shared
constants already imported from testutils.ts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in the Blob “FilterBlobs” endpoints when the optional where query parameter is omitted, ensuring the emulator returns a successful response instead of failing during response serialization.

Changes:

  • Default where in ServiceFilterBlobsResponse and ContainerFilterBlobsResponse to "" when options.where is not provided.
  • Add a regression test that issues raw FilterBlobs HTTP requests without where for both service-level and container-level endpoints.
  • Document the fix in ChangeLog.md.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/blob/handlers/ServiceHandler.ts Avoids serializing an undefined required where field by defaulting to empty string.
src/blob/handlers/ContainerHandler.ts Same defaulting fix for the container-scoped FilterBlobs response.
tests/blob/apis/service.test.ts Adds regression coverage for missing-where requests at service and container endpoints.
ChangeLog.md Notes the behavioral fix for missing where in FilterBlobs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +845 to +920
function signAndSend(
method: string,
urlPath: string
): Promise<{ status: number; body: string }> {
return new Promise((resolve, reject) => {
const now = new Date().toUTCString();
const headers: Record<string, string> = {
"x-ms-date": now,
"x-ms-version": "2021-10-04"
};

// Build canonicalized headers
const canonHeaders = Object.keys(headers)
.filter((k) => k.startsWith("x-ms-"))
.sort()
.map((k) => `${k}:${headers[k]}\n`)
.join("");

// Build canonicalized resource (emulator doubles the account name)
const [pathPart, queryPart] = urlPath.split("?");
let canonResource = `/${account}/${account}${pathPart}`;
if (queryPart) {
const params: Record<string, string[]> = {};
for (const seg of queryPart.split("&")) {
const [k, v] = seg.split("=");
(params[k.toLowerCase()] = params[k.toLowerCase()] || []).push(
v || ""
);
}
for (const k of Object.keys(params).sort()) {
canonResource += `\n${k}:${params[k].sort().join(",")}`;
}
}

const stringToSign = [
method,
"", // Content-Encoding
"", // Content-Language
"", // Content-Length
"", // Content-MD5
"", // Content-Type
"", // Date
"", // If-Modified-Since
"", // If-Match
"", // If-None-Match
"", // If-Unmodified-Since
"", // Range
canonHeaders + canonResource
].join("\n");

const sig = crypto
.createHmac("sha256", Buffer.from(accountKey, "base64"))
.update(stringToSign, "utf8")
.digest("base64");
headers["Authorization"] = `SharedKey ${account}:${sig}`;

const req = http.request(
{
hostname: host,
port,
path: `/${account}${urlPath}`,
method,
headers
},
(res: any) => {
let body = "";
res.on("data", (chunk: any) => (body += chunk));
res.on("end", () =>
resolve({ status: res.statusCode, body })
);
}
);
req.on("error", reject);
req.end();
});
}
Comment on lines +851 to +854
const headers: Record<string, string> = {
"x-ms-date": now,
"x-ms-version": "2021-10-04"
};
- Performance improvements for internal metadata access using in-memory metadata store
- Fix building failure on Node 22 platform.
- Fix * IfMatch for non-existent resource not throwing 412 Precondition Failed
- Fix FilterBlobs returning 500 instead of 200 with optional missing where parameter.
Comment on lines +922 to +952
// Service-level FilterBlobs without 'where' — should return 200
const serviceResult = await signAndSend("GET", "/?comp=blobs");
assert.strictEqual(
serviceResult.status,
200,
`Service_FilterBlobs without where should return 200, got ${serviceResult.status}: ${serviceResult.body}`
);
assert.ok(
serviceResult.body.includes("<Blobs"),
"Response should contain a <Blobs> element"
);

// Container-level FilterBlobs without 'where' — create a container first
const containerName = getUniqueName("filtertest");
const containerClient = serviceClient.getContainerClient(containerName);
await containerClient.create();

const containerResult = await signAndSend(
"GET",
`/${containerName}?restype=container&comp=blobs`
);
assert.strictEqual(
containerResult.status,
200,
`Container_FilterBlobs without where should return 200, got ${containerResult.status}: ${containerResult.body}`
);
assert.ok(
containerResult.body.includes("<Blobs"),
"Response should contain a <Blobs> element"
);

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.

2 participants