Skip to content

Commit d04a0da

Browse files
linesightclaude
andcommitted
fix(cztomczak#676): reference and debug-log the NULL-browser fallback in cookie filter
The IO-thread CanSendCookie/CanSaveCookie callbacks can receive a CefFrame whose GetBrowser() returns NULL; the early-return fallbacks were previously silent and unexplained. - frame.pyx GetPyFrame(): comment now explains when GetBrowser() is NULL off the UI thread (IO-thread cookie callbacks, cross-origin subresource requests, service workers / CefURLRequest). - cookie_access_filter.pyx CanSendCookie/CanSaveCookie: log the no-resolvable-browser fallback and cite the CEF header doc (cef_resource_request_handler.h > CefCookieAccessFilter). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b745f6a commit d04a0da

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/frame.pyx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ cdef PyFrame GetPyFrame(CefRefPtr[CefFrame] cefFrame):
3030
cdef CefString frameId = cefFrame.get().GetIdentifier()
3131
cdef CefRefPtr[CefBrowser] cefBrowser = cefFrame.get().GetBrowser()
3232
if not cefBrowser.get():
33-
# GetBrowser() can return NULL when a frame is being created or
34-
# destroyed during rapid navigation (e.g. iframes on heavy pages).
33+
# Issue #676: CefFrame::GetBrowser() may return NULL when called off
34+
# the UI thread -- e.g. from the IO-thread CanSendCookie/CanSaveCookie
35+
# callbacks for cross-origin subresource requests, or for requests not
36+
# associated with a live frame (service workers / CefURLRequest).
3537
# Raising here prevents a SIGSEGV from the naked .get().GetIdentifier()
36-
# chain that was here before this check.
38+
# chain that was previously here. Callers that can hit this (the cookie
39+
# filter) guard for it and fall back before calling GetPyFrame.
3740
raise Exception("GetPyFrame(): CefBrowser is NULL"
38-
" (frame lifecycle transition during navigation?)")
41+
" (CefFrame.GetBrowser() unavailable off the UI thread?)")
3942
cdef int browserId = cefBrowser.get().GetIdentifier()
4043
if not browserId:
4144
raise Exception("GetPyFrame(): browserId is 0 (browser not yet initialised)")

src/handlers/cookie_access_filter.pyx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ cdef public cpp_bool CookieAccessFilter_CanSendCookie(
2525
# browser was closed.
2626
if IsBrowserClosed(cef_browser):
2727
return False
28-
if not cef_frame.get().GetBrowser().get():
29-
return True # default: allow cookie
28+
# Issue #676: This callback runs on the IO thread, where
29+
# CefFrame::GetBrowser() may return NULL (observed for cross-origin
30+
# subresource requests). CEF also documents browser/frame as optional
31+
# ("may be NULL for requests originating from service workers or
32+
# CefURLRequest", cef_resource_request_handler.h > CefCookieAccessFilter).
33+
# Without a resolvable browser we cannot build a PyFrame to dispatch on,
34+
# so log and allow the cookie by default (CEF's own default is true).
35+
if not cef_frame.get() or not cef_frame.get().GetBrowser().get():
36+
Debug("CanSendCookie: no resolvable browser for the request"
37+
" (IO-thread / service-worker request); allowing by default")
38+
return True
3039

3140
browser = GetPyBrowser(cef_browser, "CanSendCookie")
3241
frame = GetPyFrame(cef_frame)
@@ -66,8 +75,14 @@ cdef public cpp_bool CookieAccessFilter_CanSaveCookie(
6675
# browser was closed.
6776
if IsBrowserClosed(cef_browser):
6877
return False
69-
if not cef_frame.get().GetBrowser().get():
70-
return True # default: allow cookie
78+
# Issue #676: see CanSendCookie above. On the IO thread
79+
# CefFrame::GetBrowser() may be NULL (and CEF documents browser/frame
80+
# as optional). Without a resolvable browser we cannot build a PyFrame,
81+
# so log and allow the cookie by default.
82+
if not cef_frame.get() or not cef_frame.get().GetBrowser().get():
83+
Debug("CanSaveCookie: no resolvable browser for the request"
84+
" (IO-thread / service-worker request); allowing by default")
85+
return True
7186

7287
browser = GetPyBrowser(cef_browser, "CanSaveCookie")
7388
frame = GetPyFrame(cef_frame)

0 commit comments

Comments
 (0)