Repository navigation
Fix Storage emulator Firestore lookups for document IDs with special characters - #11651
pcbeingused33 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where uploads hang in the Storage emulator when a rule looks up a Firestore document containing special characters (such as |) in its ID. This is resolved by URL-encoding individual path segments of the Firestore document path before constructing the request URL. A unit test has been added to verify this behavior. The review feedback suggests adding defensive checks on request.context and request.context.path to prevent potential runtime TypeError crashes if the incoming JSON payload is malformed or missing these properties.
| const encodedPath = request.context.path.split("/").map(encodeURIComponent).join("/"); | ||
| const pathname = `projects/${projectId}${encodedPath}`; |
There was a problem hiding this comment.
Since the request object is parsed from an external JSON payload (via JSON.parse), we should defensively handle cases where request.context or request.context.path might be missing or malformed at runtime to prevent the emulator from crashing with a TypeError.
const path = request.context?.path;
if (typeof path !== "string") {
return { status: DataLoadStatus.NOT_FOUND, warnings: [], errors: ["Invalid or missing Firestore document path"] };
}
const encodedPath = path.split("/").map(encodeURIComponent).join("/");
const pathname = `projects/\${projectId}\${encodedPath}`;References
- Use strict null checks and handle
undefined/nullexplicitly. (link)
…estore-path # Conflicts: # CHANGELOG.md
…estore-path # Conflicts: # CHANGELOG.md
Fixes #11650
Description
The Storage rules runtime sends Firestore document paths without URL encoding. When a document ID contains a pipe, such as an Auth0 UID, the Firestore emulator can leave the lookup unanswered and the Storage upload hangs.
Encode each path segment before making the Firestore request so the document ID is escaped and the
/separators are preserved.Scenarios Tested
The Storage rules runtime regression test exercises the Firestore lookup with an Auth0-style UID and checks that the request contains
%7Cin the document ID. The regression test fails on the unpatched runtime. All 14 tests in the Storage rules runtime and config suites pass with the fix.Sample Commands
npx mocha src/emulator/storage/rules/runtime.spec.ts src/emulator/storage/rules/config.spec.tsThis PR was prepared with the help of an AI coding assistant.