Skip to content

fix: keep write-only secrets on their endpoint and bind ephemeral keys to the project sequence - #14795

Merged
ChiragAgg5k merged 5 commits into
mainfrom
fix/write-only-secret-and-key-binding
Oct 22, 2026
Merged

ChiragAgg5k merged 5 commits into
mainfrom
fix/write-only-secret-and-key-binding

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What was vulnerable

This PR addresses two separate credential-boundary issues.

1. Redirecting a write-only secret to a different server

SMTP passwords and OAuth2 client secrets are hidden from API responses. However, a caller authorized to update the corresponding project settings could change the server endpoint while omitting the secret. The partial update retained the stored secret and paired it with the caller's new endpoint.

That let the caller make Appwrite send a secret they could not read through the API to a server they controlled: during SMTP credential verification/authentication, or a subsequent OAuth authorization-code exchange.

BEFORE
Stored configuration: trusted server + write-only secret S
                                  |
Caller with settings write access |
PATCH endpoint = attacker server  |
      secret   = omitted          |
              |                   |
              v                   v
       Merge new endpoint + retain S
                      |
                      v
        Appwrite authenticates to attacker server
                      |
                      v
             Attacker receives S

AFTER
Endpoint changes + stored secret + secret omitted
                      |
                      v
       400 general_argument_invalid
       before secret reuse or persistence

Endpoint changes + explicit secret supplied
                      |
                      v
       Use the explicitly supplied credentials

The fix adds guards before the stored credentials are merged:

  • SMTP: changing host, port, or secure requires password in the same request when a password is stored.
  • OAuth2: changing a configurable endpoint requires the client secret in the same request. This covers OIDC discovery/authorization/token/user-info URLs, GitLab, Auth0, Authentik, FusionAuth, Okta domain/authorization server, and Keycloak domain/realm.
  • Same-endpoint updates retain the existing secret. An explicit empty secret clears it; configurations without a stored secret can change endpoints without re-supplying one.
  • Microsoft's tenant setting is unchanged: it selects a path on Microsoft's fixed host.

This requires settings write access; it is not an unauthenticated secret-read endpoint.

2. Replaying an ephemeral key after a public project ID is reused

Ephemeral keys previously signed only the public project ID. Deleting a project did not invalidate its outstanding JWTs. If a new project reused that public ID before a key expired, a holder of the old key could authenticate to the new project with the key's scopes.

BEFORE
Project A: id = demo, sequence = 101
    |
    +-- issue key { projectId: demo }
    |
    +-- deleted

Project B: id = demo, sequence = 202
    |
    +-- old key: demo == demo ------> ACCEPTED
                                      |
                                      v
                              Access to a different project

AFTER
Project A issues signed key:
    { projectId: demo, projectSequence: 101 }
                          |
                          v
Project B: id = demo, sequence = 202
                          |
                  101 != 202
                          |
                          v
                   UNAUTHORIZED

All seven project-bound issuance paths now sign projectSequence: project and organization ephemeral-key endpoints, synchronous and worker function executions, migration workers, deployment runtime keys, and function/site proxying. Key::decode() rejects a sequence mismatch. The existing projectCheckDisabled bypass remains unchanged.

Compatibility and rollout

  • Legacy keys without projectSequence remain accepted until expiry. The residual replay window can last up to 24 hours, including migration keys; the public ephemeral-key endpoints cap duration at one hour. Newly issued keys include the signed claim, which cannot be removed without invalidating the signature. All issuers must be updated before the legacy-key window can close.
  • Console SMTP password guidance is updated in this PR, including Hebrew and Japanese translations: leave blank to keep the current password, and re-enter it when changing the host, port, or secure protocol.
  • The SMTP guard uses an explicit empty-string comparison, so the valid password "0" also requires re-supply when changing the server.

Added coverage

  • Key unit tests: reject mismatched sequences; accept matching string/integer sequences; preserve projectCheckDisabled and legacy claimless-key behavior.
  • SMTP E2E: reject host/port/security changes without a password for both ordinary passwords and "0"; allow the same server, an explicit password, and changes with no stored password. Existing server-change tests now supply their password.
  • OAuth2 E2E: parameterized coverage across all seven configurable providers, including Okta authorization-server and Keycloak realm changes; reject omitted secrets and accept unchanged endpoints or explicitly supplied replacement secrets.

Console Hebrew and Japanese translation audits passed, and the new hint is present in both merged dictionaries. Focused Pint and PHPStan checks passed for the SMTP action and E2E trait. The focused SMTP E2E run could not start because the local appwrite Docker service is not running; runtime validation relies on the CI Project lanes.

Related: appwrite-labs/cloud#6666

…hanges

SMTP passwords and OAuth2 client secrets are write-only, but a partial
update kept the stored secret while pointing it at a new server. Changing
the SMTP host, port or secure mode, or an OAuth2 provider's domain or
endpoints, now requires the secret in the same request (400 otherwise), so
a stored secret is only ever sent where it was configured.
Ephemeral keys only carried the public project ID, which can be reused by
a new project after deletion. Issuers now sign the project's internal
sequence too, and decoding refuses a key whose sequence differs. Keys
issued before this carry no sequence and are still accepted until they
expire.
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR hardens credential handling in three ways: ephemeral API keys are bound to the issuing project's sequence so stolen keys die with project delete/recreate, OAuth2 provider updates now require re-supplying the write-only client secret when the stored endpoint changes, and SMTP updates require the password when host/port/secure change. Note: two sub-80-confidence candidate findings were not kept (a legacy plain-secret bypass in requireSecretOnEndpointChange, and the guard not yet extended to Microsoft/Apple tenant changes); the correctness shard covering the workers/tests also ended early without a written report, so worker-side projectSequence issuance was verified only via the holistic pass.

Files Change
src/Appwrite/Auth/Key.php, app/controllers/general.php, src/Appwrite/Deployment/Deployments.php, src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php, both Keys/Ephemeral/Create.php, Workers/Functions.php, Workers/Migrations.php Embed projectSequence in every ephemeral JWT and reject ephemeral keys whose sequence no longer matches the project, with back-compat for claim-less keys and a projectCheckDisabled bypass.
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php plus the seven provider Update.php handlers Add requireSecretOnEndpointChange(): changing a stored endpoint (domain, realm, issuer, etc.) without re-supplying the client secret returns a validation error.
src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php Require the SMTP password when host, port, or secure mode changes; keep write-only password semantics and empty-password clearing.
tests/unit/Auth/KeyTest.php, tests/e2e/Services/Project/OAuth2Base.php, tests/e2e/Services/Project/SMTPBase.php Cover sequence-bound key decode, the endpoint-change guard across providers, and the SMTP server-change guard.
src/Appwrite/Platform/Workers/Migrations.php Same projectSequence claim added to the 24h migration API key.

Reviewed commit: 682822a

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The pull request prevents partial updates from reusing stored SMTP or OAuth2 secrets with changed endpoints, and updates the Console guidance for SMTP password reuse. Newly issued project-bound ephemeral keys include the project sequence, which is checked during key decoding to prevent reuse after a public project ID is recycled; regression coverage was added for these behaviors.

Latest changes: The latest commits make the SMTP stored-secret check treat the valid password "0" as present, add parameterized E2E coverage for that case, and update the SMTP password hint in Console and its Hebrew and Japanese dictionaries.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
app/controllers/general.php; src/Appwrite/Auth/Key.php; tests/unit/Auth/KeyTest.php Add project-sequence validation when decoding ephemeral keys, with unit coverage for matching, mismatched, legacy, and bypass cases.
src/Appwrite/Deployment/Deployments.php; src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php; src/Appwrite/Platform/Modules/Organization/Http/Projects/Keys/Ephemeral/Create.php; src/Appwrite/Platform/Modules/Project/Http/Project/Keys/Ephemeral/Create.php; src/Appwrite/Platform/Workers/Functions.php; src/Appwrite/Platform/Workers/Migrations.php Include the project sequence in keys issued for deployments, executions, ephemeral-key endpoints, and workers.
src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php; src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/{Auth0,Authentik,FusionAuth,Gitlab,Keycloak,Oidc,Okta}/Update.php; tests/e2e/Services/Project/OAuth2Base.php Require the write-only OAuth2 client secret when configurable provider endpoints change and cover provider cases through E2E tests.
src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php; tests/e2e/Services/Project/SMTPBase.php Require a password when SMTP server settings change while a password is stored, including the valid value "0", and exercise the guard and allowed update cases.
apps/console/src/components/pages/projects/$projectId/settings/SMTP.tsx; apps/console/src/lib/i18n/dictionaries/he/project-misc.ts; apps/console/src/lib/i18n/dictionaries/ja/project-misc.ts Explain that users must re-enter the SMTP password when changing server settings, with updated Hebrew and Japanese translations.
tests/e2e/Services/Project/OAuth2Base.php Add endpoint-change regression cases across the configurable OAuth2 providers, including the newly covered provider mappings.

Reviewed the commits since 539d7ad · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/write-only-secret-and-key-binding (after).

Metric Before After Change
🚀 Requests/sec 191.61 189.4 ⚪ -1.2%
⏱️ Latency P50 88.41 ms 91.36 ms ⚪ +3.3%
⏱️ Latency P95 211.61 ms 210.58 ms ⚪ -0.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 91.36 210.58 11,799 189.4 -1.03
Account 171.44 303.06 621 10.28 -0.18
TablesDB 88.8 167.26 6,417 104.95 +2.05
Storage 83.17 190.3 3,105 52.67 -16.35
Functions 129 243.41 1,656 28.97 +4.33

Top API waits (after)

API request Max wait (ms)
functions.create 428.52
account.name.update 418.59
storage.buckets.create 406.47
account.prefs.update 386.33
functions.variables.update 377.42

… provider

Each provider maps its params to different stored keys, so exercise GitLab,
Authentik, FusionAuth, Keycloak (domain and realm) and Okta's authorization
server too, and reset those providers between tests.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@14795

commit: 3434af7

@ChiragAgg5k
ChiragAgg5k merged commit 2fced02 into main Oct 22, 2026
73 of 74 checks passed
JadeCong pushed a commit to CloudEngineHub/appwrite that referenced this pull request Oct 23, 2026
The private-host test changes the host after an earlier test stored a
password, so the write-only password rule (appwrite#14795) rejected it before the
public-host check (appwrite#14811) ran.
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…-and-key-binding

fix: keep write-only secrets on their endpoint and bind ephemeral keys to the project sequence
(cherry picked from commit 2fced02)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
1.9.x now requires the password again whenever the SMTP host changes (backport of #14795), so the private-host regression test passes it.
sarbojitrana pushed a commit to sarbojitrana/appwrite that referenced this pull request Nov 2, 2026
…meral keys to the project (backport appwrite#14795)

(cherry picked from commit 2fced02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant