Multi-tenancy: JMAP sharing (shareWith) is not restricted to the same tenant

Issue Description

With an Enterprise license and two tenants, a user of Tenant A can share a calendar, mailbox or address book with an account of Tenant B via JMAP (shareWith/). The share is accepted, and the Tenant B user then sees the Tenant A account in its session and can read the shared data. The directory itself is isolated correctly (Principal/query only returns the own tenant, foreign ids are notFound), so this looks like a missing tenant check on shareWith.

Setup: two tenants, each with one domain and two user accounts, memberTenantId set on domains and accounts, users with the default User role.

Expected Behavior

Setting shareWith to a principal of a different tenant is rejected (for example invalidProperties or forbidden), the same way the directory hides principals of other tenants. The tenants documentation says that “principals that belong to one tenant cannot reach resources that belong to another” (Tenants | Stalwart), and in Item references with multiple tenants cross-tenant references are described as blocked by design.

Actual Behavior

The share is accepted for Calendar/set, Mailbox/set and AddressBook/set. The Tenant B user sees the Tenant A account in its JMAP session and Calendar/get on that account returns the shared calendar.

In addition, the error reveals which ids exist: shareWith/ fails with invalidProperties (“Account id … is invalid”), while the id of an account in another tenant is accepted. Principal ids are short and sequential, so a user can enumerate principals of other tenants although the directory is hidden.

Reproduction Steps

  1. Create Tenant A and Tenant B; assign one domain and two user accounts to each (memberTenantId).
  2. Log in as user A1 (Tenant A) and send:
    [“Calendar/set”, {“accountId”: “”, “update”: {“”: {“shareWith/”: {“mayReadItems”: true}}}}, “0”]
    where is the principal id of a Tenant B account.
  3. The update succeeds (no notUpdated).
  4. Log in as B1: the session lists account , Calendar/get on returns the calendar.
  5. Same result with Mailbox/set and AddressBook/set (shareWith/).
  6. shareWith/ fails with “Account id … is invalid”, a foreign valid id succeeds.

Relevant Log Output

No errors are logged; all requests succeed.

Stalwart Version

v0.16.x

Installation Method

Binary (Linux)

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

Tested on a test instance with an Enterprise trial license, accessed directly via JMAP behind an nginx reverse proxy. Not tested: FileNode and group principals as share targets.
The report was written with the help of an AI assistant (Claude); I checked the steps and results.

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

Your findings check out against the current source. The validation path for shareWith (acl_validate in crates/jmap/src/api/acl.rs) only checks that the target account_id exists in the registry of all accounts and does not check tenant_id membership at all:

async fn acl_validate(&self, grants: &[AclGrant]) -> Result<(), ShareValidationError> {
    ...
    let principal_ids = self
        .registry()
        .query::<RoaringBitmap>(RegistryQuery::new(ObjectType::Account))
        .await
        .unwrap_or_default();

    for grant in grants {
        if !principal_ids.contains(grant.account_id) {
            return Err(ShareValidationError::InvalidAccountId(Id::from(grant.account_id)));
        }
    }
    Ok(())
}

This query pulls from the global account registry across all tenants, so any existing account id (including one belonging to another tenant) passes validation, which matches what you observed: a foreign-tenant id is accepted while a nonexistent id returns invalidProperties. The session/account visibility and Calendar/get/Mailbox/get/AddressBook/get paths then honor the ACL grant without re-checking tenant boundaries, so the share is effectively cross-tenant. This is consistent with your report, the tenant isolation described in the docs (Tenants | Stalwart) is not being enforced at this specific ACL-validation step. A staff member will need to confirm the intended fix (tenant check added to acl_validate and to the session/account-visibility lookups).

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

Confirmed on 0.16: the share validation there only checks that the grantee exists, with no tenant comparison. 1.0.0, which is out now, adds the check for shareWith on calendars, address books, mailboxes and file nodes (and the equivalent WebDAV ACL path). A grantee in another tenant is now rejected with the same “Account id … is invalid” error as an id that doesn’t exist, so the response no longer tells you which ids are real.

The check only runs when a grant is added, so cross-tenant shares created while you were on 0.16 stay in place after upgrading. Remove those from the owning accounts once you’re on 1.0.