Do not guess HTTP-01 response encoding (#8942)

* fix http-01 encoding

* improve comment
This commit is contained in:
Brad Warren
2021-07-14 14:11:50 -07:00
committed by GitHub
parent 7ede5c3487
commit 2ab7857fa5
2 changed files with 14 additions and 1 deletions
+9
View File
@@ -314,6 +314,15 @@ class HTTP01Response(KeyAuthorizationChallengeResponse):
except requests.exceptions.RequestException as error:
logger.error("Unable to reach %s: %s", uri, error)
return False
# By default, http_response.text will try to guess the encoding to use
# when decoding the response to Python unicode strings. This guesswork
# is error prone. RFC 8555 specifies that HTTP-01 responses should be
# key authorizations with possible trailing whitespace. Since key
# authorizations must be composed entirely of the base64url alphabet
# plus ".", we tell requests that the response should be ASCII. See
# https://datatracker.ietf.org/doc/html/rfc8555#section-8.3 for more
# info.
http_response.encoding = "ascii"
logger.debug("Received %s: %s. Headers: %s", http_response,
http_response.text, http_response.headers)
+5 -1
View File
@@ -10,7 +10,11 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).
### Changed
*
* When self-validating HTTP-01 challenges using
acme.challenges.HTTP01Response.simple_verify, we now assume that the response
is composed of only ASCII characters. Previously we were relying on the
default behavior of the requests library which tries to guess the encoding of
the response which was error prone.
### Fixed