Secure field lost in cookie round-trip and setCookies fails on invalid batch #75
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Two related bugs in cookie handling that cause
Storage.setCookiesfailures when using Chromium:1.
Securefield dropped in both conversion directionsplaywrightCookieToCookie(playwright.go ~line 139) does NOT readcookie.Secure:cookieToPlaywrightOptionalCookie(playwright.go ~line 124) does NOT writecookie.Secure:This means
Secureis alwaysfalseafter a round-trip, causing Chromium to reject cookies with__Secure-or__Host-prefixes (which requireSecure=true).2.
AddCookiesis all-or-nothing with no error recoveryIn
browser_init.go(~line 159), all cookies are added in a single batch:If any cookie in the batch is invalid, Chromium rejects the entire call and browser creation fails. There's no way to identify which cookie caused the failure, and all valid cookies are lost too.
Proposed Fix
Fix 1: Map
Securefield in both directionsFix 2: Add cookies one-by-one with error logging
This way one bad cookie doesn't prevent all cookies from loading, and the problematic cookies are logged for debugging.
Impact
Downstream consumer
steve/mortcurrently works around this with validation in its cookie jar (filtering__Secure-/__Host-cookies), but the root cause is here in go-extractor.Starting work on this. Plan of approach:
Securefield mapping in bothcookieToPlaywrightOptionalCookieandplaywrightCookieToCookieinplaywright.goAddCookiescall inbrowser_init.gowith one-by-one cookie adding, logging a warning on failure instead of failing browser creationplaywright_test.goWork finished. PR: #77
Changes:
playwright.go: AddedSecurefield mapping in bothcookieToPlaywrightOptionalCookieandplaywrightCookieToCookiebrowser_init.go: Replaced batchAddCookieswith per-cookie adding +slog.Warnon failureplaywright_test.go: 5 new unit tests for the conversion functionsAll tests pass, clean build.