Repository navigation
Conversation
Browser bootstrap collected every cookie in the Playwright context and sent the joined header to whichever candidate URL was refetched, so a cross-origin candidate could receive the source host's session cookies. BrowserSessionState now stores the raw cookie list and the header is built per URL with RFC 6265-style domain/path/secure matching. Closes eellak#121
|
Hello @Xtacy856X !! |
|
andd, one more smaller edge case in the path matcher: |
A cookie scoped to `/download` was forwarded to `/download-private/file.pdf` because the scope check was a bare prefix test. RFC 6265 section 5.1.4 wants an exact match, a cookie path ending in `/`, or a `/` boundary right after the matching prefix.
The refetch rebuilt the Cookie header from the whole browser context, so a `Domain=.example.org` cookie still reached `cdn.example.org` even when the browser's own same-origin request carried no cookie at all. Browser bootstrap now records the Cookie header of each candidate request through Playwright's `all_headers()` (context cookies never appear in `request.headers`) and the refetch replays it verbatim; RFC 6265 matching stays only as the fallback when nothing was captured.
|
Heyy @Princess0407, thanks for digging in, both of those were real. The path one was a plain bug: Your first point I fixed at the root instead of adding another filter. The bootstrap now keeps the Cookie header the browser actually sent on each candidate request and the refetch replays it as-is, so a Both cases have a regression test now. I ran the downloader tests locally (24 passed, 3 failures that are the POSIX-only directory lock tests on Windows, same three on a clean checkout); the workflows on this PR are sitting at action_required, so CI hasn't picked the new commits up yet. |
|
Heyy @Xtacy856X again!! |
|
@Princess0407 The pleasure is all mine! Greetings from Bologna |
Problem
_bootstrap_browser_session_state()collects cookies withcontext.cookies()— every cookie in the browser context, whatever origin set it — and packs them all into oneCookieheader stored inBrowserSessionState. When the first accepted response lives on a different origin than the page that produced it,_fetch_with_browser_session_state()re-fetches the candidate throughaiohttpwith that full header, so cookies belonging to the source host get disclosed to the candidate host. Closes #121 (the issue's reporter reproduced this locally with a real Playwright browser and two HTTP hosts).Approach
BrowserSessionStatenow keeps the raw cookie list instead of a pre-joined header, and the header is built per request URL by a new_cookie_header_for_url()with RFC 6265-style matching:pathmust prefix-match the URL pathsecureare skipped for non-HTTPS fetchesThe session cache is unaffected: state is still cached per domain key, and the filtering happens at fetch time so a reused session also gets origin-scoped cookies per URL.
Tests
Four new tests in
tests/test_browser_gloss_downloader.pycovering the issue scenario (a source-host cookie is not forwarded to a cross-origin candidate, and a CDN-origin cookie still is), domain vs host-only matching, thesecureflag over HTTP vs HTTPS, and cookie path scoping. The existing cached-session test was updated for the newcookiesfield. Verified the tests bite: with the scoping temporarily disabled they all fail.tests/test_browser_gloss_downloader.py: 21 passed.tests/test_corpus_phases_lightweight.pyunchanged from baseline (the remaining failures are Windows-local environment issues:ledger/writer.pydoes a module-levelimport fcntlandos.open()on a directory, both POSIX-only — reported separately from this PR's scope).Risk and exclusions
domainis now dropped rather than sent anywhere; previously such a cookie would have been forwarded to every refetch, which is exactly the behavior under discussion._fetch_with_browser_session_stateget the scoped header automatically; no publicCorpusAPI changed.