Issue Description
Principal/query appears to fail open when a name or email filter cannot be resolved to an account id.
Relevant code:
crates/jmap/src/principal/query.rs
PrincipalFilter::Name(name) | PrincipalFilter::Email(name) => {
if let Some(account_id) = self.account_id_from_email(&name, false).await? {
filters.push(SearchFilter::is_in_set(
RoaringBitmap::from_sorted_iter([account_id]).unwrap(),
));
}
}
If account_id_from_email(&name, false) returns None, no filter is pushed.
That unresolved path is reachable because account_id_from_email() returns Ok(None) when the address cannot be mapped to an account.
Relevant code:
crates/common/src/cache/principals.rs
Ok(result.and_then(|result| {
if let EmailCache::Account(account_id) = result {
Some(account_id)
} else {
None
}
}))
and:
Ok(None)
Later, SearchQuery::filter() returns the full mask when there are no filters:
crates/store/src/search/local.rs
if self.filters.is_empty() {
return QueryResults {
results: self.mask,
comparators: self.comparators,
};
}
So an unresolved exact name / email predicate can result in all visible principals being returned instead of zero results.
Expected Behavior
If PrincipalFilter::Name or PrincipalFilter::Email cannot be resolved to an account id, the query should return no principals.
The unresolved predicate should not broaden the query.
Actual Behavior
The unresolved predicate is omitted from the search filter list.
If this leaves the query with no filters, SearchQuery::filter() returns the whole visible-principal mask.
Stalwart Version
v0.16.x
Installation Method
Binary (Linux)
Database Backend
PostgreSQL
Blob Storage
PostgreSQL
Search Engine
Internal
Directory Backend
SQL
Additional Context
Assume a tenant has multiple visible principals:
A client sends Principal/query with an exact email or name filter that does not resolve to an account.
Instead of returning an empty result, the unresolved predicate may be omitted. If no other filters remain, the search can return all visible principals for that tenant.
The client then receives multiple candidates for what was intended to be a single-principal lookup.
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