Skip to content

Conversation

@ramnes
Copy link
Contributor

@ramnes ramnes commented Dec 19, 2025

Some MySQL clients (e.g. libmysql) send a single null byte to indicate an empty password, while others (e.g. mariadb) send an empty packet. This matches MySQL server's own handling:

if (!pkt_len || (pkt_len == 1 && *pkt == 0))

(Source: https://github.com/mysql/mysql-server/blob/8.0/sql/auth/sha2_password.cc)

@ramnes ramnes force-pushed the ramnes/0x00 branch 4 times, most recently from 617c990 to d089c65 Compare December 19, 2025 22:41

func (c *Conn) compareNativePasswordAuthData(clientAuthData []byte, credential Credential) error {
if len(clientAuthData) == 0 {
if isEmptyPassword(clientAuthData) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your MySQL reference is only for caching_sha2_password_authenticate. Will it also apply for compareNativePasswordAuthData and compareSha256PasswordAuthData?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHA256 authentication does have the exact same check here: https://github.com/mysql/mysql-server/blob/056a391cdc1af9b17b5415aee243483d1bac532d/sql/auth/sql_authentication.cc#L4763

For mysql_native_password, I'm less sure but my understanding is that both cases were supported as well by setting a default \0, and then trimming with get_length_encoded_string: https://github.com/mysql/mysql-server/blob/8.0/sql/auth/sql_authentication.cc#L3003-L3012

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add the second link to function comment of isEmptyPassword. Rest lgtm

Some MySQL clients (e.g. libmysql) send a single null byte to indicate an empty password, while others (e.g. mariadb) send an empty packet. This matches MySQL server's own handling:

```c
if (!pkt_len || (pkt_len == 1 && *pkt == 0))
```

(Source: https://github.com/mysql/mysql-server/blob/8.0/sql/auth/sha2_password.cc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants