feat: admin-controlled policy for self-hosted mail server connections - #5
Merged
Conversation
Replaces the per-account allow_private_host toggle with three server-level policy flags set by admins in Settings → Security: - allow_private_hosts: permits IMAP/SMTP on private/local addresses - allow_insecure_tls: exposes per-account TLS verify skip toggle - allow_nonstandard_ports: unlocks free-form port input Migration 0013 seeds the three keys in system_settings (default false) and drops the account-level column added in the earlier draft. A new connectionPolicy service reads the flags for use in validation and connection code. The account form shows TLS and port options only when the admin has enabled them.
- makeClientCfg throws when imap_tls=false and allowInsecureTls policy is off, ensuring plain-text IMAP is rejected when admin requires secure connections - Move makeClientCfg call inside try/catch so policy errors set sync_error and broadcast account_error to the UI instead of being silently swallowed - Block plain-text SMTP when allowInsecureTls is off (STARTTLS and SSL pass) - Replace Save button on mail policy toggles with auto-save on click, matching the existing pattern used by other boolean admin settings - Export makeClientCfg and add tests covering TLS enforcement and rejectUnauthorized behaviour under all policy combinations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
makeClientCfg,send.js)sync_error/account_errorWebSocket broadcastresolveForConnection) is preserved even when private hosts are allowedChanges
backend/migrations/0013_account_allow_private_host.sql— addsallow_private_hosts,allow_insecure_tls,allow_nonstandard_portstosystem_settingsbackend/src/services/connectionPolicy.js— new module; reads all three flags from DBbackend/src/services/hostValidation.js— all three exports accept{ allowPrivate }optionbackend/src/services/imapManager.js— reads policy on every connect; enforces TLS requirement inmakeClientCfgbackend/src/routes/accounts.js— validates host/port against policy on account create/updatebackend/src/routes/admin.js— PATCH/settingspersists the three policy flagsbackend/src/routes/send.js— enforces policy for SMTP connectionsfrontend/src/components/AdminPanel.jsx— Security tab: policy toggles; account form: conditional skip-TLS toggle and port input modefrontend/src/locales/{en,de,es,fr,it,ru,zhCN}.json— i18n keys for new UI stringsTesting
npm test— 165 tests)makeClientCfgTLS enforcement andrejectUnauthorizedunder all policy combinationsallowPrivateoption tests forhostValidationfunctionsCLA