psf / psf/requests

HTTPDigestAuth uses quotes for algorithm and qop tokens of the Digest header

Open
#5,745 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
54.3k
Forks
10.4k
Avg merge
16h 43m
Merged PRs (30d)
3

Description

The HTTPDigestAuth.build_digest_header() method produces the Digest header witch contains quoted strings for algorithm and qop tokens. E.g.:
Digest username="admin", realm="server", nonce="QScBItGtnPq4Dz3v25Tht4SlctJnsR", uri="/api/v1/info", response="e0d12a4b85789351a847c773e6f4b30e", algorithm="MD5", qop="auth", nc=00000001, cnonce="0f905170a2cafe15"

While according to RFC 7616 these tokens must not be quoted:
Digest username="admin", realm="server", nonce="QScBItGtnPq4Dz3v25Tht4SlctJnsR", uri="/api/v1/info", response="e0d12a4b85789351a847c773e6f4b30e", algorithm=MD5, qop=auth, nc=00000001, cnonce="0f905170a2cafe15"

Below is the corresponding part of the RFC:

For historical reasons, a sender MUST only generate the quoted string syntax for the following parameters: username, realm, nonce, uri, response, cnonce, and opaque.

For historical reasons, a sender MUST NOT generate the quoted string syntax for the following parameters: algorithm, qop, and nc.

This can also be seen in requests examples in the RFC.

Current behavior may cause problems with some servers. The following subclass can be used as a temporary workaround:

class FixedHTTPDigestAuth(HTTPDigestAuth):
    def build_digest_header(self, method, url):
        header = super().build_digest_header(method, url)
        invalid_parts = ('algorithm', 'qop')
        parts = header.split(', ')
        for i, part in enumerate(parts):
            if any(part.startswith(ip + '=') for ip in invalid_parts):
                parts[i] = part.replace('"', '')
        header = ', '.join(parts)
        return header

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the HTTPDigestAuth.build_digest_header() method and compare its generated Digest header with the RFC 7616 examples cited in the issue. Done means algorithm and qop use unquoted tokens while the other parameters retain the required quoting.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.