Skip to content

Digest auth fails when the username or realm has non-ASCII bytes (regression since 8.21.0) #23683

Closed

Description

@zerotohero3

I did this

The server sends a UTF-8 realm:

WWW-Authenticate: Digest realm="Área Restrita", nonce="...", qop="auth"

and I run:

curl --digest -u user:secret http://host/

curl answers with:

Authorization: Digest username="user", realm="%C3%81rea Restrita", ...

A non-ASCII user name breaks the same way: -u 'josé:secret' sends username="jos%C3%A9".

I expected the following

The values should be echoed back exactly as received, which is what 8.20.0 does, and the authentication should succeed. Instead, every one of these requests ends with a 401.

a2b943b (digest: escape control codes too) added percent-encoding to auth_digest_string_quoted() for *s < ' ' and *s > 0x7e, and that catches every byte >= 0x80:

  • Where char is signed, those bytes are negative and match the first check.
  • Everywhere else, they match the second.

The response hash is still computed over the raw username and realm. Servers don't percent-decode quoted-string values (RFC 7616 uses unq()), so the server either can't find the user or realm, or it computes a different hash.

Bytes >= 0x80 are allowed as obs-text inside a quoted-string, so they don't need encoding. Only the control codes were the problem.

The same helper also quotes nonce, opaque and uri, and it is used by SASL DIGEST-MD5 (IMAP/POP3/SMTP), so those fields are affected the same way.

curl/libcurl version

curl 8.23.1-DEV (master, a502385). Affects 8.21.0 and later. Builds using Windows SSPI for Digest are not affected.

operating system

Linux. Nothing OS-specific here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions