Repository navigation
In review
Description
When a user password is stolen, the mailbox is used to send thousands of spam messages before anyone notices. The antispam filter does not stop it: such messages look legitimate.
The goal is to limit how many messages each user can send, and alert the administrator.
Proposed solution
Limit how many messages each authenticated user can send in a given time. Mail received from other servers is not affected.
- When a user exceeds the limit, further messages are refused until the limit refills. Possible approaches:
- temporary refusal: the mail client retries later, so a legitimate user loses nothing;
- permanent refusal, with a clear message for the user;
- both: a temporary refusal first, and a permanent one if the user keeps sending.
- Some users legitimately send more (newsletters, scanners, applications): the administrator can give them higher limits or exclude them.
- Opt-in: the feature is off by default, so existing installations do not change behavior after the update. The administrator enables it explicitly.
- Configuration: no UI for now. The limits are set with environment variables of the Mail module. Ideally one or two variables drive the whole configuration, and the other values are derived from them with formulas in the configuration templates. For example,
RSPAMD_RL_HOURLYsets the maximum number of messages per hour for each user: if it is not set, empty,0or-1, the whole rate limiter is off. - Notification: the Mail module exports metrics about users hitting the limit to the Metrics module (ns8-metrics). An alert rule notifies the administrator through the existing alert channels (mail, cluster alert list, my.nethesis.it), so the password can be changed quickly. A Grafana dashboard could show the trend.
The Rspamd ratelimit module, already part of the Mail application, provides the limits. A quick test with Mail 2.0 confirmed that the approaches above are feasible with configuration only, and that the Rspamd configuration templates can compute values from environment variables.
Alternative solutions
- A configuration UI in the Filter page: can be added later, on top of the environment variables.
- Limits applied by the mail server itself (Postfix), for example with a policy service.
- Notification only, without blocking: simpler, but it does not stop the damage.
See also
Metadata
Metadata
Assignees
Labels
verifiedAll test cases were verified successfully
Type
Projects
- StatusShow more project fieldsVerified
Activity
DavidePrincipi commentedon Nov 27, 2026
Testing release: Mail
2.0.0-beta.6(NethServer/ns8-mail#358)The feature is experimental and opt-in. The automated tests already cover the basic limit, the bulk and exempt lists, unauthenticated messages and disabling. Test cases left for manual QA:
/var/lib/rspamd/ratelimit_bulk.mapandratelimit_exempt.mapexist inside therspamdcontainer.RSPAMD_RL_HOURLY=12instate/rspamd.env, runsystemctl --user reload rspamd, then send some messages from Thunderbird, Outlook and a phone on port 587: after the first message, the client showsSending rate limit exceeded, try again laterand keeps the message in the outbox.RSPAMD_RL_HOURLYempty,0,-1orabc: no limit applies, and Rspamd starts normally.RATELIMIT_EXCEEDEDsymbol, and appear in the Rspamd UI history.DavidePrincipi commentedon Nov 27, 2026
VERIFIED
Tested Mail
2.0.0-beta.6on a test cluster, following the test cases above. Not tested:451error in the compose window and keeps the draft.Note: during the backup/restore test, the restored instance's Rspamd failed to start because the replaced instance still held its ports, and needed a manual restart. This is not related to the rate limit.