Fix FilterBlobs crash when where clause is omitted#2636
Open
qbradley wants to merge 3 commits intoAzure:mainfrom
Open
Fix FilterBlobs crash when where clause is omitted#2636qbradley wants to merge 3 commits intoAzure:mainfrom
qbradley wants to merge 3 commits intoAzure:mainfrom
Conversation
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>
There was a problem hiding this comment.
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
whereinServiceFilterBlobsResponseandContainerFilterBlobsResponseto""whenoptions.whereis not provided. - Add a regression test that issues raw FilterBlobs HTTP requests without
wherefor 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" | ||
| ); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.