Skip to content

Commit 7af294e

Browse files
sampras343jku
andauthored
(fix): hang after browser OIDC authentication (#1693)
* (fix): hang after browser OIDC authentication Signed-off-by: Sachin Sampras M <sampras343@gmail.com> * (docs): update changelog with bugfix info Signed-off-by: Sachin Sampras M <sampras343@gmail.com> * (fix): set close connection once before branching Signed-off-by: Sachin Sampras M <sampras343@gmail.com> --------- Signed-off-by: Sachin Sampras M <sampras343@gmail.com> Co-authored-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent ed9f2bb commit 7af294e

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ All versions prior to 0.9.0 are untracked.
88

99
## [Unreleased]
1010

11+
### Fixed
12+
13+
* Fixed ~60s hang after completing browser-based OIDC authentication.
14+
The OIDC redirect server had incomplete HTTP responses and no connection
15+
management, causing a keep-alive deadlock with the browser.
16+
1117
## [4.2.0]
1218

1319
### Fixed

sigstore/_internal/oidc/oauth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,26 @@ def __exit__(
130130

131131

132132
class _OAuthRedirectHandler(http.server.BaseHTTPRequestHandler):
133+
# Short socket timeout to prevent blocking serve_forever() on idle connections
134+
timeout = 1
135+
133136
def log_message(self, format: str, *_args: Any) -> None:
134137
pass
135138

136139
def do_GET(self) -> None:
137140
_logger.debug(f"GET: {self.path} with {dict(self.headers)}")
138141
server = cast(_OAuthRedirectServer, self.server)
139142

143+
# The redirect server only needs one request per connection.
144+
# Close conn immediately to prevent keep-alive from blocking.
145+
self.close_connection = True
146+
140147
# If the auth response has already been populated, the main thread will be stopping this
141148
# thread and accessing the auth response shortly so we should stop servicing any requests.
142149
if server.auth_response is not None:
143150
_logger.debug(f"{self.path} unavailable (teardown)")
144151
self.send_response(404)
152+
self.end_headers()
145153
return None
146154

147155
r = urllib.parse.urlsplit(self.path)
@@ -164,6 +172,7 @@ def do_GET(self) -> None:
164172
else:
165173
# Anything else sends a "Not Found" response.
166174
self.send_response(404)
175+
self.end_headers()
167176

168177

169178
OOB_REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"

0 commit comments

Comments
 (0)