{"record":{"id":"f900caf971765807","repo":"OtterMind/Chat2DB","slug":"invalid-mysql-definer-value","errorCode":null,"errorMessage":"Invalid MySQL definer: {value}","messagePattern":"Invalid MySQL definer: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java","lineNumber":91,"sourceCode":"            throw new IllegalArgumentException(\"Invalid MySQL hex digits: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * True only when the value is a well-formed 0x... hex literal. Values that merely\n     * start with 0x but contain non-hex characters must not pass through into SQL raw.\n     */\n    public static boolean isHexLiteral(String value) {\n        return value != null && HEX_LITERAL_PATTERN.matcher(value).matches();\n    }\n\n    /**\n     * Validate a DEFINER value (user@host, parts optionally single-quoted or backtick-quoted).\n     */\n    public static String requireDefiner(String value) {\n        if (value == null || !DEFINER_PATTERN.matcher(value).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL definer: \" + value);\n        }\n        return value;\n    }\n\n    /**\n     * Validate a fallback column type expression while preserving common custom type names,\n     * optional numeric precision/scale and keyword modifiers.\n     */\n    public static String requireColumnType(String value) {\n        String trimmed = StringUtils.trimToEmpty(value);\n        if (!COLUMN_TYPE_PATTERN.matcher(trimmed).matches()) {\n            throw new IllegalArgumentException(\"Invalid MySQL column type: \" + value);\n        }\n        return trimmed;\n    }\n\n    /**\n     * Validate an index sort direction: only ASC/DESC are legal, returned in canonical uppercase.","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nString definer = request.getDefiner();\nMysqlSqlGuards.requireDefiner(definer);\n\n// after\nString definer = StringUtils.trimToNull(request.getDefiner());\nif (definer == null || !definer.matches(\"^([A-Za-z0-9_$]+|'(?:''|[^'\\\\\\\\])+'|`(?:``|[^`\\\\\\\\])+`)@([A-Za-z0-9_.%:$-]+|'(?:''|[^'\\\\\\\\])+'|`(?:``|[^`\\\\\\\\])+`)$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL definer: \" + definer);\n}\nMysqlSqlGuards.requireDefiner(definer);","handlingStrategy":"validation","validationCode":"String d = StringUtils.trimToNull(definer);\nif (d == null || !d.matches(\"^([A-Za-z0-9_$]+|'(?:''|[^'\\\\\\\\])+'|`(?:``|[^`\\\\\\\\])+`)@([A-Za-z0-9_.%:$-]+|'(?:''|[^'\\\\\\\\])+'|`(?:``|[^`\\\\\\\\])+`)$\")) {\n    throw new IllegalArgumentException(\"Invalid MySQL definer: \" + definer);\n}\nMysqlSqlGuards.requireDefiner(d);","typeGuard":"static boolean isValidDefiner(String value) {\n    return value != null && value.matches(\"^([A-Za-z0-9_$]+|'(?:''|[^'\\\\\\\\])+'|`(?:``|[^`\\\\\\\\])+`)@([A-Za-z0-9_.%:$-]+|'(?:''|[^'\\\\\\\\])+'|`(?:``|[^`\\\\\\\\])+`)$\");\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["mysql","validation","injection-guard","ddl","definer"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}