Skip to content
Misconfiguration Disclosed report Intermediate

In curl's SASL OAUTHBEARER authentication, including the SOH character (0x01) in the username corrupts the message structure.

curl does not validate the username when building SASL OAUTHBEARER messages, so a username containing the SOH separator character injects extra protocol fields. Depending on the server, this could let an attacker rewrite fields such as the host or spoof log entries.

y_security Follow

Originally disclosed on HackerOne

  • Disclosed after 4 days

Summary:

This vulnerability arises because curl fails to validate the contents of the username when constructing OAuth2 authentication messages. Depending on the server-side implementation, this could lead to log tampering or credential spoofing.

Affected version

curl 8.18.0 (x86_64-apple-darwin23.6.0)

Steps To Reproduce:

  1. Set up an IMAP server using Python (port 1430)
  2. Execute curl with the username set to user\x01host=evil.com:

curl -v --url “imap://127.0.0.1:1430” -u "$(python3 -c 'import sys; sys.stdout.buffer.write(b“user\x01host=evil.com”)'):TOKEN“ --oauth2-bearer ”TOKEN"

Actual Output:

--- AUTH MESSAGE RECEIVED --- Raw: b'bixhPXVzZXIBaG9zdD1ldmlsLmNvbSwBaG9zdD0xMjcuMC4wLjEBcG9ydD0xNDMwAWF1dGg9QmVhcmVyIFRPS0VOAQE=' --- DECODED MESSAGE --- b'n,a=user[SOH]host=evil.com,[SOH]host=127.0.0.1[SOH]port=1430[SOH]auth=Bearer TOKEN[SOH][SOH]'

Expected behavior:

The SOH character in the username should be rejected with an error (e.g., CURLE_AUTH_ERROR).

Actual behavior:

The SOH character is passed through without validation, resulting in protocol field injection.

Supporting Material:

Python code for IMAP server (for Steps To Reproduce section)

Python
import socket
import base64

def start_server():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(('127.0.0.1', 1430)) 
    s.listen(1)
    print("Waiting for IMAP OAuth message on port 1430...")

    while True:
        conn, addr = s.accept()
        try:
            conn.send(b"* OK IMAP4rev1 Server Ready\r\n")
            
            conn.recv(1024) 
            conn.send(b"* CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER\r\nA001 OK\r\n")
            
            conn.recv(1024) 
            conn.send(b"+ \r\n")
            
            final_data = conn.recv(4096)
            if final_data:
                print(f"\n--- AUTH MESSAGE RECEIVED ---")
                print(f"Raw: {final_data.strip()}")
                
                try:
                    decoded = base64.b64decode(final_data.strip())
                    print(f"--- DECODED MESSAGE ---")
                    print(decoded.replace(b'\x01', b'[SOH]'))
                except:
                    print("Could not decode base64")
        except Exception as e:
            print(f"Error: {e}")
        finally:
            conn.close()

if __name__ == "__main__":
    start_server()

Impact

Summary:

curl does not validate the username for SOH (0x01) characters before constructing OAUTHBEARER messages.

The username should normally be a single block of data following n,a=. However, in this example, mixing in \x01host=evil.com causes host=evil.com to reach the server as an independent field. This means that another field within the protocol can potentially be rewritten from the username input field. Furthermore, even though the connection is actually made to 127.0.0.1, it may appear in logs as an access attempt to a different host. Server logs could record this as a connection attempt to host=evil.com. This allows attackers to conceal their actions or potentially deceive log audits.

The original report as published on HackerOne, by y_security. 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 supports SASL-based authentication for several protocols, and one of the mechanisms it implements is OAUTHBEARER. In OAUTHBEARER the client sends a single message that carries the authorisation identity and a set of key/value fields, with the SOH character (0x01) acting as the field delimiter. The username supplied to curl ends up inside that message, so anything curl does not validate in the username becomes part of the protocol structure.

The report concerns curl 8.18.0 (x86_64-apple-darwin23.6.0) and the OAUTHBEARER message construction path. The weakness is classified as improper neutralisation of value delimiters: the username is concatenated into a delimited message without checking for the delimiter itself.

Setup

No accounts or special roles are needed. The researcher used:

  • curl 8.18.0 on x86_64-apple-darwin23.6.0.
  • A local IMAP server written in Python, listening on port 1430, which advertises AUTH=OAUTHBEARER and prints the raw and decoded authentication message it receives.
  • An OAuth2 bearer token, passed to curl with --oauth2-bearer.

The test requires only a server that supports OAUTHBEARER.

Finding it

The researcher noticed that curl does not validate the contents of the username when it constructs OAuth2 authentication messages. The username is expected to be a single block of data following n,a=, but nothing stops it from containing the SOH byte that separates fields in the OAUTHBEARER message. If that byte is present, the text after it is parsed by the server as a new, independent field rather than as part of the username.

Exploitation

Step 1: start a local IMAP server

The researcher ran a Python IMAP server on port 1430. It greets the client, advertises the OAUTHBEARER capability, sends a continuation, and then prints whatever authentication message arrives, both raw and base64-decoded with SOH bytes rendered as [SOH].

Python
import socket
import base64

def start_server():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(('[redacted]', 1430))
    s.listen(1)
    print("Waiting for IMAP OAuth message on port 1430...")

    while True:
        conn, addr = s.accept()
        try:
            conn.send(b"* OK IMAP4rev1 Server Ready\r\n")

            conn.recv(1024)
            conn.send(b"* CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER\r\nA001 OK\r\n")

            conn.recv(1024)
            conn.send(b"+ \r\n")

            final_data = conn.recv(4096)
            if final_data:
                print(f"\n--- AUTH MESSAGE RECEIVED ---")
                print(f"Raw: {final_data.strip()}")

                try:
                    decoded = base64.b64decode(final_data.strip())
                    print(f"--- DECODED MESSAGE ---")
                    print(decoded.replace(b'\x01', b'[SOH]'))
                except:
                    print("Could not decode base64")
        except Exception as e:
            print(f"Error: {e}")
        finally:
            conn.close()

if __name__ == "__main__":
    start_server()

Step 2: run curl with a crafted username

The username is set to user\x01host=evil.com, with the SOH byte generated by Python so it survives shell quoting:

Bash
curl -v --url “imap://[redacted]:1430” -u "$(python3 -c 'import sys; sys.stdout.buffer.write(b“user\x01host=evil.com”)'):TOKEN“ --oauth2-bearer ”TOKEN"

Step 3: observe the message the server receives

The server printed the raw base64 message:

Text
--- AUTH MESSAGE RECEIVED ---
Raw: b'[redacted]='

and the decoded form, with SOH bytes shown as [SOH]:

Text
--- DECODED MESSAGE ---
b'n,a=user[SOH]host=evil.com,[SOH]host=[redacted][SOH]port=1430[SOH]auth=Bearer TOKEN[SOH][SOH]'

The decoded message shows the problem directly. The username field begins with n,a=user, but the injected SOH ends it early, and host=evil.com follows as a separate field. curl then appends its own fields: host=[redacted], port=1430 and auth=Bearer TOKEN, each separated by SOH. The decoded message contains two host fields, the first of which came entirely from the username.

Root cause

curl builds the OAUTHBEARER message by concatenating the username into a structure delimited by SOH, without rejecting SOH bytes inside the username. A username containing 0x01 terminates the n,a= value early and everything after it is interpreted as additional key/value fields. The expected behaviour, as stated in the report, is that the SOH character in the username should be rejected with an error such as CURLE_AUTH_ERROR; instead it is passed through without validation, resulting in protocol field injection.

Impact

What happens next depends on the server-side implementation. The report describes two consequences:

  • Field rewriting. A field within the protocol can potentially be rewritten from the username input field. In the demonstration, host=evil.com reaches the server as an independent field alongside curl's own host=[redacted].
  • Log tampering and credential spoofing. Even though the connection is actually made to [redacted], it may appear in logs as an access attempt to a different host. Server logs could record the connection as an attempt to host=evil.com, which lets an attacker conceal their actions or potentially deceive log audits.

The exact outcome depends on the server-side implementation.

Fix

The SOH character in the username should be rejected with an error such as CURLE_AUTH_ERROR. The report does not describe a patch or a specific code change.

Variants to test

  • Other control bytes in the username. Try usernames containing other delimiters or control characters accepted by the target's SASL implementation and check whether the decoded message gains extra fields.
  • Injection through the bearer token. If an application lets users influence the token passed with --oauth2-bearer, check whether SOH bytes there also split the message; a positive result is a decoded message with fields the client did not intend to send.
  • Other protocols using OAUTHBEARER. Repeat the test against SMTP, POP3 or other SASL-capable protocols; a positive result is the same early termination of n,a= and an attacker-supplied key/value pair appearing as its own field.
  • Server-side parsing differences. Send the same crafted message to different server implementations and compare how duplicate host fields are handled; a positive result is a log entry or authorisation decision that reflects the injected value rather than the real connection target.
  • Wrapper scripts and CLIs. Look for tools that pass user-controlled strings into curl's -u option; a positive result is a username containing 0x01 that reaches the server unmodified.

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. 13 min read.

What happened, in plain words

curl is a very common command-line tool that fetches and sends data over the internet. Besides downloading web pages, it can talk to mail servers. One way it proves who you are to a mail server is a scheme called OAUTHBEARER, which is part of a family of login mechanisms called SASL. In OAUTHBEARER, curl sends one single text message that contains your username and a few key/value pairs, such as which host you are connecting to and which token you are presenting. The pieces of that message are separated by a special invisible byte, SOH (value 0x01), which acts like a comma or a full stop in a sentence.

The problem is that curl takes the username you give it and drops it straight into that message without checking what is inside it. If the username itself contains the SOH byte, the server thinks the username has ended early and treats whatever follows as a brand new field. In the demonstration, a username of user\x01host=evil.com makes the server see an extra host=evil.com field that curl never meant to send. This kind of bug is called improper neutralisation of value delimiters: a character that is supposed to separate values is allowed to appear inside a value, so the value can break out of its box.

A simple comparison: imagine a form where you write your name on one line and your address on the next, and the lines are separated by a special marker. If you are allowed to type that marker inside your name, you can end your name early and start writing what looks like a new address line. The person reading the form cannot tell that the second line came from your name field.

The report was filed against curl 8.18.0 (x86_64-apple-darwin23.6.0) and is rated medium severity. The researcher showed the injected field in the message and explained that, depending on the server-side implementation, this could lead to log tampering or credential spoofing.

Context

curl supports SASL-based authentication for several protocols, and one of the mechanisms it implements is OAUTHBEARER. In OAUTHBEARER the client sends a single message that carries the authorisation identity and a set of key/value fields, with the SOH character (0x01) acting as the field delimiter. The username supplied to curl ends up inside that message, so anything curl does not validate in the username becomes part of the protocol structure.

The report concerns curl 8.18.0 (x86_64-apple-darwin23.6.0) and the OAUTHBEARER message construction path. The weakness is classified as improper neutralisation of value delimiters: the username is concatenated into a delimited message without checking for the delimiter itself.

A few terms first, because they come up throughout. A protocol is simply an agreed set of rules for how two computers talk, like the etiquette for a phone call. SASL is a framework for login mechanisms used by mail and other protocols. OAUTHBEARER is one such mechanism: instead of a password, you present a token, which is a long string that acts like a temporary pass. A delimiter is a character that marks where one piece of data ends and the next begins. Concatenating means gluing strings together end to end.

Setup

No accounts or special roles are needed. The researcher used:

  • curl 8.18.0 on x86_64-apple-darwin23.6.0.
  • A local IMAP server written in Python, listening on port 1430, which advertises AUTH=OAUTHBEARER and prints the raw and decoded authentication message it receives.
  • An OAuth2 bearer token, passed to curl with --oauth2-bearer.

IMAP is the protocol mail programs use to read mail from a server. A port is a numbered door on a computer; port 1430 here is just a convenient local door for the test server. A bearer token is a token you simply present, like showing a ticket at a gate: whoever holds it is treated as authorised. The test requires only a server that supports OAUTHBEARER. A wrapper script is a small program that calls another program for you, often filling in some of its options.

Finding it

The researcher noticed that curl does not validate the contents of the username when it constructs OAuth2 authentication messages. The username is expected to be a single block of data following n,a=, but nothing stops it from containing the SOH byte that separates fields in the OAUTHBEARER message. If that byte is present, the text after it is parsed by the server as a new, independent field rather than as part of the username.

Parsing means reading a message according to the rules and splitting it into its parts. The point is that the server has no way to know that the second host field came from the username rather than from curl itself.

Exploitation

Step 1: start a local IMAP server

The researcher ran a Python IMAP server on port 1430. It greets the client, advertises the OAUTHBEARER capability, sends a continuation, and then prints whatever authentication message arrives, both raw and base64-decoded with SOH bytes rendered as [SOH].

Base64 is a way of writing arbitrary bytes using only ordinary letters, digits and a couple of symbols, so that binary data can travel through text-based protocols. Decoding turns it back into the original bytes.

Python
import socket
import base64

def start_server():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(('[redacted]', 1430))
    s.listen(1)
    print("Waiting for IMAP OAuth message on port 1430...")

    while True:
        conn, addr = s.accept()
        try:
            conn.send(b"* OK IMAP4rev1 Server Ready\r\n")

            conn.recv(1024)
            conn.send(b"* CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER\r\nA001 OK\r\n")

            conn.recv(1024)
            conn.send(b"+ \r\n")

            final_data = conn.recv(4096)
            if final_data:
                print(f"\n--- AUTH MESSAGE RECEIVED ---")
                print(f"Raw: {final_data.strip()}")

                try:
                    decoded = base64.b64decode(final_data.strip())
                    print(f"--- DECODED MESSAGE ---")
                    print(decoded.replace(b'\x01', b'[SOH]'))
                except:
                    print("Could not decode base64")
        except Exception as e:
            print(f"Error: {e}")
        finally:
            conn.close()

if __name__ == "__main__":
    start_server()

Line by line:

  1. import socket and import base64 load two Python libraries: one for network connections, one for base64 encoding and decoding.
  2. def start_server(): begins the function that runs the fake mail server.
  3. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) creates a network socket, which is the program's handle for talking over the network. AF_INET means IPv4 addresses, SOCK_STREAM means a reliable stream connection (TCP).
  4. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) lets the program reuse the port immediately if it is restarted, avoiding a common "address already in use" error.
  5. s.bind(('[redacted]', 1430)) attaches the socket to the local address [redacted] (meaning this same computer) and port 1430.
  6. s.listen(1) starts waiting for incoming connections, with room for one waiting client.
  7. print("Waiting for IMAP OAuth message on port 1430...") tells the person running it that the server is ready.
  8. while True: keeps the server running forever, handling one connection after another.
  9. conn, addr = s.accept() waits until a client connects and returns a handle for that connection plus the client's address.
  10. conn.send(b"* OK IMAP4rev1 Server Ready\r\n") sends the standard IMAP greeting. The b prefix means these are raw bytes, and \r\n is the carriage-return plus line-feed pair that ends a line in these protocols.
  11. conn.recv(1024) reads up to 1024 bytes from the client, here the client's first command.
  12. conn.send(b"* CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER\r\nA001 OK\r\n") tells the client which features the server supports, including OAUTHBEARER, and acknowledges the command.
  13. conn.recv(1024) reads the client's next command, the one that starts authentication.
  14. conn.send(b"+ \r\n") sends a continuation, a plus sign meaning "go ahead, send your authentication data".
  15. final_data = conn.recv(4096) reads the authentication message itself, up to 4096 bytes.
  16. if final_data: checks that something actually arrived.
  17. print(f"\n--- AUTH MESSAGE RECEIVED ---") prints a heading so the output is easy to read.
  18. print(f"Raw: {final_data.strip()}") prints the message exactly as received, with surrounding whitespace removed.
  19. try: starts a block that may fail, because decoding can go wrong if the data is not valid base64.
  20. decoded = base64.b64decode(final_data.strip()) turns the base64 text back into the original bytes.
  21. print(f"--- DECODED MESSAGE ---") prints a heading for the readable version.
  22. print(decoded.replace(b'\x01', b'[SOH]')) replaces every SOH byte with the visible text [SOH] so the invisible separator can be seen in the output.
  23. except: catches any decoding error and prints Could not decode base64 instead of crashing.
  24. except Exception as e: catches other errors, such as a dropped connection, and prints them.
  25. finally: conn.close() always closes the connection when the handling is done.
  26. if __name__ == "__main__": start_server() runs the server when the file is executed directly.

Step 2: run curl with a crafted username

The username is set to user\x01host=evil.com, with the SOH byte generated by Python so it survives shell quoting:

Bash
curl -v --url “imap://[redacted]:1430” -u "$(python3 -c 'import sys; sys.stdout.buffer.write(b“user\x01host=evil.com”)'):TOKEN“ --oauth2-bearer ”TOKEN"

Line by line:

  1. curl is the program being run.
  2. -v means verbose: curl prints the details of the conversation, which helps see what is happening.
  3. --url “imap://[redacted]:1430” gives the address to connect to: the IMAP protocol on the local machine at port 1430, which is the test server from step 1.
  4. -u "$(...):TOKEN" supplies the username and a password. The part inside $(...) is a command whose output is inserted into the command line. The password is the placeholder TOKEN; with OAUTHBEARER the password is not what authenticates you.
  5. python3 -c 'import sys; sys.stdout.buffer.write(b“user\x01host=evil.com”)' runs a tiny Python program that writes the exact bytes user, then the SOH byte, then host=evil.com to its output. Writing raw bytes this way avoids the shell mangling the invisible character.
  6. --oauth2-bearer ”TOKEN" supplies the bearer token that curl places in the auth field of the OAUTHBEARER message.

Step 3: observe the message the server receives

The server printed the raw base64 message:

Text
--- AUTH MESSAGE RECEIVED ---
Raw: b'[redacted]='

This is the message as it travelled over the network, encoded in base64. It looks like gibberish because it is not meant to be read by a person; it is the bytes of the message written in a text-safe form.

and the decoded form, with SOH bytes shown as [SOH]:

Text
--- DECODED MESSAGE ---
b'n,a=user[SOH]host=evil.com,[SOH]host=[redacted][SOH]port=1430[SOH]auth=Bearer TOKEN[SOH][SOH]'

This is the same message after decoding, with each invisible SOH byte replaced by the visible label [SOH] so the structure can be read.

The decoded message shows the problem directly. The username field begins with n,a=user, but the injected SOH ends it early, and host=evil.com follows as a separate field. curl then appends its own fields: host=[redacted], port=1430 and auth=Bearer TOKEN, each separated by SOH. The decoded message contains two host fields, the first of which came entirely from the username.

Root cause

curl builds the OAUTHBEARER message by concatenating the username into a structure delimited by SOH, without rejecting SOH bytes inside the username. A username containing 0x01 terminates the n,a= value early and everything after it is interpreted as additional key/value fields. The expected behaviour, as stated in the report, is that the SOH character in the username should be rejected with an error such as CURLE_AUTH_ERROR; instead it is passed through without validation, resulting in protocol field injection.

CURLE_AUTH_ERROR is curl's internal name for an authentication error, the kind of message it would return if it refused to proceed. Field injection means adding fields to a message that the sender did not intend to include.

Impact

What happens next depends on the server-side implementation. The report describes two consequences:

  • Field rewriting. A field within the protocol can potentially be rewritten from the username input field. In the demonstration, host=evil.com reaches the server as an independent field alongside curl's own host=[redacted].
  • Log tampering and credential spoofing. Even though the connection is actually made to [redacted], it may appear in logs as an access attempt to a different host. Server logs could record the connection as an attempt to host=evil.com, which lets an attacker conceal their actions or potentially deceive log audits.

A log is the record a server keeps of what happened, like a visitor book. If the book records the wrong host, anyone reviewing it later is misled. Credential spoofing means making the server believe a different identity or destination is involved than the real one. The exact outcome depends on the server-side implementation.

Fix

The SOH character in the username should be rejected with an error such as CURLE_AUTH_ERROR. The report does not describe a patch or a specific code change.

Variants to test

  • Other control bytes in the username. Try usernames containing other delimiters or control characters accepted by the target's SASL implementation and check whether the decoded message gains extra fields. A control character is a byte that is not meant to be printed, such as a separator or a newline.
  • Injection through the bearer token. If an application lets users influence the token passed with --oauth2-bearer, check whether SOH bytes there also split the message; a positive result is a decoded message with fields the client did not intend to send.
  • Other protocols using OAUTHBEARER. Repeat the test against SMTP, POP3 or other SASL-capable protocols; a positive result is the same early termination of n,a= and an attacker-supplied key/value pair appearing as its own field. SMTP is the protocol for sending mail, POP3 another protocol for reading it.
  • Server-side parsing differences. Send the same crafted message to different server implementations and compare how duplicate host fields are handled; a positive result is a log entry or authorisation decision that reflects the injected value rather than the real connection target.
  • Wrapper scripts and CLIs. Look for tools that pass user-controlled strings into curl's -u option; a positive result is a username containing 0x01 that reaches the server unmodified. A CLI is a command-line interface, a program you drive by typing commands.

Glossary

  • curl: a command-line program for transferring data over many network protocols.
  • SASL: a framework of login mechanisms used by protocols such as IMAP and SMTP.
  • OAUTHBEARER: a SASL login mechanism that presents a token instead of a password.
  • IMAP: the protocol mail programs use to read mail from a server.
  • SMTP: the protocol used to send mail.
  • POP3: a protocol for retrieving mail from a server.
  • Protocol: an agreed set of rules for how two computers communicate.
  • SOH (0x01): a control byte with value 1, used in OAUTHBEARER as the separator between fields.
  • Delimiter: a character that marks where one piece of data ends and the next begins.
  • Improper neutralisation of value delimiters: a weakness where a separator character is allowed inside a value, letting the value break out of its intended place.
  • Field injection: adding fields to a message that the sender did not intend to include.
  • Concatenate: to glue strings together end to end.
  • Parse: to read a message according to the rules and split it into its parts.
  • Base64: a way of writing arbitrary bytes using ordinary text characters, so binary data can travel through text protocols.
  • Token: a string that acts like a temporary pass, presented to prove authorisation.
  • Bearer token: a token that is simply presented, like a ticket at a gate; whoever holds it is treated as authorised.
  • Port: a numbered door on a computer that a service listens on.
  • Socket: a program's handle for a network connection.
  • TCP: a reliable stream connection between two computers.
  • IPv4 / [redacted]: the standard numeric addressing scheme for the internet; [redacted] means this same computer.
  • Wrapper script: a small program that calls another program for you, often filling in some of its options.
  • CLI: a command-line interface, a program you drive by typing commands.
  • Log: the record a server keeps of what happened.
  • Log tampering: making log records show something other than what really happened.
  • Credential spoofing: making a server believe a different identity or destination is involved than the real one.
  • CURLE_AUTH_ERROR: curl's internal name for an authentication error.
  • Control character: a byte that is not meant to be printed, such as a separator or a newline.
  • Severity: a rating of how serious a vulnerability is.

More by y_security

View all

1 more disclosed report, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.