Repository navigation
Conversation
FirestoreSessionService used app_name, user_id and session_id as raw Firestore document path segments. The client treats "/" as a path separator and only checks segment parity, not content, so an identity component with an even number of "/" silently changed the document path and could nest one identity's session document under another's. The core VertexAiSessionService already guards session ids; the Firestore backend did not. Reject identity components that would alter the path (containing "/", equal to "." / "..", empty, or matching the Firestore-reserved __.*__ pattern) across all CRUD paths, while still accepting ordinary ids such as email addresses. The empty/None user_id list_sessions behavior from google#7662 is unchanged: it returns before reaching the validated reference. Fixes google#7800
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 29, 2026
Merge #7801 FirestoreSessionService now raises ValueError when app_name, user_id or session_id is empty, contains '/', is '.' or '..', or matches __.*__, in create_session, get_session, list_sessions, delete_session, append_event and get_user_state. An id with an even number of '/' used to be accepted and nested its documents under another path; sessions already stored under such an id can no longer be read or deleted through the service. Fixes #7800 PiperOrigin-RevId: 1009950637
Collaborator
|
Thank you @CorgiBoyG for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit ec9756e. Closing this PR as the changes are now in the main branch. |
2 tasks done
7 of 8 tasks
CorgiBoyG
added a commit
to CorgiBoyG/adk-python
that referenced
this pull request
Nov 1, 2026
…ttern The reserved-id check added in google#7801 used startswith("__") and endswith("__"), which also matches "__" and "___" because the prefix and suffix overlap. Firestore reserves only ids matching __.*__, which needs at least four characters, so those two valid ids were rejected and any sessions already stored under them could no longer be read or deleted. Require a minimum length of four so the check is equivalent to re.fullmatch(r"__.*__", value). Fixes google#7855
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.
Link to Issue or Description of Change
Problem:
FirestoreSessionServiceusesapp_name,user_idandsession_idas raw Firestore document path segments:The Firestore client treats
/as a path separator andverify_pathonly checks that a document path has an even number of segments, not segment content. So an identity component with an even number of/is accepted and silently changes the path structure, nesting one identity's session document under another's. For exampleuser_id="alice/sessions/s"produces.../users/alice/sessions/s/sessions/x, whose parent chainusers/alice/sessions/sis byte-identical to the session document of the real useralice/ sessions.This is the Firestore counterpart of the Redis key-collision issue #7464. The core
VertexAiSessionServicealready guards with_validate_session_id(); the Firestore backend applied no equivalent check.Solution:
Add
_validate_identity_component()and apply it toapp_name/user_id(in_get_sessions_ref) andsession_id(in a new_get_session_doc_ref), covering every CRUD path (create_session,get_session,list_sessions,delete_session,append_event). It rejects only components that would break the document path — containing/, equal to./.., empty, or matching the Firestore-reserved__.*__pattern — so ordinary ids, including email addresses, still work. The core allow-list^[A-Za-z0-9_-]+$would be too strict here (it rejects.), so this uses a conservative reject-list instead; happy to adjust the exact set per the issue discussion.The empty/
Noneuser_idbehavior oflist_sessionsfrom #7662 is unchanged: it returns before reaching the validated reference.Testing Plan
Unit Tests:
New regression tests (fail on main, pass after the fix):
The new tests assert that path-breaking
user_id/session_idvalues ("alice/sessions/s","x/sessions/y","..","","__reserved__") raiseValueErroroncreate_session/get_session/delete_session, while ordinary ids ("alice","[email protected]","user-123_abc","a.b.c") still succeed. Thelist_sessionsempty/Noneuser_id behavior (#7662) is covered and unchanged.Static checks:
The full repository test suite was not run.
Manual End-to-End (E2E) Tests:
Not run. The identity-to-path mapping was verified offline with
google-cloud-firestore2.34.1 by inspecting the locally-built document path and the resource name carried in the Commit RPC.Checklist
Additional context
MongoDB uses structured dict keys (no delimiter collision) and Redis is tracked separately (#7464 / #7563). If maintainers prefer, the validation helper could be hoisted into a shared location for the third-party backends; kept local to Firestore here to stay minimal.