diff --git a/content/browser/webauth/authenticator_common_impl.cc b/content/browser/webauth/authenticator_common_impl.cc index 58d2c4686bcde..1df0a04aeedf3 100644 --- a/content/browser/webauth/authenticator_common_impl.cc +++ b/content/browser/webauth/authenticator_common_impl.cc @@ -3222,7 +3222,15 @@ void AuthenticatorCommonImpl::CompleteReportRequest( void AuthenticatorCommonImpl::Cleanup() { CHECK(!req_state_ || req_state_->request_key.value() == next_request_key_); + // `req_state_.reset()` destroys the embedder request delegate which can + // synchronously close UI which (via activation observers) may destroy the + // hosting WebContents and therefore `this`. Guard with a WeakPtr and bail + // out if that happens (cf. DigitalIdentityRequestImpl::CompleteRequest). + base::WeakPtr weak_this = weak_factory_.GetWeakPtr(); req_state_.reset(); + if (!weak_this) { + return; + } next_request_key_++; CHECK(next_request_key_); // crash on overflow. Only 2^64 WebAuthn requests // per instance of this object are supported.