Skip to content

Commit a56df58

Browse files
jared mauchjared mauch
authored andcommitted
Fix TypeError: Strings must be encoded before hashing
Encode response to bytes before calling sha_new() in AuthListModerator and AuthListPoster authentication branches. In Python 3, hashlib.sha1 requires bytes, not strings. This matches the existing fix in the AuthListAdmin branch.
1 parent a5eb9dd commit a56df58

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

Mailman/SecurityManager.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,23 @@ def cryptmatchp(response, secret):
201201
elif ac == mm_cfg.AuthListModerator:
202202
# The list moderator password must be sha'd
203203
key, secret = self.AuthContextInfo(ac)
204-
if secret and sha_new(response).hexdigest() == secret:
205-
return ac
204+
if secret:
205+
if isinstance(response, str):
206+
response_bytes = response.encode('utf-8')
207+
else:
208+
response_bytes = response
209+
if sha_new(response_bytes).hexdigest() == secret:
210+
return ac
206211
elif ac == mm_cfg.AuthListPoster:
207212
# The list poster password must be sha'd
208213
key, secret = self.AuthContextInfo(ac)
209-
if secret and sha_new(response).hexdigest() == secret:
210-
return ac
214+
if secret:
215+
if isinstance(response, str):
216+
response_bytes = response.encode('utf-8')
217+
else:
218+
response_bytes = response
219+
if sha_new(response_bytes).hexdigest() == secret:
220+
return ac
211221
elif ac == mm_cfg.AuthUser:
212222
if user is not None:
213223
try:

0 commit comments

Comments
 (0)