mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Do not transform requestHeaders when logging (#1965)
Requester.__log() sanitizes the headers of the request so that authentication details are not logged, but this has the side effect of meaning that future requests that use the same Requester object will fail. Usually, this is perfectly fine, since almost every method will only make one request -- where this falls down is when we make another after a redirect. Make a copy of the requestHeaders, and sanitize those. Fixes #1959
This commit is contained in:
+6
-5
@@ -629,17 +629,18 @@ class Requester:
|
||||
if self.__logger is None:
|
||||
self.__logger = logging.getLogger(__name__)
|
||||
if self.__logger.isEnabledFor(logging.DEBUG):
|
||||
headersForRequest = requestHeaders.copy()
|
||||
if "Authorization" in requestHeaders:
|
||||
if requestHeaders["Authorization"].startswith("Basic"):
|
||||
requestHeaders[
|
||||
headersForRequest[
|
||||
"Authorization"
|
||||
] = "Basic (login and password removed)"
|
||||
elif requestHeaders["Authorization"].startswith("token"):
|
||||
requestHeaders["Authorization"] = "token (oauth token removed)"
|
||||
headersForRequest["Authorization"] = "token (oauth token removed)"
|
||||
elif requestHeaders["Authorization"].startswith("Bearer"):
|
||||
requestHeaders["Authorization"] = "Bearer (jwt removed)"
|
||||
headersForRequest["Authorization"] = "Bearer (jwt removed)"
|
||||
else: # pragma no cover (Cannot happen, but could if we add an authentication method => be prepared)
|
||||
requestHeaders[
|
||||
headersForRequest[
|
||||
"Authorization"
|
||||
] = "(unknown auth removed)" # pragma no cover (Cannot happen, but could if we add an authentication method => be prepared)
|
||||
self.__logger.debug(
|
||||
@@ -648,7 +649,7 @@ class Requester:
|
||||
self.__scheme,
|
||||
self.__hostname,
|
||||
url,
|
||||
requestHeaders,
|
||||
headersForRequest,
|
||||
input,
|
||||
status,
|
||||
responseHeaders,
|
||||
|
||||
Reference in New Issue
Block a user