Repository navigation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff changes behavior, not just formatting — both the old and new versions look problematic.
Issues with the change
1. Cookie path no longer matches across login/logout in the same way
The docstring says the path is used both when writing the cookie at login and when deleting it at logout. The two code paths must produce the identical string.
f"/chat/{access_token + '/' if access_token else ''}"→/chat/abc/or/chat/f"/chat/{access_token or 'portal'}"→/chat/abcor/chat/portalThe empty-token case now yields
/chat/portalinstead of/chat/. If any other code (or an older deployed version) still uses/chat/, the cookie won't be cleared at logout, leaving a stale auth cookie. Verify every call site was updated together.2. Inconsistent trailing slash between branches (old code)
In the original, non-empty tokens get a trailing
/(/chat/abc/) but the empty case gives/chat/with no extra segment. This asymmetry is confusing; make sure login and logout both use this same function so they can't drift apart. (Your change at least keeps them symmetric.)3.
'portal'magic stringHardcoding
"portal"as a fallback path segment:"portal"would resolve to the same cookie path as the anonymous case, causing users to stomp on each other's cookies / log each other out.ANONYMOUS_CHAT_PATH = "portal") and/or document whyportalis correct.4. Path scoping / security considerations
access_tokenis ever user-controlled, embedding it raw in a cookiePathmeans it must be URL-safe and free of/,;,,, whitespace, etc. A token containing/silently widens or narrows the cookie scope. Consider validating/sanitizing, or better, don't put secrets in aPathat all (paths are visible in requests and shared across subresource loads).5. Function naming
get_chat_user_cookie_pathsuggests pure computation; ensure it doesn't start doing I/O. It's fine now, but the docstring-heavy reliance on callers calling it twice (login + logout) is fragile — see #6.Optimization / refactor suggestions
/chat/...paths exist (grep for"/chat/").ANONYMOUS_CHAT_PATH.None, and that login-path == logout-path for each.Path(no unescaped special chars).Verdict
No syntax bug, but the semantic change (fallback
""→"portal", removal of trailing slash) can break cookie cleanup against previously issued cookies and introduces a token-collision edge case. Confirm intent, align all call sites and deployed cookies, and replace the magic string with a constant.