feat: allow custom jwt duration#11009
Conversation
📝 WalkthroughWalkthroughAdds an optional Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)app/controllers/api/account.php (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
app/controllers/api/account.php (2)
2964-2981: Critical: JWT duration is hardcoded and doesn't use the parameter.The action function is missing the
durationparameter in its signature (line 2964), and the JWT constructor on line 2971 uses a hardcoded value of900instead of thedurationparameter. This means the feature doesn't work at all.🔎 Proposed fix
- ->action(function (Response $response, User $user, Store $store, ProofsToken $proofForToken) { + ->action(function (int $duration, Response $response, User $user, Store $store, ProofsToken $proofForToken) { $sessionId = $user->sessionVerify($store->getProperty('secret', ''), $proofForToken); if (!$sessionId) { throw new Exception(Exception::USER_SESSION_NOT_FOUND); } - $jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 0); + $jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', $duration, 0); $response ->setStatusCode(Response::STATUS_CODE_CREATED)
2957-2981: Fix unused duration parameter in JWT creation.The
durationparameter validation is consistent across account.php, projects.php, and users.php (all use Range(0, 3600) with default 900), but account.php has a critical bug: the JWT constructor hardcodes900instead of using the$durationparameter. At line 2971, changenew JWT(..., 900, 0)tonew JWT(..., $duration, 0)to match the implementations in projects.php (line 1731) and users.php (line 2647).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (6)
app/config/specs/open-api3-latest-client.jsonis excluded by!app/config/specs/**app/config/specs/open-api3-latest-console.jsonis excluded by!app/config/specs/**app/config/specs/open-api3-latest-server.jsonis excluded by!app/config/specs/**app/config/specs/swagger2-latest-client.jsonis excluded by!app/config/specs/**app/config/specs/swagger2-latest-console.jsonis excluded by!app/config/specs/**app/config/specs/swagger2-latest-server.jsonis excluded by!app/config/specs/**
📒 Files selected for processing (1)
app/controllers/api/account.php
🧰 Additional context used
🧬 Code graph analysis (1)
app/controllers/api/account.php (1)
src/Appwrite/GraphQL/Types/Mapper.php (1)
param(255-363)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: Setup & Build SDK
- GitHub Check: scan
🔇 Additional comments (1)
app/controllers/api/account.php (1)
71-71: LGTM - Import correctly added.The Range validator import is appropriate for validating the JWT duration parameter.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/e2e/Services/Account/AccountCustomClientTest.php (1)
1890-1940: Consider increasing the timing buffer to improve test reliability.The test creates a JWT with a 5-second duration, then sleeps for 6 seconds before verifying expiration. While this 1-second buffer should work in most cases, it could lead to flaky test failures if API calls experience delays.
Consider increasing the buffer for more robust testing:
- ]), [ - 'duration' => 5 - ]); + ]), [ + 'duration' => 10 + ]); ... - // Wait for JWT to expire - \sleep(6); + // Wait for JWT to expire (duration + 3 second buffer) + sleep(13);Minor style note: Line 1929 uses
\sleep(6)while other parts of the file usesleep()(which is imported on line 15). For consistency, consider usingsleep(6)without the backslash.</review_comment_end>
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/e2e/Services/Account/AccountCustomClientTest.php
🧰 Additional context used
🧬 Code graph analysis (1)
tests/e2e/Services/Account/AccountCustomClientTest.php (2)
tests/e2e/Client.php (1)
Client(8-342)tests/e2e/Scopes/Scope.php (1)
getProject(150-150)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: E2E Service Test (Webhooks)
- GitHub Check: E2E Service Test (Storage)
- GitHub Check: E2E Service Test (Health)
- GitHub Check: E2E Service Test (Teams)
- GitHub Check: E2E Service Test (Functions)
- GitHub Check: E2E Service Test (Account)
- GitHub Check: E2E Service Test (Projects)
- GitHub Check: E2E Service Test (Databases/TablesDB)
- GitHub Check: E2E Service Test (Locale)
- GitHub Check: E2E Service Test (FunctionsSchedule)
- GitHub Check: E2E Service Test (Avatars)
- GitHub Check: E2E Service Test (Console)
- GitHub Check: Unit Test
- GitHub Check: E2E Service Test (Site Screenshots)
- GitHub Check: E2E Service Test (Dev Keys)
- GitHub Check: E2E General Test
- GitHub Check: Benchmark
- GitHub Check: Setup & Build SDK
- GitHub Check: Linter
- GitHub Check: scan
✨ Benchmark results
⚡ Benchmark Comparison
|
What does this PR do?
appwrite/app/controllers/api/projects.php
Line 1720 in 96b11b0
appwrite/app/controllers/api/users.php
Line 2619 in 96b11b0
Checklist