OtterMind/Chat2DB · error · IllegalArgumentException
Invalid MySQL definer: {value}
Error message
Invalid MySQL definer: {value} What it means
Thrown by MysqlSqlGuards.requireDefiner when a DEFINER clause value does not match 'user@host' where each part is either a bare [A-Za-z0-9_$]+ token or a single/backtick-quoted string, and the host part may include .%:$-. The DEFINER is interpolated raw into CREATE statements, so malformed values are rejected to prevent injection and SQL errors. Null is also rejected.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java:91
throw new IllegalArgumentException("Invalid MySQL hex digits: " + value);
}
return value;
}
/**
* True only when the value is a well-formed 0x... hex literal. Values that merely
* start with 0x but contain non-hex characters must not pass through into SQL raw.
*/
public static boolean isHexLiteral(String value) {
return value != null && HEX_LITERAL_PATTERN.matcher(value).matches();
}
/**
* Validate a DEFINER value (user@host, parts optionally single-quoted or backtick-quoted).
*/
public static String requireDefiner(String value) {
if (value == null || !DEFINER_PATTERN.matcher(value).matches()) {
throw new IllegalArgumentException("Invalid MySQL definer: " + value);
}
return value;
}
/**
* Validate a fallback column type expression while preserving common custom type names,
* optional numeric precision/scale and keyword modifiers.
*/
public static String requireColumnType(String value) {
String trimmed = StringUtils.trimToEmpty(value);
if (!COLUMN_TYPE_PATTERN.matcher(trimmed).matches()) {
throw new IllegalArgumentException("Invalid MySQL column type: " + value);
}
return trimmed;
}
/**
* Validate an index sort direction: only ASC/DESC are legal, returned in canonical uppercase.View on GitHub (pinned to 5ee1e990e7)
Solutions
- Ensure the definer is 'user@host' with both parts present and non-empty.
- Trim surrounding whitespace and stray quotes before validation.
- Quote (single or backtick) any user/host part containing special characters.
- If the intent is the definer of the invoking user, omit the DEFINER clause entirely rather than passing a placeholder.
Example fix
// before
String definer = request.getDefiner();
MysqlSqlGuards.requireDefiner(definer);
// after
String definer = StringUtils.trimToNull(request.getDefiner());
if (definer == null || !definer.matches("^([A-Za-z0-9_$]+|'(?:''|[^'\\\\])+'|`(?:``|[^`\\\\])+`)@([A-Za-z0-9_.%:$-]+|'(?:''|[^'\\\\])+'|`(?:``|[^`\\\\])+`)$")) {
throw new IllegalArgumentException("Invalid MySQL definer: " + definer);
}
MysqlSqlGuards.requireDefiner(definer); Defensive patterns
Strategy: validation
Validate before calling
String d = StringUtils.trimToNull(definer);
if (d == null || !d.matches("^([A-Za-z0-9_$]+|'(?:''|[^'\\\\])+'|`(?:``|[^`\\\\])+`)@([A-Za-z0-9_.%:$-]+|'(?:''|[^'\\\\])+'|`(?:``|[^`\\\\])+`)$")) {
throw new IllegalArgumentException("Invalid MySQL definer: " + definer);
}
MysqlSqlGuards.requireDefiner(d); Type guard
static boolean isValidDefiner(String value) {
return value != null && value.matches("^([A-Za-z0-9_$]+|'(?:''|[^'\\\\])+'|`(?:``|[^`\\\\])+`)@([A-Za-z0-9_.%:$-]+|'(?:''|[^'\\\\])+'|`(?:``|[^`\\\\])+`)$");
} Prevention
- Require 'user@host' with both parts present.
- Quote any part containing special characters.
- Trim whitespace and stray quotes before validation.
- Omit the DEFINER clause entirely when the invoking user is intended.
When it happens
Trigger: Calling requireDefiner(value) with a string missing the '@' separator, containing illegal characters in an unquoted part, having an empty user or host side, or being null.
Common situations: A frontend definer field left as a bare username without '@host'; an untrusted or copy-pasted value with trailing whitespace or quotes; a host with characters outside the allowed set that were not quoted; passing CURRENT_USER (a keyword) where a literal definer is expected.
Related errors
- Invalid MySQL {what}: {value}
- Invalid MongoDB database name: {name}
- Invalid MySQL default value: {value}
- Invalid MySQL bit literal: {value}
- Invalid MySQL hex digits: {value}
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/f900caf971765807.
Report an issue: GitHub.