fix the controllers#12506
Conversation
Greptile SummaryThis PR adds session expiry enforcement to JWT-based authentication in three code paths — console cookie auth (
Confidence Score: 4/5The core logic is correct and the three changed paths are consistent with each other; the main concern is a minor implementation choice in how the expiry timestamp is normalized before comparison. The expiry-check logic is equivalent across all three files and the auth flow correctly rejects expired sessions. The only findings are the unnecessary round-trips through new \DateTime() and format() before formatTz(), which add noise and carry a subtle null-fallback risk, but are unlikely to cause a real defect given that Appwrite stores well-formed datetime strings. All three changed files contain the same redundant date-normalisation pattern; no single file needs special attention beyond the others. Important Files Changed
Reviews (1): Last reviewed commit: "fix the controllers" | Re-trigger Greptile |
| if (!empty($session) && | ||
| ( | ||
| !$session->isSet('expire') || | ||
| DateTime::formatTz(DateTime::format(new \DateTime($session->getAttribute('expire')))) >= DateTime::formatTz(DateTime::now()) | ||
| ) | ||
| ) { |
There was a problem hiding this comment.
The stored
expire value from the DB is already in Appwrite's Utopia\Database\DateTime string format, so round-tripping it through new \DateTime() and DateTime::format() before passing to DateTime::formatTz() is redundant. More importantly, if $session->getAttribute('expire') ever returns a malformed or null string, new \DateTime(...) will silently create a "now" timestamp instead of throwing, making the session appear perpetually non-expired (if null produces "now", now >= now is true). Passing the raw stored string directly to DateTime::formatTz() avoids this ambiguity.
| if (!empty($session) && | |
| ( | |
| !$session->isSet('expire') || | |
| DateTime::formatTz(DateTime::format(new \DateTime($session->getAttribute('expire')))) >= DateTime::formatTz(DateTime::now()) | |
| ) | |
| ) { | |
| if (!empty($session) && | |
| ( | |
| !$session->isSet('expire') || | |
| DateTime::formatTz($session->getAttribute('expire')) >= DateTime::formatTz(DateTime::now()) | |
| ) | |
| ) { |
| ( | ||
| $session->isSet('expire') && | ||
| DatabaseDateTime::formatTz(DatabaseDateTime::format(new \DateTime($session->getAttribute('expire')))) < DatabaseDateTime::formatTz(DatabaseDateTime::now()) | ||
| ) |
There was a problem hiding this comment.
Same redundant round-trip via
new \DateTime() and DatabaseDateTime::format() before DatabaseDateTime::formatTz(). The value returned by $session->getAttribute('expire') should already be in Appwrite's stored datetime format, so DatabaseDateTime::formatTz($expire) is sufficient and avoids the silent "now" fallback if the value is ever null.
| ( | |
| $session->isSet('expire') && | |
| DatabaseDateTime::formatTz(DatabaseDateTime::format(new \DateTime($session->getAttribute('expire')))) < DatabaseDateTime::formatTz(DatabaseDateTime::now()) | |
| ) | |
| ( | |
| $session->isSet('expire') && | |
| DatabaseDateTime::formatTz($session->getAttribute('expire')) < DatabaseDateTime::formatTz(DatabaseDateTime::now()) | |
| ) |
| ( | ||
| $session->isSet('expire') && | ||
| DatabaseDateTime::formatTz(DatabaseDateTime::format(new \DateTime($session->getAttribute('expire')))) < DatabaseDateTime::formatTz(DatabaseDateTime::now()) | ||
| ) |
There was a problem hiding this comment.
Same redundant round-trip via
new \DateTime() and DatabaseDateTime::format() before DatabaseDateTime::formatTz(). The stored expire string is already in Appwrite's datetime format; passing it directly to DatabaseDateTime::formatTz() is cleaner and avoids the silent "now" fallback if the value is ever null.
| ( | |
| $session->isSet('expire') && | |
| DatabaseDateTime::formatTz(DatabaseDateTime::format(new \DateTime($session->getAttribute('expire')))) < DatabaseDateTime::formatTz(DatabaseDateTime::now()) | |
| ) | |
| ( | |
| $session->isSet('expire') && | |
| DatabaseDateTime::formatTz($session->getAttribute('expire')) < DatabaseDateTime::formatTz(DatabaseDateTime::now()) | |
| ) |
What does this PR do?
(Provide a description of what this PR does and why it's needed.)
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)
Related PRs and Issues
Checklist