Skip to content

fix(delete-user-data): enforce path boundary on Cloud Storage deletion - #3369

Merged
avolkovi merged 4 commits into
nextfrom
fix/delete-user-data-storage-prefix-boundary
Dec 3, 2026
Merged

avolkovi merged 4 commits into
nextfrom
fix/delete-user-data-storage-prefix-boundary

Conversation

@avolkovi

@avolkovi avolkovi commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Enforce exact object and directory boundary matching in clearStorageData so deleting a user whose custom UID is a prefix of another user's UID (e.g., 1 vs 12) cannot delete sibling users' objects in Cloud Storage.

Changes

  • delete-user-data/functions/src/index.ts:
    • When a configured storage prefix does not end with /, delete the exact object (bucket.file(prefix).delete({ ignoreNotFound: true })) and the directory prefix (bucket.deleteFiles({ prefix: ${prefix}/ })) instead of calling bucket.deleteFiles({ prefix }) without a boundary.
    • Guard against empty uid and empty prefix segments (e.g., {DEFAULT}/ or trailing commas) to prevent bucket-wide deletion.
  • delete-user-data/extension.yaml and delete-user-data/README.md:
    • Update the directory example from {DEFAULT}/media/{UID} to {DEFAULT}/media/{UID}/ and note that directory paths should use trailing slashes and custom UIDs should not contain /.
  • delete-user-data/functions/__tests__/clearStorageData.test.ts:
    • Add unit tests covering directory paths with and without trailing slashes, exact flat file paths, empty prefixes/trailing commas, and empty UIDs.

Verification

  • tsc compilation succeeded with no errors.
  • jest __tests__/clearStorageData.test.ts --verbose: 5/5 tests passed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the user data deletion extension to handle storage path boundaries more safely, ensuring directories are deleted cleanly using trailing slashes without affecting other users sharing a UID prefix. It adds comprehensive unit tests to verify these boundaries and introduces checks for empty UIDs and prefixes. The review feedback suggests extending the empty uid guard globally to protect other deletion functions (Firestore and RTDB) from accidental root-level deletions, and safely handling potential non-standard errors in the catch block using optional chaining.

Comment thread delete-user-data/functions/src/index.ts Resolved
Comment thread delete-user-data/functions/src/index.ts Resolved
Comment thread delete-user-data/functions/src/index.ts Resolved
Comment thread delete-user-data/functions/src/index.ts Resolved
Comment thread delete-user-data/functions/src/index.ts Resolved

@ajperel ajperel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you also update the version number and CHANGELOG.

@avolkovi

avolkovi commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Bumped version to 0.1.32 in delete-user-data/extension.yaml and added the changelog entry in delete-user-data/CHANGELOG.md (0eb585c).

@avolkovi
avolkovi merged commit e429ae7 into next Dec 3, 2026
20 checks passed
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.

3 participants