CVE-2026-24031 Analysis — Dovecot SQL-Based Authentication Bypass (an auth_username_chars Regression)
A regression in Dovecot's settings system caused the SQL escape function requested by the SQL passdb to be silently ignored, so usernames substituted into SQL queries were not escaped. When an administrator had cleared auth_username_chars, an attacker could bypass authentication for any user and enumerate users.
Published on medium.com
Database
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Dovecot is a mail server whose authentication layer can look users up in SQL databases. A passdb SQL configuration builds a query from a template such as SELECT username, password FROM users WHERE username = '%u', where %u is replaced with the username the client supplied at login. Because that value is attacker-controlled, the substitution has to be escaped by the database driver before the query is sent.
The advisory quoted in the write-up, OXDC-2026-0001, describes the issue in one line:
Dovecot SQL based authentication can be bypassed when
auth_username_charsis cleared by admin. This vulnerability allows bypassing authentication for any user and user enumeration.
Read at face value that sounds like a pure configuration mistake. The analysis argues the root cause is a regression from the 2.4 settings-system refactor, in which an explicitly requested SQL escape function is silently discarded. Clearing auth_username_chars is only the precondition that lets the bug be triggered in practice.
The write-up is based on a direct clone of the dovecot/core repository, comparing the vulnerable 2.4.2 source with the patched 2.4.3 source.

