Stalwart: Anonymous Takeover of an Instance Before Initial Setup Completes

An unauthenticated attacker forges an access token for a Stalwart server whose initial setup is still running, completes the setup with their own values and keeps a permanent administrator account.

Advisory ID: TP-2026-137
Product: Stalwart (open-source mail and collaboration server with SMTP, IMAP, JMAP, CalDAV, CardDAV and WebDAV)
Vulnerability type: Empty default key for OAuth access tokens during initial setup (CWE-1188)
CVE: not requested
CVSS 3.1: 9.8 (Critical) · CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Affected versions: up to and including v0.16.27 (verified live: v0.16.21 and v0.16.22 with the official Docker images)
Fixed in: v1.0.0
Reported: 17 September 2026

Summary

Stalwart is an open-source mail and collaboration server. Until the initial setup is complete, the server does not create the object that holds the random key for its OAuth access tokens and therefore seals tokens with the empty key. Whoever knows the key issues valid tokens, and the empty key is known to everyone. An unauthenticated attacker forges a token for the administrator recovery account, completes the setup through x:Bootstrap/set with their own values and receives the credentials of a permanent administrator account. The same state arises when a configured instance starts with STALWART_RECOVERY_MODE after losing its data store.

Root cause

Line numbers refer to v0.16.22. insert_safe_defaults returns early in bootstrap mode (crates/common/src/manager/defaults.rs:80-94) and in recovery mode (crates/common/src/manager/defaults.rs:96-98), before the OidcProvider object with its random 64-character encryption_key is created (crates/common/src/manager/defaults.rs:345-374).
The schema default of the field is the empty string, and secret() returns Ok("") for it instead of an error (crates/registry/src/utils/secret.rs:17), so the random fallback in crates/common/src/auth/oauth/config.rs:143-148 never fires.
The server therefore derives the token sealing key from the empty string (crates/common/src/auth/oauth/crypto.rs:23, crates/common/src/auth/oauth/token.rs:20-21).
A token for the account id RECOVERY_ADMIN_ID (u32::MAX, crates/common/src/auth/mod.rs:35) receives the full administrator permission set.
The setup listener accepts plaintext connections on all interfaces on port 8080 (crates/common/src/config/server/listener.rs:63-88), and the empty key stays valid after the setup completes until the next process start.

Proof of Concept

Schematically:

1. GET /auth/jwks.json
   -> {"keys":[]}          (instance is still in initial setup)

2. Create an access token for account 4294967295 (RECOVERY_ADMIN_ID),
   sealed with the key blake3::derive_key("stalwart-oauth-token-sw1", "")

3. JMAP call x:Bootstrap/set with Authorization: Bearer <forged token>
   -> 200, the response contains the credentials of the newly created administrator

/auth/jwks.json returns an empty key list only before the setup completes, so the vulnerable state is remotely detectable without authentication. Verified on v0.16.22 in the default configuration: the token sealed with the empty key was accepted, the same token sealed with a different key received 401, and x:Bootstrap/set answers 401 without a token.

Impact

  • Complete takeover of a freshly started server without an account and without any action by the operator.
  • The attacker's administrator account survives a restart; the operator sees their own setup run appear to succeed and is locked out afterwards.
  • Read access to the entire server configuration and all accounts, write access to all settings.
  • The login with the forged token appears in the log as a regular successful administrator login.

References

Is Something Like This in Your Software?

Our team found this vulnerability during its work. Have your applications tested by the same specialists, with a penetration test from turingpoint.