Add custom auth, connection testing, preconfig_only, and security fixes

Major form improvements:
- Custom SMTP/Sieve credentials (separate username/password per protocol)
- Connection testing on save (IMAP, SMTP, Sieve) with localized errors
- preconfig_only mode to restrict domains to preconfigured entries
- Form POST value preservation on save errors (auth selects, passwords)
- Smart host placeholders (SMTP/Sieve default to IMAP host)

Security and bug:
- Fix password re-encryption bug (was comparing raw vs encrypted values)
- Fix XSS: escape label output in special folders form
- Fix parse_url() return value not checked for false
- Fix decrypt() failures not handled (fallback to empty string)
- Sanitize log output (remove raw POST data from log messages)
- Replace weak == comparisons with strict === (PHP and JS)

SQL changes:
- Consolidate 4 migrations (2026021000-03) into single 2026021000
- Remove now unused notify_sound_url column
- Add smtp_username, smtp_password, sieve_username, sieve_password columns
This commit is contained in:
Laurent Dinclaux
2026-02-10 20:48:49 +11:00
parent 3a8202bd7a
commit fd9836c7ae
25 changed files with 1042 additions and 209 deletions

View File

@@ -37,6 +37,10 @@ CREATE TABLE IF NOT EXISTS `ident_switch`
smallint
NOT NULL
DEFAULT 1,
`smtp_username`
varchar(64),
`smtp_password`
varchar(255),
`sieve_host`
varchar(64),
`sieve_port`
@@ -46,6 +50,10 @@ CREATE TABLE IF NOT EXISTS `ident_switch`
smallint
NOT NULL
DEFAULT 1,
`sieve_username`
varchar(64),
`sieve_password`
varchar(255),
`notify_check`
smallint
NOT NULL
@@ -59,9 +67,6 @@ CREATE TABLE IF NOT EXISTS `ident_switch`
`notify_desktop`
smallint
DEFAULT NULL,
`notify_sound_url`
varchar(255)
DEFAULT NULL,
`drafts_mbox`
varchar(64),
`sent_mbox`

View File

@@ -1,5 +1,76 @@
-- Upgrade from v4.x to v5.x
-- Increase password column for encrypted values
ALTER TABLE `ident_switch`
MODIFY `password` varchar(255);
-- Add unique constraint on identity ID
ALTER TABLE `ident_switch`
ADD UNIQUE (`iid`);
-- Add Sieve support
ALTER TABLE `ident_switch`
ADD `sieve_host` varchar(64) AFTER `smtp_auth`;
ALTER TABLE `ident_switch`
ADD `sieve_port`
int
CHECK(`sieve_port` > 0 AND `sieve_port` <= 65535)
AFTER `sieve_host`;
ALTER TABLE `ident_switch`
ADD `sieve_auth`
smallint
NOT NULL
DEFAULT 1
AFTER `sieve_port`;
-- Add custom SMTP/Sieve credentials
ALTER TABLE `ident_switch`
ADD `smtp_username`
varchar(64)
DEFAULT NULL
AFTER `smtp_auth`;
ALTER TABLE `ident_switch`
ADD `smtp_password`
varchar(255)
DEFAULT NULL
AFTER `smtp_username`;
ALTER TABLE `ident_switch`
ADD `sieve_username`
varchar(64)
DEFAULT NULL
AFTER `sieve_auth`;
ALTER TABLE `ident_switch`
ADD `sieve_password`
varchar(255)
DEFAULT NULL
AFTER `sieve_username`;
-- Add notification settings
ALTER TABLE `ident_switch`
ADD `notify_check`
smallint
NOT NULL
DEFAULT 1
AFTER `sieve_password`;
ALTER TABLE `ident_switch`
ADD `notify_basic`
smallint
DEFAULT NULL
AFTER `notify_check`;
ALTER TABLE `ident_switch`
ADD `notify_sound`
smallint
DEFAULT NULL
AFTER `notify_basic`;
ALTER TABLE `ident_switch`
ADD `notify_desktop`
smallint
DEFAULT NULL
AFTER `notify_sound`;

View File

@@ -1,15 +0,0 @@
ALTER TABLE `ident_switch`
ADD `sieve_host` varchar(64) AFTER `smtp_auth`;
ALTER TABLE `ident_switch`
ADD `sieve_port`
int
CHECK(`sieve_port` > 0 AND `sieve_port` <= 65535)
AFTER `sieve_host`;
ALTER TABLE `ident_switch`
ADD `sieve_auth`
smallint
NOT NULL
DEFAULT 1
AFTER `sieve_port`;

View File

@@ -1,30 +0,0 @@
ALTER TABLE `ident_switch`
ADD `notify_check`
smallint
NOT NULL
DEFAULT 1
AFTER `sieve_auth`;
ALTER TABLE `ident_switch`
ADD `notify_basic`
smallint
DEFAULT NULL
AFTER `notify_check`;
ALTER TABLE `ident_switch`
ADD `notify_sound`
smallint
DEFAULT NULL
AFTER `notify_basic`;
ALTER TABLE `ident_switch`
ADD `notify_desktop`
smallint
DEFAULT NULL
AFTER `notify_sound`;
ALTER TABLE `ident_switch`
ADD `notify_sound_url`
varchar(255)
DEFAULT NULL
AFTER `notify_desktop`;

View File

@@ -38,6 +38,10 @@ CREATE TABLE ident_switch
smallint
NOT NULL
DEFAULT(1),
smtp_username
varchar(64),
smtp_password
varchar(255),
sieve_host
varchar(64),
sieve_port
@@ -47,6 +51,10 @@ CREATE TABLE ident_switch
smallint
NOT NULL
DEFAULT(1),
sieve_username
varchar(64),
sieve_password
varchar(255),
notify_check
smallint
NOT NULL
@@ -60,9 +68,6 @@ CREATE TABLE ident_switch
notify_desktop
smallint
DEFAULT NULL,
notify_sound_url
varchar(255)
DEFAULT NULL,
drafts_mbox
varchar(64),
sent_mbox

View File

@@ -1,4 +1,53 @@
-- Upgrade from v4.x to v5.x
-- Increase password column for encrypted values
ALTER TABLE ident_switch
ALTER COLUMN password TYPE varchar(255);
-- Add unique constraint on identity ID
ALTER TABLE ident_switch
ADD CONSTRAINT ident_switch_iid_unique UNIQUE (iid);
CREATE INDEX IF NOT EXISTS IX_ident_switch_iid ON ident_switch(iid);
-- Add Sieve support
ALTER TABLE ident_switch
ADD sieve_host varchar(64);
ALTER TABLE ident_switch
ADD sieve_port
integer
CHECK(sieve_port > 0 AND sieve_port <= 65535);
ALTER TABLE ident_switch
ADD sieve_auth
smallint
NOT NULL
DEFAULT(1);
-- Add custom SMTP/Sieve credentials
ALTER TABLE ident_switch ADD COLUMN smtp_username varchar(64) DEFAULT NULL;
ALTER TABLE ident_switch ADD COLUMN smtp_password varchar(255) DEFAULT NULL;
ALTER TABLE ident_switch ADD COLUMN sieve_username varchar(64) DEFAULT NULL;
ALTER TABLE ident_switch ADD COLUMN sieve_password varchar(255) DEFAULT NULL;
-- Add notification settings
ALTER TABLE ident_switch
ADD notify_check
smallint
NOT NULL
DEFAULT 1;
ALTER TABLE ident_switch
ADD notify_basic
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_sound
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_desktop
smallint
DEFAULT NULL;

View File

@@ -1,13 +0,0 @@
ALTER TABLE ident_switch
ADD sieve_host varchar(64);
ALTER TABLE ident_switch
ADD sieve_port
integer
CHECK(sieve_port > 0 AND sieve_port <= 65535);
ALTER TABLE ident_switch
ADD sieve_auth
smallint
NOT NULL
DEFAULT(1);

View File

@@ -1,25 +0,0 @@
ALTER TABLE ident_switch
ADD notify_check
smallint
NOT NULL
DEFAULT 1;
ALTER TABLE ident_switch
ADD notify_basic
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_sound
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_desktop
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_sound_url
varchar(255)
DEFAULT NULL;

View File

@@ -38,6 +38,10 @@ CREATE TABLE ident_switch
smallint
NOT NULL
DEFAULT 1,
smtp_username
varchar(64),
smtp_password
varchar(255),
sieve_host
varchar(64),
sieve_port
@@ -47,6 +51,10 @@ CREATE TABLE ident_switch
smallint
NOT NULL
DEFAULT 1,
sieve_username
varchar(64),
sieve_password
varchar(255),
notify_check
smallint
NOT NULL
@@ -60,9 +68,6 @@ CREATE TABLE ident_switch
notify_desktop
smallint
DEFAULT NULL,
notify_sound_url
varchar(255)
DEFAULT NULL,
drafts_mbox
varchar(64),
sent_mbox

View File

@@ -1,3 +1,5 @@
-- Upgrade from v4.x to v5.x
-- SQLite: recreate table with all new columns
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
@@ -43,6 +45,36 @@ CREATE TABLE ident_switch
smallint
NOT NULL
DEFAULT 1,
smtp_username
varchar(64),
smtp_password
varchar(255),
sieve_host
varchar(64),
sieve_port
integer
CHECK(sieve_port > 0 AND sieve_port <= 65535),
sieve_auth
smallint
NOT NULL
DEFAULT 1,
sieve_username
varchar(64),
sieve_password
varchar(255),
notify_check
smallint
NOT NULL
DEFAULT 1,
notify_basic
smallint
DEFAULT NULL,
notify_sound
smallint
DEFAULT NULL,
notify_desktop
smallint
DEFAULT NULL,
drafts_mbox
varchar(64),
sent_mbox

View File

@@ -1,13 +0,0 @@
ALTER TABLE ident_switch
ADD sieve_host varchar(64);
ALTER TABLE ident_switch
ADD sieve_port
integer
CHECK(sieve_port > 0 AND sieve_port <= 65535);
ALTER TABLE ident_switch
ADD sieve_auth
smallint
NOT NULL
DEFAULT 1;

View File

@@ -1,25 +0,0 @@
ALTER TABLE ident_switch
ADD notify_check
smallint
NOT NULL
DEFAULT 1;
ALTER TABLE ident_switch
ADD notify_basic
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_sound
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_desktop
smallint
DEFAULT NULL;
ALTER TABLE ident_switch
ADD notify_sound_url
varchar(255)
DEFAULT NULL;