Setup
No live target, accounts or roles are described. The work is source comparison: a clone of dovecot/core, the vulnerable tree at 2.4.2 and the patched tree at 2.4.3, plus the patch commits. The affected versions named in the report are 2.4.0 to 2.4.2 and 3.1.0 to 3.1.3. The fixes are CE core 2.4.3 or later and Pro core 3.1.4 or later.
The configuration precondition is an admin who has set auth_username_chars to an empty string. The report notes this is sometimes done in practice to support wide or unicode usernames.
Finding it
Dovecot reuses the username a client supplies at login in several places: SQL and LDAP queries, and file paths through %u, %n and %d variable substitution. auth_username_chars is the first line of defence against dangerous characters reaching those places.
The default in src/auth/auth-settings.c is:
.username_chars = "[redacted].-_@",
Only letters, digits and . - _ @ are allowed, so SQL metacharacters such as a single quote or a semicolon are not on the whitelist at all.
The string is converted into a 256-byte bitmap, username_chars_map, with a special case in src/auth/auth-settings.c around lines 623 to 630:
if (*set->username_chars == '\0') { memset(set->username_chars_map, 1, sizeof(set->username_chars_map));} else { for (p = set->username_chars; *p != '\0'; p++) set->username_chars_map[(int)(uint8_t)*p] = 1;}
An empty auth_username_chars therefore does not mean "no characters allowed". It means the opposite: every byte from 0x00 to 0xFF is allowed. The moment an admin clears the setting, the first-line filter against SQL metacharacters disappears completely.
The filtering itself happens in auth_request_fix_username() in src/auth/auth-request-fields.c, which checks that map:
for (p = (unsigned char *)user; *p != '\0'; p++) { if (set->username_translation_map[*p & 0xff] != 0) *p = set->username_translation_map[*p & 0xff]; if (set->username_chars_map[*p & 0xff] == 0) { *error_r = t_strdup_printf( "Username character disallowed by auth_username_chars: " "0x%02x (username: %s)", *p, str_sanitize(*username, 128)); return -1; }}
When username_chars_map is filled with 1s across the board, this check rejects nothing. Up to that point the situation is still an admin misconfiguration. The interesting part is what happens next.
Exploitation
Step 1: confirm the query template and the escaping intent
An SQL passdb expands variables such as %u inside the configured passdb_sql_query template. To prevent SQL injection, the substituted value must always go through SQL escaping. In src/auth/passdb-sql.c the escape function is defined as:
static int passdb_sql_escape(const char *str, const char **output_r, void *context, const char **error_r){ struct sql_db *db = context; return sql_escape_string(db, str, output_r, error_r);}
and the lookup path passes it explicitly:
static void sql_lookup_pass(struct passdb_sql_request *sql_request){ ... const struct settings_get_params params = { .escape_func = passdb_sql_escape, .escape_context = module->db, }; if (settings_get_params(authdb_event(sql_request->auth_request), &passdb_sql_setting_parser_info, ¶ms, &set, &error) < 0) { ... } e_debug(authdb_event(sql_request->auth_request), "query: %s", set->query); auth_request_ref(sql_request->auth_request); sql_query(module->db, set->query, sql_query_callback, sql_request); ...}
settings_get_params() is called with escape_func = passdb_sql_escape, and that function calls the underlying driver's sql_escape_string() (MySQL, PostgreSQL or SQLite) to escape quotes and similar characters. The contract in settings.h documents the intent:
struct settings_get_params { var_expand_escape_func_t *escape_func; ...};
"If non-NULL, it is guaranteed to be used for escaping." The analysis found that this contract was not honoured.
Step 2: locate the override in the settings layer
The bug is not in passdb-sql.c but one layer down, in settings_var_expand_init() inside src/lib-settings/settings.c. The settings system can receive a var-expand escape function from two places:
- The explicit
escape_funca caller passes intosettings_get_params(), for examplepassdb_sql_escape. - A default escape callback registered somewhere up the event hierarchy,
init_ctx.escape_func.
The vulnerable 2.4.0 to 2.4.2 code unconditionally used option 2, whatever the caller passed. The patch commit 34fbd3956d changes src/lib-settings/settings.c as follows:
ctx->var_params.tables_arr = array_front(&init_ctx.tables); ctx->var_params.providers_arr = array_front(&init_ctx.providers); ctx->var_params.contexts = array_front(&init_ctx.contexts);- ctx->var_params.escape_func = init_ctx.escape_func;- ctx->var_params.escape_context = init_ctx.escape_context;+ if (ctx->escape_func != NULL) {+ + ctx->var_params.escape_func = ctx->escape_func;+ ctx->var_params.escape_context = ctx->escape_context;+ } else {+ ctx->var_params.escape_func = init_ctx.escape_func;+ ctx->var_params.escape_context = init_ctx.escape_context;+ } ctx->var_params.event = ctx->event;
Even though passdb-sql.c explicitly requests escape_func = passdb_sql_escape, the variable-substitution step silently discarded it and used whatever escape function the event chain happened to expose, which could be unrelated or absent. The username substituted for %u could therefore end up not escaped at all, or escaped incorrectly, for SQL.
Step 3: combine the two conditions
Two conditions have to line up for real exploitation:
- Precondition A: an admin has set
auth_username_charsto an empty string, disabling the character whitelist. - Root cause B: the
settings_var_expand_init()bug that ignorespassdb_sql_escape, present in every 2.4.0 to 2.4.2 and 3.1.0 to 3.1.3 install regardless of configuration.
The CVSS vector's AC:H (high attack complexity) reflects the fact that condition A has to be true.

