First-party OAuth clients bypass the expired-password check (expiresAt) on OIDC sign-in

Issue Description

In v1.0.0 an expired main credential (password expiresAt in the past) correctly stops an OIDC sign-in to a registered client (“Your password has expired. Change it in the account portal, then sign in again.”). This was the fix for t/1933.

But when an administrator marks a registered OAuthClient as firstParty: true, the same expired password signs in and the client receives an authorization code. The description of firstParty only says that tokens carry the account’s full permissions and that the user is still asked for consent – it does not mention that password expiry is skipped.

Reproduced in a test instance (see steps). The cause seems to be in crates/http/src/auth/oauth/auth.rs (around line 688) and token.rs: the check is skipped with !client.is_first_party(), and ResolvedClient::is_first_party() is true both for Stalwart’s own web applications and for any registered client with first_party = true (this part checked in the source only). The exemption makes sense for the account portal, so the user can change the expired password there, but it also applies to third-party apps an admin marked as trusted.

Expected Behavior

An expired password stops OIDC sign-in to every client except Stalwart’s own web applications (account portal, admin UI), regardless of firstParty on a registered client – or the firstParty description documents that it also skips password expiry.

Actual Behavior

With firstParty: true on a registered client, a user whose password has expired completes the OIDC sign-in and the client receives an authorization code. With firstParty: false the same sign-in is refused with “Your password has expired. Change it in the account portal, then sign in again.” (as expected). IMAP login with the expired password is refused in both cases.

Reproduction Steps

  1. Register an OAuthClient (confidential, authorization code + PKCE, redirect URI of a webmail), scopes mail/contacts/calendars/files, firstParty: false.
  2. Set credentials/0/expiresAt of a user to a date in the past.
  3. Open the authorization URL for this client (Stalwart’s own login page), allow the consent, sign in with the expired password → “Your password has expired …”, no code (correct).
  4. Set firstParty: true on the same client and reload the settings.
  5. Repeat step 3 with the same user → the browser is redirected to the client’s redirect URI with an authorization code.

Relevant Log Output

Both sign-ins (firstParty false → refused, firstParty true → code issued) only log at info level:
INFO Authentication successful (auth.success) listenerId = “http”, accountName = “[email protected]”
No credential-expired event appears at info level in either case.

Stalwart Version

v1.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

Tested in a test environment after migrating from v0.16.27 with stalwart-migrate 1.0.0. Our workaround: firstParty only for stalwart-webui, not for our webmail and identity broker. Related: t/1933, t/2047.

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

Let me confirm the source check.

Your reading of the source matches what I found. I’m not a maintainer, so I can’t say whether this is intended. A human will follow up on that.

What the source shows

  • crates/http/src/auth/oauth/auth.rs (line 688) only refuses the sign-in with CredentialExpired when !client.is_first_party().
  • crates/http/src/auth/oauth/token.rs (lines 475 and 517) uses the same !is_first_party() condition. It covers both the refresh path and the credential-version check.
  • Both checks use the same is_first_party() result. So an OAuthClient registered with firstParty: true is exempt from the expiry check in the same way as an installed application such as the WebUI.

What the docs say

  • The first-party sections in OAuth clients and Register a client describe only two effects. First-party clients get unscoped tokens with the account’s full permissions, and consent is still shown.
  • Neither page says that password expiry is skipped, so the behaviour you saw isn’t documented.

Your workaround
Setting firstParty: true only on the client for stalwart-webui is consistent with the code. The refused sign-in is the only effect I could confirm for firstParty: false. I didn’t trace what else changes for scoped tokens.

I couldn’t find anything in the docs or source that says whether the exemption should apply to registered clients, or whether the docs should mention it.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

The code issued to a first-party client in that case doesn’t carry the account’s permissions. Every access token is checked against the password expiry when it’s used, and for a grant through a first-party client an expired password downgrades the token to authentication, reading and changing the password, and receiving mail. Your webmail gets a code and a token, but the token can’t open the mailbox, calendars or files until the password has been changed. Only third-party grants are refused outright (access_token.rs, assert_is_valid).

That’s deliberate: firstParty is meant for applications that act as part of the server, like a WebUI build hosted elsewhere, where the user should land on the password change screen. The password policy page describes the restricted state.

For a webmail or an identity broker, your workaround is the right configuration: leave firstParty off so they get scoped tokens and a clear “password expired” message at sign-in. The firstParty description should say this, and I’ll get the docs updated.

Thank you for the clarification!