Skip to content

fix(jahia-log): isolate the spec marker's request from the visitor's session cookie - #253

Merged
x0h01 merged 2 commits into
mainfrom
fix/isolate-jahia-log-marker-from-browser-session
Sep 2, 2026
Merged

fix(jahia-log): isolate the spec marker's request from the visitor's session cookie#253
x0h01 merged 2 commits into
mainfrom
fix/isolate-jahia-log-marker-from-browser-session

Conversation

@x0h01

@x0h01 x0h01 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

The [BEGIN SPEC]/[BEGIN TEST]/[END TEST]/[END SPEC] markers enableSpecsMarker() registers could silently promote the visitor's own session to root, leaking an authenticated view into the very next command the test ran. This fix isolates the marker's request from the browser's session cookie so the feature keeps working exactly as before without that side effect.

Why

executeGroovy authenticates with root's HTTP Basic credentials, but it still runs as a cy.request(), which Cypress attaches to the browser's current cookies like any other request to the app's origin. A servlet container commonly binds Basic-Auth to whatever session a request already carries rather than opening an isolated one, so if the visitor's own session cookie rode along, that session's identity got mutated server-side to root — invisible to the marker itself, but not to whatever the test did next on that same cookie jar.

This is what Jahia/jahia-cypress#251 reports: a consumer moving from 8.2.1 to 8.4.0 saw a logged-in footer on the first page visit after a before hook that ends in cy.logout(). I bisected the regression to this exact mechanism — not to the user-helpers rework the issue's own investigation suspected (that PR predates the 8.2.1 tag and isn't part of the 8.2.1→8.4.0 delta at all). The marker (#234) is the commit that introduced the observable failure, confirmed by building both sides of it from source and running the reporter's own repro spec against each.

Two assumptions are verified:

  • Restoring the same cookie value afterward does not fix it — the server still recognizes that exact session id as root's, because the session object itself was mutated in place, not the cookie string.
  • A hard clearCookies() after the marker's request does fix it, but would silently log out any suite that establishes a session once in an outer before and expects it to persist across every test in the spec (a common pattern, and exactly what loginAndStoreSession's cy.session() caching exists for).

Changes

  • src/support/jahiaLog.tsenableSpecsMarker()'s four hook bodies now run their executeGroovy call through a new withPreservedCookies() helper: snapshot the current cookies, clear the jar, run the marker request (so it gets a disposable session of its own, with nothing pre-existing for Basic-Auth to mutate), clear again, then restore the original snapshot exactly. A session a suite legitimately established earlier is untouched; the marker's own request can never leak into whatever runs right after it.

Validation

  • yarn build and yarn lint — clean.
  • Reproduced #251 locally against a fresh ghcr.io/jahia/jahia-ee-dev:8-SNAPSHOT with luxe-jahia-demo installed, running its tests/cypress/e2e/forms/61-login.cy.ts spec — the exact repro from the issue and from Jahia/luxe-jahia-demo#461:
    • @jahia/cypress@8.2.1/8.3.0/8.4.0 (as published): 8.2.1 passes 7/7, 8.3.0 and 8.4.0 both fail identically on shows the back-office login entry to anonymous visitors.
    • Built from source and bisected: the commit right before feat: add specs and tests marks to jahia log #234 passes; feat: add specs and tests marks to jahia log #234 itself reproduces the failure — isolating the regression to this marker, not to the user-helpers rework the issue suspected.
    • This branch's fix, packed and installed in place of the registry package: 7/7 passing, 3 consecutive clean runs.

Documentation

None — the marker's own behavior and log output are unchanged; only its side effect on the browser's session is removed.

ADR

None.

…session cookie

executeGroovy authenticates with root's HTTP Basic credentials, but cy.request()
still attaches the browser's current cookies. A servlet container commonly binds
Basic-Auth to whatever session a request already carries rather than opening an
isolated one, so the [BEGIN TEST]/[END TEST] marker beforeEach/afterEach could
silently promote the visitor's own session to root before the next command ran.

Run the marker's request on a disposable, cleared cookie jar and restore the
original snapshot afterward, so it can never touch the session a test (or a
suite's loginAndStoreSession) is actually relying on.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🦜 Chachalog

@jahia/cypress patch

Create a new entry online or run npx chachalog@0.5.6 prompt to create a new entry locally.

@pkg-pr-new

pkg-pr-new Bot commented Sep 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@jahia/cypress@253.tgz

commit: 4e04ca3

@x0h01
x0h01 merged commit 058ce0d into main Sep 2, 2026
19 checks passed
@x0h01
x0h01 deleted the fix/isolate-jahia-log-marker-from-browser-session branch September 2, 2026 11:56
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.

A consumer moving from @jahia/cypress 8.2.1 to 8.4.0 sees a logged-in footer on the first visit after a before hook

2 participants