With A in place, the username reaches the query template without the character filter, and with B in place the value may not be escaped, or escaped incorrectly, by the SQL driver. The report does not include a concrete request or a captured response; the chain is established from the source comparison.
Root cause
The defect is a regression introduced by the 2024 commit ef0c63b6 ("auth: passdb/userdb sql - Convert to new settings"), a large refactor that moved SQL passdb and userdb onto the new settings framework. The Dovecot developers flag it in the commit log as a "v2.4 regression".
In settings_var_expand_init(), the caller-supplied escape_func was overwritten by the event-chain default instead of taking priority. The documented guarantee in settings.h was therefore not enforced by the implementation, and the escaping that passdb-sql.c believed it had requested never ran. The character whitelist in auth_username_chars was the only remaining barrier, and clearing it removes that barrier entirely because an empty value maps to "allow every byte".
The same class of bug produced a sibling CVE in the LDAP passdb, CVE-2026-27860 (LDAP filter injection). Both trace back to the same settings_var_expand_init() defect.
Impact
According to the advisory, the vulnerability allows bypassing authentication for any user and user enumeration. The bypass requires the admin to have cleared auth_username_chars; the escaping defect itself is present on every affected install regardless of configuration. The report quotes no CVSS score, only the observation that the vector carries AC:H because of the configuration precondition.
Fix
The core patch is the priority reordering inside settings_var_expand_init() shown above. In full, as given in the report:
@@ -1673,8 +1673,14 @@ settings_var_expand_init(struct settings_apply_ctx *ctx) ctx->var_params.tables_arr = array_front(&init_ctx.tables); ctx->var_params.providers_arr = array_front(&init_ctx.providers); ctx->var_params.contexts = array_front(&init_ctx.contexts);- ctx->var_params.escape_func = init_ctx.escape_func;- ctx->var_params.escape_context = init_ctx.escape_context;+ if (ctx->escape_func != NULL) {+ /* settings_get_params()'s escape_func overrides all others */+ ctx->var_params.escape_func = ctx->escape_func;+ ctx->var_params.escape_context = ctx->escape_context;+ } else {+ ctx->var_params.escape_func = init_ctx.escape_func;+ ctx->var_params.escape_context = init_ctx.escape_context;+ } ctx->var_params.event = ctx->event; }
When a caller of settings_get_params() explicitly supplies an escape_func such as passdb_sql_escape, that value now takes priority; the event-chain default is only a fallback. This makes the escape functions passed by passdb-sql.c, userdb-sql.c and db-ldap.c actually take effect.
Related commits shipped alongside it:
25c34e5084:passdb sql - Fix escaping for set_credentials()(a missing-escape path in the OTP credential-update flow; not a separate CVE, but the same pattern).6a8f2daf15:passdb/userdb ldap - Fix escaping ldap filter, base and bind_userdn(CVE-2026-27860, the LDAP counterpart).74a6f1612e:Rewrite ldap_escape() with a unit test(regression-prevention hardening).
Upgrade targets: CE core to 2.4.3 or later, Pro core to 3.1.4 or later.
Detection and mitigation
Check the configuration:
doveconf -n | grep auth_username_chars
An empty value (auth_username_chars =) is an immediate red flag. At minimum, restore it to something at or above the default whitelist ([redacted].-_@). If unicode usernames are genuinely required, do not remove the restriction entirely; build an explicit whitelist that still excludes characters used in SQL injection (', ", ;, \, whitespace and so on).
For log-based detection, with auth_debug = yes enabled, check the query: ... debug line emitted by passdb-sql.c for usernames containing abnormal quote or comment patterns (--, #, /*). The line comes from:
e_debug(authdb_event(sql_request->auth_request), "query: %s", set->query);
Operational and network controls:
- Apply rate limiting on authentication endpoints, since response-time or error-message differences could be leveraged for user enumeration.
- On the database side, if SQL query logging is enabled, add detection rules for abnormal WHERE-clause patterns in
password_queryanduser_query.
Variants to test
- Other passdb/userdb backends that pass an explicit escape function. Look for callers of
settings_get_params()that setescape_funcand check whether the substituted value is escaped in the final query. A positive result is a value containing a quote or comment sequence reaching the backend unescaped while the caller clearly requested escaping. - LDAP passdb. The same defect produced CVE-2026-27860. Try a username containing LDAP filter metacharacters against an LDAP passdb and watch for filter injection in the resulting search. A positive result is a filter that changes shape based on the supplied username.
- The OTP credential-update path. Commit
25c34e5084fixed a missing escape inset_credentials(). Exercise the OTP credential-update flow with a username containing SQL metacharacters and check whether the update query is escaped. A positive result is an unescaped value in the credential update. - Empty character whitelists in other products. Any setting that maps an empty value to "allow everything" is worth testing. Set the equivalent of
auth_username_charsto empty and send a username with a single quote, a semicolon or a comment sequence. A positive result is the character reaching the query template unchanged. - Log-based detection coverage. Enable debug logging and send usernames containing
--,#or/*. A positive result is aquery:line showing those patterns in the expanded query, which confirms the detection rule fires.
What happened, in plain words
Dovecot is a mail server: the software that receives, stores and hands out email for a domain. Before it lets anyone read their mail, it has to check who they are. That check is called authentication, and Dovecot can be told to look the answer up in a database instead of in a local file. The database it asks is usually a SQL database, the kind of system that stores rows in tables and answers questions written in a small language called SQL.
When someone logs in, Dovecot takes the username they typed and drops it into a prepared question for the database, for example "find the row whose username is this". The prepared question is called a query, and the placeholder where the username goes is %u. Because the username comes from whoever is connecting, it cannot be trusted: a person with bad intentions can type characters that change the meaning of the query. The standard defence is escaping, which means marking those dangerous characters so the database treats them as plain text rather than as instructions.
This report is about a bug where Dovecot asked for that escaping, and the request was quietly thrown away. The result: on certain configurations, a crafted username could slip into the query unescaped, and the advisory says authentication could be bypassed for any user, and usernames could be enumerated (that is, an attacker could find out which accounts exist).
The official advisory, OXDC-2026-0001, puts it in one line:
Dovecot SQL based authentication can be bypassed when
auth_username_charsis cleared by admin. This vulnerability allows bypassing authentication for any user and user enumeration.
Read on its own, that sounds like an administrator simply misconfigured something. The analysis argues the real cause is a regression: a change made during a big rewrite of Dovecot's settings system in version 2.4 that broke behaviour which used to work. Clearing auth_username_chars is only the condition that lets the bug be triggered in practice.
The analysis is based on a direct clone of the dovecot/core repository, comparing the vulnerable 2.4.2 source with the patched 2.4.3 source.

1. Overview

A few words first, because they come up constantly.
- Source code is the human-readable text a program is written in. A repository is a project folder kept under version control, so every change is recorded and old versions can be compared with new ones. Cloning a repository means downloading a full copy of it.
- A commit is one saved change to that folder, with a short identifier (a hash such as
34fbd3956d) and a message describing it. - A regression is a bug introduced by a change that was meant to improve something. The feature worked, someone rewrote part of it, and it stopped working.
- A CVE is a public catalogue number for a known security flaw, so that people across the world can refer to the same issue unambiguously.
The report's argument in one sentence: the escaping was requested correctly by the database login code, but a lower layer of the settings system ignored the request, and the only thing still standing between an attacker and the query was a character whitelist that some administrators switch off.
2. Background: what auth_username_chars actually does
Dovecot reuses the username a client supplies at login in several places: SQL and LDAP queries, and file paths through %u, %n and %d variable substitution. LDAP is another kind of directory database, often used for accounts. Variable substitution means replacing a short marker such as %u with the actual username before the text is used.
auth_username_chars is the first line of defence against dangerous characters reaching those places. Think of it as the guest list at a door: if your name contains a character that is not on the list, you do not get in.
The default value in src/auth/auth-settings.c is:
.username_chars = "[redacted].-_@",
Line by line: this is one setting assignment. The name on the left, username_chars, is the setting. The text in quotes on the right is the list of characters that are allowed in a username: the lower-case alphabet, the upper-case alphabet, the digits, then a dot, a hyphen, an underscore and an at sign. Nothing else is permitted. In particular, SQL metacharacters, the characters that have special meaning inside a SQL query, such as a single quote (') or a semicolon, are not on the list at all. A single quote is how SQL marks the beginning and end of a piece of text, so it is exactly the character an attacker uses to break out of a value and start writing instructions.
That string is then converted into a 256-byte bitmap called username_chars_map. A bitmap here is simply a table of 256 yes/no slots, one for each possible byte value from 0 to 255, where a slot is marked if that character is allowed. Checking a character becomes a single lookup instead of a scan through a list. The conversion has a special case, in src/auth/auth-settings.c around lines 623 to 630:
if (*set->username_chars == '\0') { memset(set->username_chars_map, 1, sizeof(set->username_chars_map));} else { for (p = set->username_chars; *p != '\0'; p++) set->username_chars_map[(int)(uint8_t)*p] = 1;}
Line by line:
if (*set->username_chars == '\0')asks: is the first character of the setting the end-of-string marker? In other words, is the setting empty?- If it is empty,
memset(set->username_chars_map, 1, sizeof(set->username_chars_map));fills the whole 256-slot table with 1, meaning yes, allowed, for every possible byte. - Otherwise, the
elsebranch walks the configured string one character at a time (for (p = set->username_chars; *p != '\0'; p++)) and marks only those characters as allowed in the table.
So an empty auth_username_chars does not mean "no characters allowed". It means the exact opposite: every byte from 0x00 to 0xFF is allowed. The moment an administrator clears the setting, the first-line filter against SQL metacharacters disappears completely. The report notes administrators sometimes do this in practice to support wide or unicode usernames, that is, names containing letters outside the basic Latin alphabet.
The filtering itself happens in auth_request_fix_username() in src/auth/auth-request-fields.c, which checks that table:
for (p = (unsigned char *)user; *p != '\0'; p++) { if (set->username_translation_map[*p & 0xff] != 0) *p = set->username_translation_map[*p & 0xff]; if (set->username_chars_map[*p & 0xff] == 0) { *error_r = t_strdup_printf( "Username character disallowed by auth_username_chars: " "0x%02x (username: %s)", *p, str_sanitize(*username, 128)); return -1; }}
Line by line:
- The
forloop walks the supplied username one character at a time until the end-of-string marker. - The first
ifapplies an optional translation: if the translation table has an entry for this character, the character is replaced by it. This lets an administrator map, say, one character onto another. - The second
ifis the actual check: if the allowed-characters table has a 0 for this character, the character is not permitted. - When that happens, an error message is built with
t_strdup_printf, naming the offending byte in hexadecimal and including a sanitised copy of the username, and the function returns-1, meaning failure.
When username_chars_map is filled with 1s across the board, this check rejects nothing. Up to that point the situation is still an administrator misconfiguration. The interesting part is what happens next.
3. How the SQL query gets built
An SQL passdb builds its query string, for example SELECT username, password FROM users WHERE username = '%u', by expanding variables such as %u inside the configured passdb_sql_query template. A template is a piece of text with blanks to fill in. To prevent SQL injection, the substituted value must always go through SQL escaping. SQL injection is the class of attack where untrusted input is treated as part of the query's instructions instead of as data.
In src/auth/passdb-sql.c the escape function is defined as:
static int passdb_sql_escape(const char *str, const char **output_r, void *context, const char **error_r){ struct sql_db *db = context; return sql_escape_string(db, str, output_r, error_r);}
Line by line:
static int passdb_sql_escape(...)declares a function that takes the string to escape, a place to put the escaped result, a context pointer and a place to put an error message. It returns an integer status.struct sql_db *db = context;recovers the database connection from the context, so the function knows which database driver it is talking to.return sql_escape_string(db, str, output_r, error_r);hands the work to the driver's own escaping routine and returns its result. The driver is the piece of software that knows the specific rules of MySQL, PostgreSQL or SQLite, each of which escapes slightly differently.
And the lookup path passes it explicitly:
static void sql_lookup_pass(struct passdb_sql_request *sql_request){ ... const struct settings_get_params params = { .escape_func = passdb_sql_escape, .escape_context = module->db, }; if (settings_get_params(authdb_event(sql_request->auth_request), &passdb_sql_setting_parser_info, ¶ms, &set, &error) < 0) { ... } e_debug(authdb_event(sql_request->auth_request), "query: %s", set->query); auth_request_ref(sql_request->auth_request); sql_query(module->db, set->query, sql_query_callback, sql_request); ...}
Line by line:
sql_lookup_passis the function that performs a login lookup against SQL. The...marks code left out of the excerpt.paramsis a small structure of options..escape_func = passdb_sql_escapesays: when you fill in the template, use this function to escape values..escape_context = module->dbgives that function the database connection it needs.settings_get_params(...)asks the settings system to load the configuration for this lookup, passing the options along. If it returns a negative value, something went wrong and the error path is taken.e_debug(...)writes a debug log line containing the final query, but only when debug logging is enabled.sql_query(...)sends the finished query to the database with a callback to handle the answer.
At first glance this looks correct. settings_get_params() is called with escape_func = passdb_sql_escape, and that function calls the underlying driver's sql_escape_string() to escape quotes and similar characters. The contract in settings.h documents the intent:
struct settings_get_params { var_expand_escape_func_t *escape_func; ...};
Line by line: this declares the options structure. Among its fields is escape_func, a pointer to the function to use for escaping. The ... stands for the other fields, left out here. The documentation states: "If non-NULL, it is guaranteed to be used for escaping." In plain words, if the caller supplies an escape function, that function will definitely be the one used. The analysis found that this promise was not kept.
4. The real root cause: an escape_func override bug
The bug is not in passdb-sql.c but one layer down, in settings_var_expand_init() inside src/lib-settings/settings.c. The settings system can receive a var-expand escape function from two places:
- The explicit
escape_funca caller passes intosettings_get_params(), for examplepassdb_sql_escape. - A default escape callback registered somewhere up the event hierarchy,
init_ctx.escape_func. An event hierarchy is a chain of logging and context objects; a callback is a function that gets called later by someone else.
A useful comparison: you ask a colleague to sign a letter with your own pen (option 1), but the office has a rule that all letters are signed with the office stamp (option 2). The vulnerable code always used the office stamp, no matter what you asked for.
The vulnerable 2.4.0 to 2.4.2 code unconditionally used option 2, whatever the caller passed. The patch commit 34fbd3956d changes src/lib-settings/settings.c as follows:
ctx->var_params.tables_arr = array_front(&init_ctx.tables); ctx->var_params.providers_arr = array_front(&init_ctx.providers); ctx->var_params.contexts = array_front(&init_ctx.contexts);- ctx->var_params.escape_func = init_ctx.escape_func;- ctx->var_params.escape_context = init_ctx.escape_context;+ if (ctx->escape_func != NULL) {+ + ctx->var_params.escape_func = ctx->escape_func;+ ctx->var_params.escape_context = ctx->escape_context;+ } else {+ ctx->var_params.escape_func = init_ctx.escape_func;+ ctx->var_params.escape_context = init_ctx.escape_context;+ } ctx->var_params.event = ctx->event;
Line by line:
- The first three lines copy the tables, providers and contexts from the initial context into the working context. These are the pieces of configuration the settings system will use.
- The two lines starting with
-are the old, vulnerable code: always take the escape function and its context from the event chain, ignoring whatever the caller asked for. - The lines starting with
+are the fix.if (ctx->escape_func != NULL)asks whether the caller supplied an escape function. If yes, use the caller's function and context. If not, fall back to the event-chain default. - The last line attaches the event object, unchanged.
Even though passdb-sql.c explicitly requests escape_func = passdb_sql_escape, the variable-substitution step silently discarded it and used whatever escape function the event chain happened to expose, which could be unrelated or absent. The username substituted for %u could therefore end up not escaped at all, or escaped incorrectly, for SQL.
5. Full attack chain
Two conditions have to line up for real exploitation:
- Precondition A: an administrator has set
auth_username_charsto an empty string, disabling the character whitelist. - Root cause B: the
settings_var_expand_init()bug that ignorespassdb_sql_escape, present in every 2.4.0 to 2.4.2 and 3.1.0 to 3.1.3 install regardless of configuration.
The CVSS vector's AC:H (high attack complexity) reflects the fact that condition A has to be true. CVSS is a standard scoring system for vulnerabilities; its attack complexity field describes how much must go right for an attacker before the flaw can be used. High complexity here reflects the fact that condition A has to be true.

With A in place, the username reaches the query template without the character filter, and with B in place the value may not be escaped, or escaped incorrectly, by the SQL driver. The report does not include a concrete request or a captured response; the chain is established from the source comparison.
6. The actual fix (v2.4.3)
The core patch is the priority reordering inside settings_var_expand_init() shown above. In full, as given in the report:
@@ -1673,8 +1673,14 @@ settings_var_expand_init(struct settings_apply_ctx *ctx) ctx->var_params.tables_arr = array_front(&init_ctx.tables); ctx->var_params.providers_arr = array_front(&init_ctx.providers); ctx->var_params.contexts = array_front(&init_ctx.contexts);- ctx->var_params.escape_func = init_ctx.escape_func;- ctx->var_params.escape_context = init_ctx.escape_context;+ if (ctx->escape_func != NULL) {+ /* settings_get_params()'s escape_func overrides all others */+ ctx->var_params.escape_func = ctx->escape_func;+ ctx->var_params.escape_context = ctx->escape_context;+ } else {+ ctx->var_params.escape_func = init_ctx.escape_func;+ ctx->var_params.escape_context = init_ctx.escape_context;+ } ctx->var_params.event = ctx->event; }
Line by line:
- The
@@line is a diff header: it says which function the change is in and how many lines the old and new versions occupy. A diff is a side-by-side record of what changed. - The unchanged lines copy the tables, providers and contexts as before.
- The
-lines are removed: the unconditional use of the event-chain escape function. - The
+lines are added: if the caller supplied an escape function, use it, with a comment saying thatsettings_get_params()'s escape function overrides all others; otherwise fall back to the event-chain default. - The final line attaches the event object, unchanged.
When a caller of settings_get_params() explicitly supplies an escape_func such as passdb_sql_escape, that value now takes priority; the event-chain default is only a fallback. This makes the escape functions passed by passdb-sql.c, userdb-sql.c and db-ldap.c actually take effect. userdb is the part of Dovecot that looks up user details such as home directory and mail location, and db-ldap.c is the LDAP backend.
Related commits shipped alongside it:
25c34e5084:passdb sql - Fix escaping for set_credentials()(a missing-escape path in the OTP credential-update flow; not a separate CVE, but the same pattern). OTP means one-time password, a second factor used at login.6a8f2daf15:passdb/userdb ldap - Fix escaping ldap filter, base and bind_userdn(CVE-2026-27860, the LDAP counterpart).74a6f1612e:Rewrite ldap_escape() with a unit test(regression-prevention hardening). A unit test is a small automated check that a specific piece of code behaves as expected.
Upgrade targets: CE core to 2.4.3 or later, Pro core to 3.1.4 or later. CE and Pro are the community and commercial editions of Dovecot.
7. Detection and mitigation
Check the configuration
doveconf -n | grep auth_username_chars
Line by line:
doveconf -nis Dovecot's configuration tool; the-noption prints only the settings that differ from the defaults, which keeps the output short.- The vertical bar
|takes that output and feeds it to the next command. grep auth_username_charsprints only the lines containing that setting name.
An empty value (auth_username_chars =) is an immediate red flag. At minimum, restore it to something at or above the default whitelist ([redacted].-_@). If unicode usernames are genuinely required, do not remove the restriction entirely; build an explicit whitelist that still excludes characters used in SQL injection (', ", ;, \, whitespace and so on).
Apply the patch
- CE core to 2.4.3 or later.
- Pro core to 3.1.4 or later.
Log-based detection
With auth_debug = yes enabled, check the query: ... debug line emitted by passdb-sql.c for usernames containing abnormal quote or comment patterns (--, #, /*). In SQL, -- and # start a comment and /* opens a block comment, so an attacker uses them to cut off the rest of a query. The line comes from:
e_debug(authdb_event(sql_request->auth_request), "query: %s", set->query);
Line by line: e_debug writes a debug message. The first argument is the event the message belongs to, so it lands in the right log context. The second is the format string "query: %s", where %s is replaced by the third argument, the finished query text. Reading these lines tells you exactly what was sent to the database.
Operational and network controls
- Apply rate limiting on authentication endpoints, since response-time or error-message differences could be leveraged for user enumeration. Rate limiting means capping how many attempts one source can make in a period.
- On the database side, if SQL query logging is enabled, add detection rules for abnormal WHERE-clause patterns in
password_queryanduser_query. The WHERE clause is the part of a query that states which rows to match.
Variants to test
- Other passdb/userdb backends that pass an explicit escape function. Look for callers of
settings_get_params()that setescape_funcand check whether the substituted value is escaped in the final query. A positive result is a value containing a quote or comment sequence reaching the backend unescaped while the caller clearly requested escaping. - LDAP passdb. The same defect produced CVE-2026-27860. Try a username containing LDAP filter metacharacters against an LDAP passdb and watch for filter injection in the resulting search. A positive result is a filter that changes shape based on the supplied username.
- The OTP credential-update path. Commit
25c34e5084fixed a missing escape inset_credentials(). Exercise the OTP credential-update flow with a username containing SQL metacharacters and check whether the update query is escaped. A positive result is an unescaped value in the credential update. - Empty character whitelists in other products. Any setting that maps an empty value to "allow everything" is worth testing. Set the equivalent of
auth_username_charsto empty and send a username with a single quote, a semicolon or a comment sequence. A positive result is the character reaching the query template unchanged. - Log-based detection coverage. Enable debug logging and send usernames containing
--,#or/*. A positive result is aquery:line showing those patterns in the expanded query, which confirms the detection rule fires.
Glossary
- Authentication: the process of proving who you are before being allowed in, usually with a username and password.
- Dovecot: a mail server program that stores and serves email and checks logins.
- SQL: the language used to ask questions of a relational database, such as "find the row with this username".
- Query: one such question sent to a database.
- Template: text with placeholders that get filled in before use, such as
SELECT ... WHERE username = '%u'. - Variable substitution: replacing a marker such as
%uwith the actual value, here the username. - Escaping: marking characters in a value so the database treats them as plain text rather than as part of the query's instructions.
- SQL injection: an attack where untrusted input is interpreted as part of a query instead of as data.
- Metacharacter: a character with special meaning in a language, such as a single quote or semicolon in SQL.
- Whitelist: a list of things that are allowed; anything not on it is refused.
- Bitmap: a table of yes/no slots, one per possible value, used for fast lookups.
- passdb: the part of Dovecot that verifies a user's password.
- userdb: the part of Dovecot that looks up a user's details, such as where their mail is stored.
- LDAP: a directory database often used to store accounts and their attributes.
- LDAP filter injection: the LDAP equivalent of SQL injection, where input changes the shape of a directory search.
- Source code: the human-readable text a program is written in.
- Repository: a project folder kept under version control so changes can be tracked and compared.
- Commit: one saved change in a repository, identified by a short hash.
- Diff: a record showing which lines were removed and added between two versions.
- Regression: a bug introduced by a change that was meant to improve something.
- CVE: a public catalogue number for a known security vulnerability.
- Advisory: an official notice from a vendor describing a vulnerability and its fix.
- CVSS: a standard scoring system for vulnerabilities, including fields such as attack complexity.
- Attack complexity (AC): a CVSS field describing how much must go right for an attacker;
AC:Hmeans high. - Callback: a function handed to another piece of code to be called later.
- Event hierarchy: a chain of logging and context objects that code can attach messages and settings to.
- Unit test: a small automated check that one piece of code behaves as expected.
- OTP: one-time password, a second factor used at login.
- Rate limiting: capping how many attempts a source can make in a given period.
- User enumeration: finding out which accounts exist on a system, often from differences in responses.
- WHERE clause: the part of a SQL query that states which rows to match.
- CE / Pro: the community and commercial editions of Dovecot.