Skip to content

Commit 00a4bc0

Browse files
committed
Fix test failure in state_mismatch test
1 parent ac2c224 commit 00a4bc0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

msal/oauth2cli/authcode.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ def _process_auth_response(self, auth_response):
164164
# OAuth2 successful and error responses contain state when it was used
165165
# https://www.rfc-editor.org/rfc/rfc6749#section-4.2.2.1
166166
self._send_full_response("State mismatch") # Possibly an attack
167-
# Still set auth_response so the server doesn't hang forever
168-
self.server.auth_response = auth_response
167+
# Don't set auth_response for security, but mark as done to avoid hanging
168+
self.server.done = True
169169
else:
170170
template = (self.server.success_template
171171
if "code" in auth_response else self.server.error_template)
@@ -375,12 +375,13 @@ def _get_auth_response(self, result, auth_uri=None, timeout=None, state=None,
375375
self._server.timeout = timeout # Otherwise its handle_timeout() won't work
376376
self._server.auth_response = {} # Shared with _AuthCodeHandler
377377
self._server.auth_state = state # So handler will check it before sending response
378+
self._server.done = False # Flag to indicate completion without setting auth_response
378379
while not self._closing: # Otherwise, the handle_request() attempt
379380
# would yield noisy ValueError trace
380381
# Derived from
381382
# https://docs.python.org/2/library/basehttpserver.html#more-examples
382383
self._server.handle_request()
383-
if self._server.auth_response:
384+
if self._server.auth_response or self._server.done:
384385
break
385386
result.update(self._server.auth_response) # Return via writable result param
386387

0 commit comments

Comments
 (0)