Timing Attack Vulnerability in curl Digest Authentication via Non-Constant-Time String Comparison
curl's Digest Authentication compares algorithm names with a non-constant-time string comparison, so response times differ slightly depending on the algorithm. An attacker could use those timing differences to infer which authentication algorithm the server supports.
- Disclosed after 5 hours
Summary:
A timing attack vulnerability exists in curl's Digest Authentication implementation due to the use of non-constant-time string comparison (strcmp()) when comparing authentication algorithms in digest.c line 360. This allows attackers to determine the supported authentication algorithm through response time analysis.
No AI was used to discover this vulnerability or generate this report.
Affected version
* curl version 7.88.1 (x86_64-pc-linux-gnu)
* libcurl/7.88.1 OpenSSL/3.0.8 zlib/1.2.13 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.10.0 nghttp2/1.52.0
* Platform: Linux Ubuntu 22.04.3 LTS
Steps To Reproduce:
- Set up a test server with Digest Authentication enabled:
bash
# Using a simple Python HTTP server with digest auth
python3 -m http.server 8080 --digest
2. Run the timing attack PoC against the local server: *(Attachment on the original report: poc_timing_attack.py)*
bash
python3 poc_timing_attack.py http://localhost:8080/protected
3. Observe the timing differences between algorithm comparisons:
text
Testing algorithm: MD5 - 963236.5 ns
Testing algorithm: MD5-sess - 826390.0 ns
Testing algorithm: SHA-1 - 814495.0 ns
- The PoC will identify the algorithm with significantly different response times:
text
VULNERABILITY CONFIRMED: Timing attack possible
The server likely uses algorithm: MD5
Response time: 963236.50 ns
Deviation: +25.9% from average
Supporting Material/References:
- PoC script output showing timing differences
*Vulnerable code location in digest.c line 360
*curl documentation on Digest Authentication : https://everything.curl.dev/libcurl-http/auth.html
Impact
Summary:
An attacker can exploit this vulnerability to:
1. Determine supported authentication algorithms on the server
2. Facilitate targeted attacks by identifying weaker algorithms (e.g., MD5 vs SHA-256)
3. Gain reconnaissance information about server configuration
4. Potentially bypass authentication if combined with other vulnerabilities
The vulnerability violates the principle of constant-time comparison for security-sensitive operations and could lead to authentication mechanism fingerprinting.
##Additional Information:
* CVSS Score: 5.3 (Medium) - CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
* Fix Recommendation: Replace strcmp() with Curl_timestrcmp() in /lib/vauth/digest.c:360
* Similar vulnerabilities: Previously addressed in other parts of curl codebase with constant-time comparison fixes
Context
curl is a command-line tool and library for transferring data with URLs, and libcurl is the library that implements the protocols. One of the HTTP authentication schemes it supports is Digest Authentication, where the client and server agree on a hashing algorithm and exchange a challenge and a response derived from the user's credentials. The algorithm is negotiated through the algorithm parameter of the WWW-Authenticate challenge, and curl has to compare the value the server sends against the algorithms it knows about.
The report concerns the code that performs that comparison in digest.c, specifically line 360, where strcmp() is used. Because strcmp() returns as soon as it finds a difference, the time it takes depends on how many leading bytes of the two strings match. That is the classic shape of a timing side channel: an attacker who can measure the comparison time precisely enough can learn information about the compared value one byte at a time.
The weakness is classified as Information Exposure Through Timing Discrepancy, with a medium severity. The affected asset is the curl source repository at https://github.com/curl/curl.
Setup
The researcher tested against a specific, documented build rather than an arbitrary deployment:
- curl version 7.88.1 (
x86_64-pc-linux-gnu) libcurl/7.88.1 OpenSSL/3.0.8 zlib/1.2.13 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.10.0 nghttp2/1.52.0- Platform: Linux Ubuntu 22.04.3 LTS
The test needs a server that speaks Digest Authentication and a client that uses the vulnerable curl build. The researcher used a local Python HTTP server with digest auth enabled. The proof-of-concept script is referenced as an attachment on the report (poc_timing_attack.py) but its contents are not reproduced in the text.
Finding it
The researcher identified that the algorithm comparison in digest.c at line 360 is done with strcmp(), a function that is not constant-time. Security-sensitive comparisons, such as those involving secrets or values that an attacker should not be able to probe, are expected to use a constant-time routine so that the execution time does not depend on the input. The report notes that similar issues had previously been addressed elsewhere in the curl codebase with constant-time comparison fixes, which makes this occurrence look like an oversight rather than a deliberate design choice.
The reasoning is that if the comparison short-circuits on the first differing byte, then an attacker who can send many challenges and measure the response time can infer how much of the supplied algorithm string matches what the server expects. Over enough samples, that leaks the supported algorithm.
Exploitation
Step 1: stand up a Digest Authentication server
The researcher started a local server with digest auth enabled:
# Using a simple Python HTTP server with digest auth
python3 -m http.server 8080 --digest
This gives a target on localhost:8080 that issues Digest challenges, so the client-side comparison in curl is exercised on every request to the protected path.
Step 2: run the timing PoC
The PoC script was run against the protected endpoint:
python3 poc_timing_attack.py http://localhost:8080/protected
Step 3: observe the timing differences
The output shows a distinct timing for each algorithm tested:
Testing algorithm: MD5 - 963236.5 ns
Testing algorithm: MD5-sess - 826390.0 ns
Testing algorithm: SHA-1 - 814495.0 ns
The MD5 case is measurably slower than the other two.
Step 4: confirm the vulnerability
The PoC then reports its conclusion:
VULNERABILITY CONFIRMED: Timing attack possible
The server likely uses algorithm: MD5
Response time: 963236.50 ns
Deviation: +25.9% from average
The script identifies MD5 as the likely algorithm and reports a deviation of +25.9% from average. That is the fingerprinting result: the attacker learns which algorithm the server supports without needing any credentials.
Root cause
The comparison of the authentication algorithm in digest.c line 360 uses strcmp(), which is not constant-time. strcmp() stops at the first byte that differs, so the number of bytes it has to examine depends on how much of the attacker-supplied string matches the expected value. That variation in work translates into a variation in response time, which is the side channel.
The report notes that similar issues had previously been addressed in other parts of the codebase with constant-time comparison fixes. The report does not describe any test or review process that should have caught it.
Impact
The report lists four consequences of the vulnerability:
- Determine supported authentication algorithms on the server.
- Facilitate targeted attacks by identifying weaker algorithms (for example MD5 versus SHA-256).
- Gain reconnaissance information about server configuration.
- Potentially bypass authentication if combined with other vulnerabilities.
The report frames the core issue as authentication mechanism fingerprinting: the attacker learns which algorithm the server uses, which is useful for choosing follow-up attacks, but is not by itself an authentication bypass. The fourth point is explicitly conditional on combining this with other vulnerabilities. The CVSS vector given is CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N, scored 5.3 (Medium): network reachable, low complexity, no privileges or user interaction required, with a low confidentiality impact and no integrity or availability impact.
Fix
The report's recommendation is to replace strcmp() with Curl_timestrcmp() at /lib/vauth/digest.c:360. Curl_timestrcmp() is curl's own constant-time string comparison helper, so the comparison time no longer depends on how many leading bytes match. The report does not state whether a patch was merged or which release contains it.
Variants to test
- Other protocol negotiation paths in curl. Anywhere the client compares a server-supplied string (algorithm names, auth scheme names, realm values) against a known list is a candidate. A positive result is a measurable timing difference between the value the server actually uses and values it does not, as in the MD5 versus MD5-sess and SHA-1 measurements above.
- Other clients and libraries implementing Digest Authentication. The same pattern, a non-constant-time comparison of the
algorithmparameter, may exist in other implementations. A positive result is the same shape of signal: one candidate consistently slower than the others by a margin larger than the measurement noise. - Server-side algorithm selection. If a server compares the client's proposed algorithm against its supported list with a non-constant-time routine, the same technique applies in the other direction. A positive result is a timing difference that tracks the server's configured algorithm.
- Combining fingerprinting with downgrade attempts. Once the algorithm is known, test whether the server accepts a weaker algorithm than it should. A positive result is a successful authentication using the weaker algorithm where policy should have rejected it.
Hunting notes
This kind of bug tends to hide in code paths where a value from the peer is compared against a small set of known constants: algorithm names, scheme names, version strings, and similar negotiation parameters. It is easy to overlook because the compared value is not itself a secret, which is why it often survives review; the leak is about configuration, not credentials.
During recon, the signal is a client or server that exposes a choice of algorithms or schemes and whose responses can be timed. A local or low-latency target makes the measurement practical, which is why the researcher used a local server.
The impact is framed as reconnaissance and fingerprinting, with the conditional bypass noted separately, backed by a PoC with per-algorithm timings and a +25.9% deviation from the average. The CVSS vector supplied in the report matches that framing: low confidentiality impact, no integrity or availability impact.
What happened, in plain words
curl is a small program that fetches things from the internet when you type a web address into a terminal, and it is also a library (a reusable block of code) called libcurl that other programs use to do the same thing. One of the ways curl can log in to a website is called Digest Authentication. In Digest Authentication the website and curl agree on a mathematical recipe, called a hashing algorithm, and use it to scramble the password so the password itself never travels over the network.
Before they can scramble anything, the website has to tell curl which recipe it wants to use. It does this by sending a short message that includes a field called algorithm. curl then compares the value the website sent against the list of algorithms it knows about. The report is about how that comparison is written in curl's source code, in a file called digest.c, on line 360.
The comparison uses a standard programming function called strcmp(). strcmp() compares two pieces of text character by character and stops as soon as it finds a difference. That sounds efficient, and for most purposes it is. But the time it takes depends on how many characters at the start of the two texts are the same. If an attacker can measure that time very precisely, they can learn something about the text being compared, one character at a time. This kind of leak is called a timing attack, and the weakness class here is Information Exposure Through Timing Discrepancy.
The researcher who wrote the report showed that this timing difference can be measured, and that it reveals which algorithm the server is using. The severity was rated medium, and the affected asset is the curl source code repository at https://github.com/curl/curl.
A useful everyday comparison: imagine a bouncer checking names against a guest list by reading both aloud and stopping at the first letter that does not match. If your name starts with the same three letters as a real guest, the bouncer reads three letters before stopping. If it starts with the same five letters, they read five. By timing how long the bouncer reads, you can work out how much of a real name you have guessed correctly, without ever seeing the list.
Context
curl is a command-line tool and a library for transferring data with URLs. A URL is the address you type in a browser, like https://example.com/page. libcurl is the part of curl that actually speaks the protocols, the rules computers use to talk to each other over a network. HTTP is the main protocol used by websites.
One of the login schemes curl supports is Digest Authentication. In this scheme the client (curl) and the server (the website) agree on a hashing algorithm. The client and server then exchange a challenge and a response derived from the user's credentials, so the password itself is never sent.
The algorithm is negotiated through the algorithm parameter of the WWW-Authenticate challenge. WWW-Authenticate is the header (a labelled line in the HTTP response) the server sends to say "you need to log in, and here is how". The algorithm parameter inside it names the recipe the server wants. curl has to compare the value the server sends against the algorithms it knows about, to decide whether it can proceed.
The report concerns the code that performs that comparison in digest.c, specifically line 360, where strcmp() is used. Because strcmp() returns as soon as it finds a difference, the time it takes depends on how many leading bytes of the two strings match. A byte is a single unit of data, roughly one character of text. That is the classic shape of a timing side channel: an attacker who can measure the comparison time precisely enough can learn information about the compared value one byte at a time.
The weakness is classified as Information Exposure Through Timing Discrepancy, with a medium severity. The affected asset is the curl source repository at https://github.com/curl/curl.
Setup
The researcher tested against a specific, documented build rather than an arbitrary deployment. The researcher tested against a specific, documented build.
- curl version 7.88.1 (
x86_64-pc-linux-gnu) libcurl/7.88.1 OpenSSL/3.0.8 zlib/1.2.13 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.10.0 nghttp2/1.52.0- Platform: Linux Ubuntu 22.04.3 LTS
The long second line is the version banner: it lists libcurl and every supporting library it was built with, such as OpenSSL (for encryption) and zlib (for compression).
The test needs two things: a server that speaks Digest Authentication, and a client that uses the vulnerable curl build. The researcher used a local Python HTTP server with digest auth enabled, so the whole experiment runs on one machine.
The proof-of-concept script is referenced as an attachment on the report (poc_timing_attack.py) but its contents are not reproduced in the text. A proof of concept, or PoC, is a small program that demonstrates a vulnerability actually works, rather than just describing it in theory.
Finding it
The researcher identified that the algorithm comparison in digest.c at line 360 is done with strcmp(), a function that is not constant-time. Constant-time means the operation always takes the same amount of time, no matter what the inputs are. Security-sensitive comparisons, such as those involving secrets or values that an attacker should not be able to probe, are expected to use a constant-time routine so that the execution time does not depend on the input.
The report notes that similar issues had previously been addressed elsewhere in the curl codebase with constant-time comparison fixes. In other words, the project already knew about this class of bug and had fixed it in other places. That makes this occurrence look like an oversight rather than a deliberate design choice.
The reasoning is that if the comparison stops at the first differing byte, then an attacker who can send many challenges and measure the response time can infer how much of the supplied algorithm string matches what the server expects. Over enough samples, that leaks the supported algorithm. "Over enough samples" means the attacker repeats the measurement many times and averages the results, because a single measurement is too noisy to trust.
Exploitation
Step 1: stand up a Digest Authentication server
The researcher started a local server with digest auth enabled:
# Using a simple Python HTTP server with digest auth
python3 -m http.server 8080 --digest
Line by line:
# Using a simple Python HTTP server with digest authis a comment. The#tells the shell (the program that reads your typed commands) to ignore the rest of the line. It is there for the human reader.python3runs Python, a programming language that comes with many small built-in tools.-m http.servertells Python to run its built-in web server module. A module is a bundle of ready-made code.8080is the port number. A port is like a numbered door on a computer: the web server listens on door 8080, so requests addressed to that door reach it. Ports let one machine run many services at once.--digestswitches the server into Digest Authentication mode, so it will issue Digest challenges instead of just serving files.
This gives a target on localhost:8080 that issues Digest challenges. localhost is the name a computer uses for itself, so the client and server are the same machine. The client-side comparison in curl is exercised on every request to the protected path, which is what makes the timing measurable.
Step 2: run the timing PoC
The PoC script was run against the protected endpoint:
python3 poc_timing_attack.py http://localhost:8080/protected
Line by line:
python3runs Python again.poc_timing_attack.pyis the name of the script file. The.pyending shows it is Python code.http://localhost:8080/protectedis the address of the target.http://is the protocol,localhostis the machine,8080is the port, and/protectedis the path, the specific page or resource on the server. The name suggests it is a page that requires login.
A candidate algorithm is one of the names the script tries, such as MD5 or SHA-1.
Step 3: observe the timing differences
The output shows a distinct timing for each algorithm tested:
Testing algorithm: MD5 - 963236.5 ns
Testing algorithm: MD5-sess - 826390.0 ns
Testing algorithm: SHA-1 - 814495.0 ns
Line by line:
Testing algorithm: MD5means the script tried the algorithm name MD5. MD5 is an old hashing algorithm.963236.5 nsis the measured time in nanoseconds. A nanosecond is one billionth of a second, so this is roughly one millisecond. The.5shows the measurement is precise enough to record fractions of a nanosecond.Testing algorithm: MD5-sessis a variant of MD5 where the session is mixed into the hash.826390.0 nsis the time for that variant, noticeably smaller than the MD5 time.Testing algorithm: SHA-1is another hashing algorithm, older than SHA-256 but newer than MD5.814495.0 nsis its time, the smallest of the three.
The MD5 case is measurably slower than the other two.
Step 4: confirm the vulnerability
The PoC then reports its conclusion:
VULNERABILITY CONFIRMED: Timing attack possible
The server likely uses algorithm: MD5
Response time: 963236.50 ns
Deviation: +25.9% from average
Line by line:
VULNERABILITY CONFIRMED: Timing attack possibleis the script's verdict. It is the script's verdict that a timing attack is possible.The server likely uses algorithm: MD5is the fingerprint. The script has worked out which algorithm the server is configured with, without any credentials.Response time: 963236.50 nsrepeats the measurement for the winning candidate.Deviation: +25.9% from averagesays how far that measurement sits from the average.
That is the fingerprinting result: the attacker learns which algorithm the server supports without needing any credentials. Fingerprinting means building a profile of a system's configuration by observing its behaviour.
Root cause
The comparison of the authentication algorithm in digest.c line 360 uses strcmp(), which is not constant-time. strcmp() stops at the first byte that differs, so the number of bytes it has to examine depends on how much of the attacker-supplied string matches the expected value. That variation in work translates into a variation in response time, which is the side channel. A side channel is any unintended way information leaks out, here through timing rather than through the content of a response.
The report notes that similar issues had previously been addressed elsewhere in curl with constant-time comparison fixes. The report notes that similar issues had previously been addressed in other parts of the codebase. The report does not describe any test or review process that should have caught it.
Impact
The report lists four consequences of the vulnerability:
- Determine supported authentication algorithms on the server.
- Facilitate targeted attacks by identifying weaker algorithms (for example MD5 versus SHA-256).
- Gain reconnaissance information about server configuration.
- Potentially bypass authentication if combined with other vulnerabilities.
Reconnaissance means gathering information about a target before attacking it, the way a burglar might note which windows are unlocked. Knowing that a server uses MD5 rather than SHA-256 is useful because MD5 is the weaker of the two.
The report frames the core issue as authentication mechanism fingerprinting: the attacker learns which algorithm the server uses, which is useful for choosing follow-up attacks, but is not by itself an authentication bypass. An authentication bypass means getting in without valid credentials; this bug does not do that on its own. The fourth point is explicitly conditional on combining this with other vulnerabilities.
The CVSS vector given is CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N, scored 5.3 (Medium). CVSS is a standard scoring system for vulnerabilities. The vector is a compact code describing the conditions:
| Part | Meaning |
|---|---|
AV:N |
Attack Vector: Network. The attacker reaches the target over a network. |
AC:L |
Attack Complexity: Low. No special conditions are needed. |
PR:N |
Privileges Required: None. The attacker needs no account. |
UI:N |
User Interaction: None. No victim has to click anything. |
S:U |
Scope: Unchanged. The impact stays within the vulnerable component. |
C:L |
Confidentiality: Low. Some information leaks. |
I:N |
Integrity: None. Data cannot be altered. |
A:N |
Availability: None. The service cannot be knocked offline. |
In short: network reachable, low complexity, no privileges or user interaction required, with a low confidentiality impact and no integrity or availability impact.
Fix
The report's recommendation is to replace strcmp() with Curl_timestrcmp() at /lib/vauth/digest.c:360. Curl_timestrcmp() is curl's own constant-time string comparison helper, so the comparison time no longer depends on how many leading bytes match. The report does not state whether a patch was merged or which release contains it.
Variants to test
- Other protocol negotiation paths in curl. Anywhere the client compares a server-supplied string (algorithm names, auth scheme names, realm values) against a known list is a candidate. A realm is the label a server gives to the area it is protecting. A positive result is a measurable timing difference between the value the server actually uses and values it does not, as in the MD5 versus MD5-sess and SHA-1 measurements above.
- Other clients and libraries implementing Digest Authentication. The same pattern, a non-constant-time comparison of the
algorithmparameter, may exist in other implementations. A positive result is the same shape of signal: one candidate consistently slower than the others by a margin larger than the measurement noise. - Server-side algorithm selection. If a server compares the client's proposed algorithm against its supported list with a non-constant-time routine, the same technique applies in the other direction. A positive result is a timing difference that tracks the server's configured algorithm.
- Combining fingerprinting with downgrade attempts. Once the algorithm is known, test whether the server accepts a weaker algorithm than it should. A downgrade is when a system is pushed to use a weaker option than it ought to. A positive result is a successful authentication using the weaker algorithm where policy should have rejected it.
Hunting notes
This kind of bug tends to hide in code paths where a value from the peer is compared against a small set of known constants: algorithm names, scheme names, version strings, and similar negotiation parameters. The peer is the other end of the connection, here the server. It is easy to overlook because the compared value is not itself a secret, which is why it often survives review; the leak is about configuration, not credentials. Reviewers tend to ask "is this value sensitive?" and, seeing an algorithm name, say no. The right question is "can an attacker learn something useful from the timing?"
During recon, the signal is a client or server that exposes a choice of algorithms or schemes and whose responses can be timed. A local or low-latency target makes the measurement practical, which is why the researcher used a local server.
The impact is framed as reconnaissance and fingerprinting, with the conditional bypass noted separately, backed by a PoC with per-algorithm timings and a +25.9% deviation from the average. The CVSS vector supplied in the report matches that framing: low confidentiality impact, no integrity or availability impact.
Glossary
- Algorithm (hashing algorithm): a one-way mathematical recipe that turns text into a fixed-length scrambled value.
- Authentication: proving who you are to a system, usually with a username and password.
- Authentication bypass: getting into a system without valid credentials.
- Byte: a single unit of data, roughly one character of text.
- Constant-time: an operation that always takes the same amount of time regardless of its inputs.
- curl: a command-line tool and library for transferring data with URLs.
- CVSS: a standard scoring system for rating the severity of vulnerabilities.
- Digest Authentication: a login scheme where client and server agree on a hashing algorithm and exchange a challenge and response, so the password is never sent.
- Downgrade: pushing a system to use a weaker option than it should.
- Fingerprinting: building a profile of a system's configuration by observing its behaviour.
- Header: a labelled line in an HTTP request or response carrying metadata.
- HTTP: the protocol websites use to exchange pages and data.
- Jitter: normal variation in network delay.
- Latency: the delay in sending data across a network.
- libcurl: the library inside curl that implements the protocols.
- localhost: the name a computer uses for itself.
- MD5: an old hashing algorithm, considered weak by modern standards.
- Module: a bundle of ready-made code in a programming language.
- Nanosecond: one billionth of a second.
- Path: the specific page or resource on a server, such as
/protected. - Peer: the other end of a network connection.
- Port: a numbered door on a computer that a service listens on.
- Proof of concept (PoC): a small program that demonstrates a vulnerability actually works.
- Protocol: a set of rules computers follow to talk to each other.
- Realm: the label a server gives to the area it is protecting.
- Reconnaissance: gathering information about a target before attacking it.
- SHA-1: a hashing algorithm older than SHA-256 but newer than MD5.
- SHA-256: a modern hashing algorithm.
- Shell: the program that reads the commands you type.
- Side channel: an unintended way information leaks out, such as through timing.
strcmp(): a standard programming function that compares two strings and stops at the first difference.- String: a piece of text in programming.
- Timing attack: an attack that learns secrets by measuring how long operations take.
- URL: the address of something on the internet, like
https://example.com/page. WWW-Authenticate: the HTTP response header a server sends to request login and describe how to do it.