Skip to content

fix(session): resume session with its real name, not hard-coded 'x' - #426

Merged
usernane merged 1 commit into
mainfrom
dev
Sep 27, 2026
Merged

usernane merged 1 commit into
mainfrom
dev

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Resume sessions under their real name in SessionManager::checkAndLoadFromCookie() instead of a hard-coded 'x', so session cookies are emitted under the correct name.

Motivation

checkAndLoadFromCookie() looks up the session ID by the requested name but then constructs the resumed Session with 'name' => 'x'. Since the name becomes the cookie name (setNameHelper() → Cookie::setName()), the resumed session's getName() returns 'x' and every emitted Set-Cookie header is written as x=<id> instead of <realName>=<id>. The browser's real session cookie is never updated. Combined with reGenerateID() on login (session-fixation flow), the regenerated ID is emitted under the wrong name, so the browser keeps sending the old (pre-regeneration) ID and the user appears logged out / the new ID is never adopted. Fixes #425.

Changes

  • SessionManager::checkAndLoadFromCookie() now constructs the resumed session with 'name' => $sName (the requested name) instead of 'x'.

UI Changes

Not applicable.

How to Test / Verify

New regression test in tests/WebFiori/Framework/Tests/Session/SessionsManagerTest.php:

  • testResumedSessionKeepsRequestedName — persists a session under a real name, resets the manager (new request), resumes it by ID, and asserts the resumed session is RESUMED, keeps its requested name (not 'x'), and that getCookiesHeaders() emits Set-Cookie: <realName>=....

The test fails on the pre-fix code (Expected 'wf-session' / Actual 'x') and passes after. Full SessionsManagerTest class: 28 tests / 97 assertions passing (6 pre-existing DB skips).

Breaking Changes and Migration Steps

None. This corrects the cookie name of resumed sessions; no application-facing API changes.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) Docs Repo
  • I considered backward compatibility
  • I considered security

Related issues

Closes #425

SessionManager::checkAndLoadFromCookie() constructed the resumed Session
with 'name' => 'x' instead of the requested session name. Because the
name becomes the cookie name, the resumed session's cookie (and any
Set-Cookie header, including a regenerated ID on login) was emitted as
'x=<id>' rather than '<realName>=<id>', so the browser never adopted the
correct/updated session cookie.

Use $sName when constructing the resumed session. Adds a regression
test asserting the resumed session keeps its requested name and that the
emitted cookie header uses that name.
@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.96%. Comparing base (971c662) to head (8e09554).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #426      +/-   ##
============================================
+ Coverage     81.94%   81.96%   +0.02%     
  Complexity     3293     3293              
============================================
  Files           106      106              
  Lines          9735     9735              
============================================
+ Hits           7977     7979       +2     
+ Misses         1758     1756       -2     
Flag Coverage Δ
php-8.1 80.80% <ø> (ø)
php-8.2 80.80% <ø> (ø)
php-8.3 89.21% <100.00%> (+0.02%) ⬆️
php-8.4 89.21% <100.00%> (+0.02%) ⬆️
php-8.5 89.09% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@usernane
usernane merged commit 1751e54 into main Sep 27, 2026
16 checks passed
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.

bug(session): checkAndLoadFromCookie() resumes session with hard-coded name 'x', emitting Set-Cookie under wrong name

1 participant