Repository navigation
fix(vcs): bind Entire and Origin installation state to the console user (appwrite:appwrite:alert#4626) - #15181
Conversation
The hardening that introduced Appwrite\Vcs\State -- projectId plus userId, an expiry and a single-use nonce under the HMAC -- reached the GitHub App callback and the shared OAuth callback, but not the Entire and Origin flows. Those two still signed only the project id and the two redirect URLs, and their public callbacks accepted any state whose HMAC verified, with no user injected, no expiry and no nonce. A project member could hand the resulting install link to a victim and have the victim's installation -- and so the plugin's repository read and write access -- recorded under the member's own project. Move all four actions onto State: the authorize actions inject the user and sign through State::create(), and the callbacks verify with State::verify(), reject an expired state and a user who did not start the flow, and consume the nonce, which also gives Origin the single-use guard it had none of. The receipt's state claim is now the authoritative one, so a provider-signed receipt can no longer be re-paired with an attacker-supplied state. State itself grows the base64url transport Entire needs for its opaque state token, which the Entire callback used to hand-roll. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
The change introduces a signed, expiring VCS state token (
Reviewed commit: 9e4ecd5 |
🔵 Tier A · Mergeable after minor fixes
Entire and Origin installation callbacks now use signed, user-bound state with expiry and single-use nonce checks, while their authorization flows create that state. The shared State implementation supports base64url transport, and regression tests cover bound and legacy states. The callbacks also treat the provider receipt's state claim as authoritative over a query parameter. Latest changes: The latest commits type-check the receipt state claim before using it, avoiding coercion of non-string claims in both callbacks.
Note Not approving while a bug finding is open: Reject present non-string receipt state claims
Fix with agent prompt### Issue 1
src/Appwrite/Platform/Modules/VCS/Http/Entire/Callback/Get.php:105
**Reject present non-string receipt state claims**
If a verified receipt contains `state` as an array or number, this maps it to `''`, so the following fallback accepts the caller-supplied query state instead of rejecting the malformed claim. That weakens the receipt-authoritative check and regresses the previous behavior, which failed verification for these non-string values; the same issue is present in Origin's callback at line 92.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 7
Reviewed the commits since |
A provider that echoed the state as a nested object instead of a string would have reached \strval() on an array. The query parameter stays the fallback for that case, as it was before the claim became authoritative. Co-Authored-By: Claude Opus 5 <[email protected]>
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
There was a problem hiding this comment.
This PR reworks the VCS Entire/Origin OAuth install flows by moving state signing/verification into src/Appwrite/Vcs/State.php, adding single-use state and receipt locks in vcsCommentLocks, and binding callbacks to the initiating console user.
Key findings
- 🟡 State lock consumed before installation attach completes — Get.php:129
| $state = $this->verifiedState(!empty($state) ? $state : \strval($receiptClaims['state'] ?? '')); | ||
| $projectId = $state['projectId'] ?? ''; | ||
| $redirectFailure = $state['failure'] ?? ''; | ||
| $receiptState = \is_string($receiptClaims['state'] ?? null) ? $receiptClaims['state'] : ''; |
There was a problem hiding this comment.
Reject present non-string receipt state claims
If a verified receipt contains state as an array or number, this maps it to '', so the following fallback accepts the caller-supplied query state instead of rejecting the malformed claim. That weakens the receipt-authoritative check and regresses the previous behavior, which failed verification for these non-string values; the same issue is present in Origin's callback at line 92.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/VCS/Http/Entire/Callback/Get.php
Line: 105
Comment:
**Reject present non-string receipt state claims**
If a verified receipt contains `state` as an array or number, this maps it to `''`, so the following fallback accepts the caller-supplied query state instead of rejecting the malformed claim. That weakens the receipt-authoritative check and regresses the previous behavior, which failed verification for these non-string values; the same issue is present in Origin's callback at line 92.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · security · Reply if this doesn't apply.
There was a problem hiding this comment.
Fixed in 5bc3223: both the Entire and Origin callbacks now refuse a receipt whose state claim is present but not a string, instead of falling back to the query parameter.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…-state-binding # Conflicts: # src/Appwrite/Platform/Modules/VCS/Http/Entire/Authorize/Get.php # src/Appwrite/Platform/Modules/VCS/Http/Entire/Callback/Get.php # src/Appwrite/Platform/Modules/VCS/Http/Origin/Authorize/Get.php # src/Appwrite/Platform/Modules/VCS/Http/Origin/Callback/Get.php # src/Appwrite/Vcs/State.php
…before the attach A receipt whose state claim is present but not a string is now refused instead of falling back to the query parameter. The single-use state and receipt claims are taken after the project and installation id checks, so a callback that fails those checks can be retried with the same state.
🟢 Tier S · Ready to mergeMoves Entire and Origin installation state onto the shared signed
📂 Walkthrough · 7
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed |
…inding fix(vcs): bind Entire and Origin installation state to the console user (appwrite:appwrite:alert#4626) (cherry picked from commit 2e592b3)
What
Closes code-scanning alert appwrite:appwrite:alert#4626.
The hardening that introduced
Appwrite\Vcs\State—projectIdplususerId, an expiry and a single-use nonce under the HMAC — reachedGitHub/Callback/Get.phpand the shared OAuthCallback/Base.php, but the Entire and Origin flows were never migrated. Before this PR,grep 'State::'overModules/VCS/Httpmatched only those two call sites.Both Entire and Origin signed
hash_hmac('sha256', json_encode([$projectId, $success, $failure]), $key)— no user, no expiry, no nonce — and theirscope => publiccallbacks injected nouserand verified that HMAC alone.Impact
A console user with
vcs.readon any project could callGET /v1/vcs/entire/authorize(or/v1/vcs/origin/authorize) for their own project, capture the install URL that embeds the signed state verbatim, and send it to a victim. When the victim approved the Appwrite plugin for their own Entire project / Cursor workspace, the callback verified only the HMAC over the attacker'sprojectIdand wrote aninstallationsdocument holding the victim'sproviderInstallationIdunder the attacker's project.Factory::fromInstallation()mints provider credentials from the server-wideappId/privateKeyplus that installation id, so no victim-held token is needed: the attacker's project gained the plugin's full scope set — includingrepository:contents:writeandrepository:pull_requests:write— over the victim's repositories.Two secondary defects on the same path: the state never expired, so a leaked or logged one stayed usable forever, and the Origin callback had no single-use record at all.
How
All four actions move onto
Appwrite\Vcs\State, mirroringGitHub/Callback/Get.php:Entire/Authorize/Get.php,Origin/Authorize/Get.php— injectuserand sign throughState::create($project->getId(), $user->getId(), $success, $failure). Origin gains theAPP_LIMIT_VCS_STATEcheck its sibling already had, and its callback'sstateparam moves from a bare4096to that constant.Entire/Callback/Get.php,Origin/Callback/Get.php— injectuser, verify withState::verify(), then reject an expired state, reject$user->isEmpty() || $user->getId() !== $state->userId, and consume$state->nonceas a single-usevcsCommentLocksdocument. That last one is the single-use guard Origin had none of; Entire's existing receiptjtilock stays as defence in depth.stateclaim is now authoritative, and a querystatepresent alongside it musthash_equalsit, so a provider-signed receipt can no longer be re-paired with an attacker-supplied state.Stategrows the base64url transport Entire needs for its opaque state token (encode(), andverify()reading either form), replacing thedecodeState()the Entire callback hand-rolled.Tests
TDD, red first:
tests/e2e/Services/VCSEntire—testCreateInstallationCancelledWithUnboundStatebuilds a state signed the legacy way (project + two redirect URLs, no user, expiry or nonce) with the server's real_APP_OPENSSL_KEY_V1and asserts the callback refuses it with nolocationheader. Onmainthat state verifies and the callback redirects. Its counterparttestCreateInstallationCancelledWithBoundStateasserts a properly bound state is still accepted, which also fails onmain— the old three-field check rejects a six-field signature.tests/unit/Vcs/StateTest.php—testVerifiesEncodedState/testRejectsEncodedOtherKeycover the new opaque-token transport (both errored before the change, asencode()did not exist), andtestRejectsUnboundStatepins, in both encodings, that a state withoutuserId,expireandnoncenever verifies.Verified locally in a PHP 8.5 container:
tests/unit/Vcsgreen (107 tests), Pint and PHPStan clean on the touched files,composer refactor:checkclean. The Entire e2e lane was not run locally — the only Appwrite stack on this host belongs to another checkout and binds :80/:443/:9501, so a second stack would collide;.github/ci/e2e.jsonalready mapssrc/Appwrite/Platform/Modules/VCS/to theVCSEntireandVCSGitHublanes, so CI covers it. The 17 unit errors outsidetests/unit/Vcsare environmental (KeyTestneeds_APP_OPENSSL_KEY_V1,ListCacheTestneeds Redis) and are unrelated to this change.🤖 Generated with Claude Code