# Server-side forgot-password, recovery-email, and user-invite

**URL:** https://support.stalw.art/t/server-side-forgot-password-recovery-email-and-user-invite/291
**Category:** Feature Ideas
**Created:** [May 20, 2026, 4:11am UTC](https://support.stalw.art/t/server-side-forgot-password-recovery-email-and-user-invite/291 "2026-05-20T04:11:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gbatkhuyag](https://support.stalw.art/user_avatar/support.stalw.art/gbatkhuyag/32/224_2.png) [@gbatkhuyag](https://support.stalw.art/u/gbatkhuyag)
#### Post date: [May 20, 2026, 4:11am UTC](https://support.stalw.art/t/server-side-forgot-password-recovery-email-and-user-invite/291/1 "2026-05-20T04:11:48Z")

</div>

## Proposed features

### 1. Forgot-password (self-service password reset)

**New unauthenticated endpoints:**

```auto
POST /api/auth/forgot-password
Body: { "username": "alice" }
Response: 200 OK (always, to prevent user enumeration)

```

```auto
POST /api/auth/reset-password
Body: { "token": "<opaque>", "newPassword": "…" }
Response: 200 OK | 400 Bad Request (expired / already used)

```

**Server behaviour:**

1. Look up the principal. If not found → silently no-op (anti-enumeration).

2. Resolve recovery email (see feature 2 below). If none → silently no-op.

3. Generate a 256-bit random token; store `SHA-256(token)` + TTL (e.g. 1 h) + account ID in the existing key-value store.

4. Send a reset email via Stalwart’s own SMTP delivery.

5. On `reset-password`: validate token with constant-time comparison, mark single-use, call the existing `SysAccountPasswordUpdate` path to set the new password.

**Rate limiting:** per-IP and per-username buckets — consistent with the existing `is_http_anonymous_request_allowed`framework.

**Configuration** (feature is off when not configured):

| Key | Purpose |
| --- | --- |
| `auth.password-reset.enabled` | Master switch (default: `false`) |
| `auth.password-reset.token-ttl` | Token lifetime (default: `1h`) |
| `auth.password-reset.from-email` | Sender address for reset emails |
| `auth.password-reset.base-url` | Public origin used in the reset link |

No external SMTP config needed — Stalwart already delivers mail.

* * *

### 2. Recovery-email on principal

A `recoveryEmail` field on the principal/account used solely for out-of-band identity actions (password reset, invites). It is **not** an email alias and does not receive regular mail.

**Self-service endpoints (requires the user’s own session token):**

```auto
GET /api/account/recovery-email
Response: { "recoveryEmail": "alice-backup@example.com" | null }

PUT /api/account/recovery-email
Body: { "recoveryEmail": "alice-backup@example.com" }
Response: 200 OK

```

**Resolution order for password-reset emails:**

1. `principal.recoveryEmail` (new field)

2. First address in `principal.emails[]`

**Privilege model:** reading and writing this field requires only the user’s own session — no admin token. This maps to new fine-grained permissions (e.g. `SysAccountRecoveryEmailGet` / `SysAccountRecoveryEmailUpdate`) that are granted to regular users by default, consistent with how `SysAccountPasswordGet/Update` works today.

* * *

### 3. User invite (admin-initiated onboarding)

An admin can trigger a welcome / account-activation email that generates the same kind of single-use reset token and delivers it to the user’s recovery email (or first email address).

**New endpoint (requires a dedicated `SysAccountInvite` permission):**

```auto
POST /api/admin/invite-user
Body: { "username": "bob" }
Response: 200 OK

```

The email contains a `/reset-password?token=…` link. The invited user sets their own password on first login — no password is ever set by the admin on their behalf.

**`stalwart-cli` counterpart:** `stalwart-cli account invite <username>`

* * *

## What this is NOT

- A full OAuth2 “device authorization” or PKCE flow — that already exists.

- Mandatory: all three features are **off by default** , zero impact on existing deployments unless explicitly enabled.

- Specific to Bulwark: these endpoints are generic HTTP; any JMAP client or CLI tool can use them.

* * *

## Relation to the existing codebase

| Existing piece | How it is reused |
| --- | --- |
| `RECOVERY_ADMIN_ID` | Unchanged — still the emergency CLI admin |
| `SysAccountPasswordUpdate` | Called by the `reset-password` handler |
| `validate_access_token` / `encode_access_token` | Pattern for short-lived reset tokens |
| `is_http_anonymous_request_allowed` | Rate limiting for the unauthenticated endpoints |
| Stalwart SMTP delivery | Sends reset / invite emails — no new SMTP config required |
| `handle_account_request` / `AccountApiHandler` | Extended with recovery-email GET/PUT |

* * *

## Acceptance criteria

- `POST /api/auth/forgot-password` — unauthenticated, rate-limited, always returns 200

---

<div class="post-metadata">

### Author: ![dataforge](https://support.stalw.art/letter_avatar_proxy/v4/letter/d/47e85d/32.png) [@dataforge](https://support.stalw.art/u/dataforge)
#### Post date: [November 14, 2026, 2:35am UTC](https://support.stalw.art/t/server-side-forgot-password-recovery-email-and-user-invite/291/2 "2026-11-14T02:35:02Z")

</div>

+1 for this, from a hosting provider moving about 50 small-business customers off cPanel onto Stalwart v1.1.0, each domain as its own tenant.

cPanel lets a mailbox owner set a recovery address and reset a forgotten password themselves. On v1.1.0 there is no field on an Account for that, and a reset is admin-only (Reset a password, auth/accounts/manage). So every forgotten password becomes a ticket for the tenant admin or for us, and the recovery addresses our users set in cPanel have nowhere to go.

Since 1.x moved account management into the registry, a smaller version of the request above might fit better than new `/api/auth` endpoints:

1. An optional `recoveryAddress` on Account, editable by the user from their own account, by their tenant admin and by admins. It receives no mail and is not an alias.
2. Set only after a verification link sent to it is clicked, so a stolen session cannot quietly point recovery somewhere else. A notice goes to the mailbox itself whenever it changes.
3. A “forgot password” link on the sign-in page that sends a short-lived, single-use reset link to the verified address. Same answer whether or not the account exists, with rate limits per IP and per account.
4. A reset by link clears the password but keeps the account’s TOTP, so a lost mailbox password does not also bypass 2FA.
5. A server-wide switch, plus a per-tenant switch so a tenant can turn it off for its own domains.

The same verified address would also serve as the place to send quota warnings once a mailbox is full and can no longer receive mail, but the reset flow is the main need.

Checked against v1.1.0 source and docs; written with AI help.
