Skip to content

Handle cookie-gate redirects that loop to the same URL#396

Open
beginner59 wants to merge 4 commits into
j0k3r:masterfrom
beginner59:clean-cookie-gate-pr390
Open

Handle cookie-gate redirects that loop to the same URL#396
beginner59 wants to merge 4 commits into
j0k3r:masterfrom
beginner59:clean-cookie-gate-pr390

Conversation

@beginner59

Copy link
Copy Markdown

Summary

Some sites (for example Tamedia/Piano CMS pages such as tagesanzeiger.ch) respond with:

  • 302 Found
  • Set-Cookie
  • Location pointing back to the same URL

In this case RedirectPlugin raises CircularRedirectionException before the cookie plugin can persist the cookie, so the follow-up request never includes the entitlement token.

This patch fixes that by:

  • adding CookiePlugin to the plugin chain
  • exposing CookiePlugin::storeSetCookies() for manual persistence
  • detecting this specific cookie-gate redirect pattern
  • storing cookies from the redirect response
  • retrying the request once with the stored cookie

Test plan

  • Added testCookieGateRedirectRetriesWithStoredCookie
  • Verified that the retry request includes the stored entitlementToken

@beginner59 beginner59 force-pushed the clean-cookie-gate-pr390 branch 4 times, most recently from 26d8f7f to adf61d6 Compare July 8, 2026 15:42
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.37%. Comparing base (557f8dc) to head (c24194f).

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #396      +/-   ##
============================================
+ Coverage     95.85%   96.37%   +0.51%     
- Complexity      704      713       +9     
============================================
  Files            17       17              
  Lines          1908     1930      +22     
============================================
+ Hits           1829     1860      +31     
+ Misses           79       70       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Juerg1 and others added 2 commits July 9, 2026 12:30
Sites like tagesanzeiger.ch respond with 302, Set-Cookie, and a
Location header pointing back to the same URL. RedirectPlugin
throws CircularRedirectionException before cookies are stored.

Store Set-Cookie from the redirect response and retry the request
once so the entitlement token is sent on the follow-up request.
Remove redundant method_exists() checks that fail PHPStan on
CircularRedirectionException, and add tests for non-cookie-gate
redirects and CookiePlugin edge cases.

Co-authored-by: Cursor <cursoragent@cursor.com>
@beginner59 beginner59 force-pushed the clean-cookie-gate-pr390 branch from ef64689 to 23a46a1 Compare July 9, 2026 10:31
Juerg1 and others added 2 commits July 9, 2026 15:47
Keep the non-cookie-gate redirect regression test, but stop asserting
into Monolog test record offsets so the test suite stays within the
existing PHPStan ignore count.

Co-authored-by: Cursor <cursoragent@cursor.com>
Drop brittle Monolog record-index assertions that broke PHPUnit on CI
while keeping behavioral checks for cookie-gate retry and no-retry paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants