View Issue Details

IDProjectCategoryView StatusLast Update
0010328libmicrohttpd2Generalpublic2025-09-07 01:01
Reporterarthurscchan Assigned ToKarlson2k  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Fixed in VersionGit master 
Summary0010328: A logic bug in algorithm enum parsing found in `auth_digest.c`
DescriptionThe issue was discovered in the function [`get_rq_dauth_algo(...)`](https://git.gnunet.org/libmicrohttpd2.git/tree/src/mhd2/auth_digest.c#n468) within `src/mhd2/auth_digest.c`. When the client’s `algorithm` parameter is **quoted**, several mappings return the **wrong** enum, diverging from the behaviour of the unquoted branch. Specifically:

* `"MD5-sess"` is mapped to **`MHD_DIGEST_AUTH_ALGO_SHA512_256`** (should be **`MHD_DIGEST_AUTH_ALGO_MD5_SESSION`**).
* `"SHA-512-256-sess"` is mapped to **`MHD_DIGEST_AUTH_ALGO_MD5_SESSION`** (should be **`MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION`**).
* `"SHA-512-256"` (non-session) is mapped to **`MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION`** (should be **`MHD_DIGEST_AUTH_ALGO_SHA512_256`**).

Other mappings are correct and consistent with the **unquoted** branch.

```c
if (algo_param->quoted)
{
  ...
  if (mhd_str_equal_caseless_quoted_s_bin_n(..., mhd_MD5_TOKEN mhd_SESS_TOKEN))
    return MHD_DIGEST_AUTH_ALGO_SHA512_256;

  if (mhd_str_equal_caseless_quoted_s_bin_n(..., mhd_SHA512_256_TOKEN mhd_SESS_TOKEN))
    return MHD_DIGEST_AUTH_ALGO_MD5_SESSION;

  if (mhd_str_equal_caseless_quoted_s_bin_n(..., mhd_SHA512_256_TOKEN))
    return MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION;
}
```

The enum `MHD_DigestAuthAlgo` is defined in [`microhttpd2.h`](https://git.gnunet.org/libmicrohttpd2.git/tree/src/include/microhttpd2.h#n7289), which confirms the correct enum values expected here:

```c
enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthAlgo
{
  MHD_DIGEST_AUTH_ALGO_INVALID = 0,
  MHD_DIGEST_AUTH_ALGO_MD5 = ...,
  MHD_DIGEST_AUTH_ALGO_MD5_SESSION = ...,
  MHD_DIGEST_AUTH_ALGO_SHA256 = ...,
  MHD_DIGEST_AUTH_ALGO_SHA256_SESSION = ...,
  MHD_DIGEST_AUTH_ALGO_SHA512_256 = ...,
  MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION = ...,
};
```

Each enum encodes both the **base algorithm** (MD5, SHA-256, SHA-512/256) and whether it is a **session variant** (`-sess`). The buggy code erroneously maps quoted values to different enums, breaking the intended logic of algorithm parsing.

## Consequence

With quoted tokens (e.g., `algorithm="MD5-sess"`), the server misinterprets the algorithm and computing with the wrong digest, or rejecting an otherwise valid response as unsupported. This can cause interoperability problems in real world Digest authentication clients, making compliant clients appear broken.
Additional InformationFound during the ongoing security audit carried out by Ada Logics and facilitated by OSTIF in the libmicrohttpd2 project.
TagsNo tags attached.

Activities

Karlson2k

2025-09-06 16:51

manager   ~0025842

The code processes unescaped token as "unquoted", so any strings like algorithm="MD5-sess" are recognised correctly.

The problem could be triggered only by something exotic like algorithm="M\D5-sess". With such case the authentication still fail as the length of MD5 nonce is different from SHA256 nonce. As "-sess" algorithms are not supported, the only practical difference is another error code reported to application ("wrong nonce" instead of "unsupported algo").

Karlson2k

2025-09-06 16:52

manager   ~0025843

Fixed by 10574ede9dc46eac3ff97fe514c1bb1832537fd7

Issue History

Date Modified Username Field Change
2025-09-02 14:23 arthurscchan New Issue
2025-09-06 16:51 Karlson2k Assigned To => Karlson2k
2025-09-06 16:51 Karlson2k Status new => confirmed
2025-09-06 16:51 Karlson2k Note Added: 0025842
2025-09-06 16:52 Karlson2k Status confirmed => resolved
2025-09-06 16:52 Karlson2k Resolution open => fixed
2025-09-06 16:52 Karlson2k Fixed in Version => Git master
2025-09-06 16:52 Karlson2k Note Added: 0025843
2025-09-07 01:01 root Project libmicrohttpd => libmicrohttpd2
2025-09-07 01:01 root Category digest authentication (HTTP) => General