feat: admin-controlled policy for self-hosted mail server connections#144
Open
saiththerobo wants to merge 3 commits into
Open
feat: admin-controlled policy for self-hosted mail server connections#144saiththerobo wants to merge 3 commits into
saiththerobo wants to merge 3 commits into
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
Owner
|
Hey @saiththerobo — two things to fix before merging:
Also consider caching |
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
Closes #126. Also addresses the use case raised in discussion #116.
Adds three admin-only toggles under Settings → Security → Mail Server Connection Policy, allowing self-hosted deployments (protonmail-bridge, Dovecot on localhost, etc.) to connect to local IMAP/SMTP servers while keeping the existing SSRF protection intact for internet-facing instances.
All three flags default to off, so existing deployments are unaffected.
Changes
backend/migrations/0013_account_allow_private_host.sql— addsallow_private_hosts,allow_insecure_tls,allow_nonstandard_portstosystem_settingsbackend/src/services/connectionPolicy.js— new module that reads the three flags from the DBbackend/src/services/hostValidation.js— all exports accept{ allowPrivate }option; DNS rebinding protection is preservedbackend/src/services/imapManager.js— reads policy on every connection; enforces TLS requirement; policy errors surface to the UI viasync_errorand WebSocket broadcastbackend/src/routes/accounts.js— validates host and port against policy on account create/updatebackend/src/routes/admin.js— PATCH/settingspersists the three flagsbackend/src/routes/send.js— enforces policy for outgoing SMTPfrontend/src/components/AdminPanel.jsx— policy toggles in Security tab (auto-save on click); account form shows skip-TLS toggle only whenallowInsecureTlsis enabledTesting
makeClientCfgTLS enforcement andrejectUnauthorizedunder all policy/account combinationsallowPrivatetests for all threehostValidationexportsContributor License Agreement
By submitting this pull request I confirm that: