Skip to content
Crypto Disclosed report Intermediate

Unescaped username in SASL DIGEST-MD5 response allows injection

The SASL DIGEST-MD5 response builder inserts the username without escaping quotes or backslashes, unlike the HTTP digest path. An attacker who controls the username could inject extra fields such as a second realm into the authentication response sent to a server.

am-8113 Follow

Originally disclosed on HackerOne

  • Disclosed after 24 hours

Summary:

The username is inserted into the digest-md5 response without escaping the quotes or backslashes. The HTTP digest path on line 863 in lib/vauth/digest.c uses auth_digest_string_quoted() but the SASL does not (line 478).

Commit ac419bf sorted the HTTP in 2013. It looks like the SASL was moved into the same file much later on so was potentially missed. There is a comment that says escape the realm and nonce as necessary but it doesn't mention the user.

Affected version

8.19.1 Tested on my mac but I expect it to work on all platforms.

Steps To Reproduce:

I created a dummy server (using Claude code full disclosure) to demo.

curl -s --max-time 2 --digest --user 'admin:pass' http://127.0.0.1:8888/

Produces: Authorization: Digest username="admin", realm="test", nonce="abc123", uri="/", cnonce="OGE4MDE5ZDQ0NGUyMWQ4NTA3Y2JjNmViMTgzZDc4NWQ=", nc=00000001, qop=auth, response="741d2018ce65199de3d31d86c6b40a0e"

curl -s --max-time 2 --digest --user 'admin"test:pass' http://127.0.0.1:8888/

Produces: Authorization: Digest username="admin"test", realm="test", nonce="abc123", uri="/", cnonce="MmMwNGRmYzdkYjMxNDI0Mjg3NjUwODU3NWRjMTk4ZWU=", nc=00000001, qop=auth, response="cd9a77e93a813147fb6433d6adc94a10"

curl -s --max-time 2 imap://127.0.0.1:1143/ --user "admin"test:pass" --login-options "AUTH=DIGEST-MD5"

Produces: username="admin"test",realm="test",nonce="abc123",cnonce="731e487fc8b26e964f61a99afb4bc6dd",nc="00000001",digest-uri="imap/127.0.0.1",response=5833517c49eae3087bb93c977f4ddbea,qop=auth

And then using this exploit: curl -s --max-time 2 imap://127.0.0.1:1143/ --user "admin",realm="evil.com:pass" --login-options "AUTH=DIGEST-MD5"

Produces: username="admin",realm="evil.com",realm="test",nonce="abc123",cnonce="94bd2728bd0e169a68954fecf1778a07",nc="00000001",digest-uri="imap/127.0.0.1",response=796d4900b43a41a294abe87a20a13da9,qop=auth

I've added in the evil realm by injecting a field into the request.

I've attached the full server script so you can see how I tested it.

Impact

Summary:

A username containing " or \ produces a malformed digest-md5 response. This could potentially enable injection of data into the smtp/imap/pop3/ldap auth.

The original report as published on HackerOne, by am-8113. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

curl speaks several authentication schemes, and one of them is SASL DIGEST-MD5, used when curl authenticates to services such as IMAP, SMTP, POP3 and LDAP. In a DIGEST-MD5 exchange the client sends a response containing a set of comma-separated fields, among them username, realm, nonce, cnonce, nc, digest-uri, response and qop. Because those fields are quoted strings separated by commas, any quote or backslash inside a value has to be escaped, otherwise the value can terminate early and the rest of it is parsed as additional fields.

The report concerns the code that builds this response in lib/vauth/digest.c. The same file also handles HTTP Digest authentication, and the HTTP path already escapes the username properly. The SASL path does not.

Setup

The affected version is 8.19.1. The researcher tested on a Mac and expected the behaviour to work on all platforms. To demonstrate the issue they wrote a dummy server, which they say was produced with Claude code and attached in full to the report, and pointed curl at it on loopback addresses:

  • an HTTP Digest server on [redacted]:8888
  • an IMAP server on [redacted]:1143

Finding it

The researcher compared the two code paths in lib/vauth/digest.c. On line 863 the HTTP digest path calls auth_digest_string_quoted(), which escapes the value before placing it in the header. The SASL path on line 478 does not do the same. The username is inserted into the DIGEST-MD5 response without escaping quotes or backslashes.

They also looked at the history. Commit ac419bf sorted out the HTTP side in 2013. The SASL code appears to have been moved into the same file much later, so it was potentially missed at that point. A comment in the code says to escape the realm and nonce as necessary, but it does not mention the user, which fits with the omission.

Exploitation

Step 1: confirm the HTTP path escapes correctly

The first request uses a plain username against the HTTP Digest server:

Bash
curl -s --max-time 2 --digest --user 'admin:pass' http://[redacted]:8888/

It produces:

HTTP
Authorization: Digest username="admin", realm="test", nonce="abc123", uri="/", cnonce="[redacted]=", nc=00000001, qop=auth, response="[redacted]"

This is the baseline: a well-formed header with the username in quotes.

Step 2: show the HTTP path handles a quote in the username

The next request puts a double quote inside the username:

Bash
curl -s --max-time 2 --digest --user 'admin"test:pass' http://[redacted]:8888/

It produces:

HTTP
Authorization: Digest username="admin\"test", realm="test", nonce="abc123", uri="/", cnonce="[redacted]=", nc=00000001, qop=auth, response="[redacted]"

The quote is escaped as \", so the value stays inside its quoted string. This is the behaviour of auth_digest_string_quoted() on the HTTP path.

Step 3: send a quote in the username over SASL DIGEST-MD5

The same idea is then applied to IMAP with SASL DIGEST-MD5:

Bash
curl -s --max-time 2 imap://[redacted]:1143/ --user "admin\"test:pass" --login-options "AUTH=DIGEST-MD5"

It produces:

Text
username="admin"test",realm="test",nonce="abc123",cnonce="[redacted]",nc="00000001",digest-uri="imap/[redacted]",response=[redacted],qop=auth

Here the quote inside the username is not escaped. The value admin"test closes the quoted string after admin, and the parser sees test" as trailing material rather than part of the username. The response is malformed.

Step 4: inject an extra field

The researcher then used the unescaped quote and backslash to close the username value and start a new field, adding a second realm:

Bash
curl -s --max-time 2 imap://[redacted]:1143/ --user "admin\",realm=\"evil.com:pass" --login-options "AUTH=DIGEST-MD5"

It produces:

Text
username="admin",realm="evil.com",realm="test",nonce="abc123",cnonce="[redacted]",nc="00000001",digest-uri="imap/[redacted]",response=[redacted],qop=auth

The username value is closed after admin, and the injected realm="evil.com" appears as a field of its own, ahead of the genuine realm="test" that the server supplied. The researcher describes this as adding an evil realm by injecting a field into the request.

Root cause

The SASL DIGEST-MD5 response builder in lib/vauth/digest.c (line 478) inserts the username into the response without escaping quotes or backslashes. The HTTP digest path in the same file (line 863) uses auth_digest_string_quoted() and is therefore safe. The existing defence on the HTTP side was simply not applied to the SASL side, likely because the SASL code was moved into the file long after the HTTP fix in commit ac419bf and the escaping was not carried over. The comment about escaping the realm and nonce does not cover the username, so nothing in the code prompted the check.

Impact

A username containing " or \ produces a malformed DIGEST-MD5 response. The researcher states this could potentially enable injection of data into SMTP, IMAP, POP3 or LDAP authentication. The demonstrated case injects an additional realm field into the response. The report is rated low severity and does not show a concrete attack against a real service; the demonstration runs against the researcher's own dummy server.

Fix

The report does not describe a fix.

Variants to test

  • Other SASL mechanisms that build a quoted, comma-separated response from user-controlled values: try a username containing " and \ and check whether the value is escaped in the wire output.
  • Other fields in the DIGEST-MD5 response that come from configuration rather than the server, such as the realm or digest-uri, if a client lets you influence them.
  • The same comparison across protocols: run the identical username against HTTP Digest and against IMAP, SMTP, POP3 and LDAP DIGEST-MD5 and diff the escaping. A positive result is an unescaped quote in the SASL output where the HTTP output shows \".
  • Duplicate-field handling on the server side: send a response with two realm fields, as in the demonstration, and observe which one the server uses. A positive result is the server accepting or preferring the injected value.

Hunting notes

This kind of bug hides where one code path was fixed and a parallel path was added or moved later without the same treatment. Comparing sibling functions in the same file, especially where one calls a quoting or escaping helper and the other does not, is a quick way to spot it. Commit history helps: a fix from years earlier plus a later refactor that pulled new code into the same file is a signal to check whether the fix was carried over. Comments that mention escaping some fields but not others are another signal.

The researcher built a dummy server and showed the output for a normal username, a username with a quote, and a crafted username that injects a second realm field.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

curl is a command-line tool that fetches things from the internet. It can also log in to mail servers and directory servers. One of the ways it logs in is called SASL DIGEST-MD5. When curl uses this method, it sends a short text message to the server containing several pieces of information, such as the username, a random value called a nonce, and a scrambled password proof called a response. These pieces are written as name="value" pairs separated by commas, like items on a shopping list.

Because the values sit inside quotation marks, any quotation mark or backslash that appears inside a value must be escaped, meaning it gets a backslash in front of it so the server knows it is part of the value and not the end of it. If that escaping is missing, a username containing a quote can close its own value early, and whatever comes after it gets read by the server as extra fields. That is the bug: curl builds the SASL DIGEST-MD5 message without escaping the username, so a crafted username can inject additional fields into the login message.

The same file in curl also handles a different login method called HTTP Digest, and that path does escape the username correctly. The report compares the two paths side by side to show the difference.

The product and the feature

curl is a program you run in a terminal. It is used both by people and by other software to talk to web servers, mail servers and more. The report concerns version 8.19.1.

SASL stands for Simple Authentication and Security Layer. It is a general way for a client and a server to agree on how to prove who the client is. DIGEST-MD5 is one of the methods SASL offers. It is used when curl logs in to services such as IMAP (receiving mail), SMTP (sending mail), POP3 (another mail protocol) and LDAP (a directory service, like a company phone book).

In a DIGEST-MD5 exchange, the client sends one message made of comma-separated fields. The fields mentioned in the report are:

  • username: who is logging in.
  • realm: the area or domain the login belongs to.
  • nonce: a random value the server sent earlier, used to make each login unique.
  • cnonce: a random value the client generates.
  • nc: a counter.
  • digest-uri: which service is being accessed.
  • response: the scrambled proof that the client knows the password.
  • qop: the quality of protection, meaning which protections are applied.

Because each value is wrapped in quotation marks and the fields are separated by commas, a quote or backslash inside a value has to be escaped. Otherwise the value ends early and the rest is read as new fields. This is the same idea as writing a name inside quotation marks in a sentence: if the name itself contains a quotation mark, you need a way to show it is part of the name.

Where the bug lives

The code that builds this message is in a file called lib/vauth/digest.c. The same file also handles HTTP Digest authentication, which is the login method web servers use.

The researcher compared the two code paths in that file:

  1. On line 863, the HTTP digest path calls a helper function called auth_digest_string_quoted(). That helper escapes the value before putting it into the header.
  2. On line 478, the SASL path does not call that helper. The username goes into the DIGEST-MD5 message without escaping quotes or backslashes.

They also looked at the history of the code. A commit named ac419bf fixed the HTTP side back in 2013. The SASL code appears to have been moved into the same file much later, so the fix was potentially missed when that happened. A comment in the code says to escape the realm and nonce as necessary, but it does not mention the username, which fits with the omission.

Setting up a test

The researcher tested on a Mac and expected the behaviour to work on all platforms. To demonstrate the issue, they wrote a dummy server, which they say was produced with Claude code and attached in full to the report. A dummy server is a small program that pretends to be a real server so you can watch what a client sends it without touching anything real.

They pointed curl at two addresses on the same machine (the loopback address, which always means "this computer"):

  • an HTTP Digest server on [redacted]:8888
  • an IMAP server on [redacted]:1143

Step 1: confirm the HTTP path escapes correctly

The first request uses a plain username against the HTTP Digest server:

Bash
curl -s --max-time 2 --digest --user 'admin:pass' http://[redacted]:8888/

Line by line:

  • curl: run the curl program.
  • -s: silent mode, so curl does not print progress information.
  • --max-time 2: give up after two seconds, so the test cannot hang.
  • --digest: use HTTP Digest authentication.
  • --user 'admin:pass': log in as the user admin with the password pass.
  • http://[redacted]:8888/: the address of the dummy server on this computer, port 8888.

It produces:

HTTP
Authorization: Digest username="admin", realm="test", nonce="abc123", uri="/", cnonce="[redacted]=", nc=00000001, qop=auth, response="[redacted]"

This is the baseline: a well-formed header with the username in quotes. The Authorization header is the part of an HTTP request where the client proves who it is. Everything here looks as expected, with each value neatly inside its own quotation marks.

Step 2: show the HTTP path handles a quote in the username

The next request puts a double quote inside the username:

Bash
curl -s --max-time 2 --digest --user 'admin"test:pass' http://[redacted]:8888/

This is the same command as before, except the username is now admin"test instead of admin. The point is to see what curl does when the username itself contains the character that marks the end of a value.

It produces:

HTTP
Authorization: Digest username="admin\"test", realm="test", nonce="abc123", uri="/", cnonce="[redacted]=", nc=00000001, qop=auth, response="[redacted]"

The quote is escaped as \", so the value stays inside its quoted string. The server reading this knows the username is admin"test and not two separate things. This is the behaviour of auth_digest_string_quoted() on the HTTP path, and it is the correct way to handle the problem.

Step 3: send a quote in the username over SASL DIGEST-MD5

The same idea is then applied to IMAP with SASL DIGEST-MD5:

Bash
curl -s --max-time 2 imap://[redacted]:1143/ --user "admin\"test:pass" --login-options "AUTH=DIGEST-MD5"

Line by line:

  • curl -s --max-time 2: the same silent, two-second-limit curl as before.
  • imap://[redacted]:1143/: talk to an IMAP server on this computer, port 1143.
  • --user "admin\"test:pass": log in as admin"test with password pass. The backslash before the quote is how the shell passes a literal quote character through.
  • --login-options "AUTH=DIGEST-MD5": tell curl to use the DIGEST-MD5 login method.

It produces:

Text
username="admin"test",realm="test",nonce="abc123",cnonce="[redacted]",nc="00000001",digest-uri="imap/[redacted]",response=[redacted],qop=auth

Here the quote inside the username is not escaped. Look at username="admin"test": the value admin"test closes the quoted string after admin, and the server sees test" as trailing material rather than part of the username. The message is malformed, meaning it does not follow the expected shape and the server cannot read it the way curl intended.

Step 4: inject an extra field

The researcher then used the unescaped quote and backslash to close the username value and start a new field, adding a second realm:

Bash
curl -s --max-time 2 imap://[redacted]:1143/ --user "admin\",realm=\"evil.com:pass" --login-options "AUTH=DIGEST-MD5"

Line by line:

  • The first part is the same IMAP request as before.
  • --user "admin\",realm=\"evil.com:pass": the username is now admin",realm="evil.com and the password is pass. The backslashes are there so the shell passes the quote characters through to curl literally.

It produces:

Text
username="admin",realm="evil.com",realm="test",nonce="abc123",cnonce="[redacted]",nc="00000001",digest-uri="imap/[redacted]",response=[redacted],qop=auth

The username value is closed after admin, and the injected realm="evil.com" appears as a field of its own, ahead of the genuine realm="test" that the server supplied. The researcher describes this as adding an evil realm by injecting a field into the request. In other words, the attacker controls not just the username but the structure of the whole message.

Why it happens

The SASL DIGEST-MD5 response builder in lib/vauth/digest.c (line 478) inserts the username into the response without escaping quotes or backslashes. The HTTP digest path in the same file (line 863) uses auth_digest_string_quoted() and is therefore safe. The existing defence on the HTTP side was simply not applied to the SASL side, likely because the SASL code was moved into the file long after the HTTP fix in commit ac419bf and the escaping was not carried over. The comment about escaping the realm and nonce does not cover the username, so nothing in the code prompted the check.

What it means

A username containing " or \ produces a malformed DIGEST-MD5 response. The researcher states this could potentially enable injection of data into SMTP, IMAP, POP3 or LDAP authentication. The demonstrated case injects an additional realm field into the response. The report is rated low severity and does not show a concrete attack against a real service; the demonstration runs against the researcher's own dummy server.

Fix

The report does not describe a fix.

Variants to test

  • Other SASL mechanisms that build a quoted, comma-separated response from user-controlled values: try a username containing " and \ and check whether the value is escaped in the wire output.
  • Other fields in the DIGEST-MD5 response that come from configuration rather than the server, such as the realm or digest-uri, if a client lets you influence them.
  • The same comparison across protocols: run the identical username against HTTP Digest and against IMAP, SMTP, POP3 and LDAP DIGEST-MD5 and diff the escaping. A positive result is an unescaped quote in the SASL output where the HTTP output shows \".
  • Duplicate-field handling on the server side: send a response with two realm fields, as in the demonstration, and observe which one the server uses. A positive result is the server accepting or preferring the injected value.

Hunting notes

This kind of bug hides where one code path was fixed and a parallel path was added or moved later without the same treatment. Comparing sibling functions in the same file, especially where one calls a quoting or escaping helper and the other does not, is a quick way to spot it. Commit history helps: a fix from years earlier plus a later refactor that pulled new code into the same file is a signal to check whether the fix was carried over. Comments that mention escaping some fields but not others are another signal.

The researcher built a dummy server and showed the output for a normal username, a username with a quote, and a crafted username that injects a second realm field.

Glossary

  • curl: a command-line program for sending requests to servers and fetching data.
  • SASL: Simple Authentication and Security Layer, a general framework for logging in to services.
  • DIGEST-MD5: a SASL login method that sends a comma-separated message of quoted fields, including a scrambled password proof.
  • HTTP Digest: a login method used by web servers, handled by the same file in curl.
  • IMAP: a protocol for reading mail from a server.
  • SMTP: a protocol for sending mail.
  • POP3: another protocol for reading mail.
  • LDAP: a protocol for looking things up in a directory service.
  • Username: the name a client logs in as.
  • Realm: the area or domain a login belongs to.
  • Nonce: a random value the server sends so each login is unique.
  • nc: a counter field in the DIGEST-MD5 message.
  • digest-uri: the field naming which service is being accessed.
  • qop: quality of protection, which protections are applied.
  • Escaping: putting a backslash before a special character so it is treated as part of a value rather than as a separator.
  • Injection: slipping extra data into a message so the receiver reads it as something the sender did not intend.
  • Malformed: not following the expected shape, so the receiver cannot read it correctly.
  • Header: a line in an HTTP request carrying extra information, such as login proof.
  • Loopback address: an address such as [redacted] that always means the same computer.
  • Dummy server: a small program that pretends to be a real server so you can watch what a client sends.
  • Commit: a saved change in a code repository, identified by a short name such as ac419bf.
  • Refactor: reorganising code without changing what it does, which can accidentally drop a fix.
  • Helper function: a small function that does one job, such as escaping a value, called from other code.
  • Severity: a rating of how serious a bug is; this one is rated low.
  • Control: in a test, a known-good case used for comparison against the case being tested.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.