Remember-me cookie in SessionAuthAdapter missing httpOnly and secure flags#450
Conversation
📝 WalkthroughWalkthroughThis PR enhances the remember-me cookie security in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #450 +/- ##
============================================
+ Coverage 82.58% 82.65% +0.06%
Complexity 2831 2831
============================================
Files 243 243
Lines 7545 7552 +7
============================================
+ Hits 6231 6242 +11
+ Misses 1314 1310 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/Unit/Auth/Adapters/SessionAuthAdapterTest.php (1)
66-74: Tests verify cookie presence but not the security flags.The test correctly verifies that the
remember_tokencookie is set and has a non-empty value. However, per the PR objectives, tests should also assert that the cookie is created withsecure=true,httponly=true, and proper expiration.The current
Cookieclass stores only the value inself::$storage, making flag verification difficult without mocking. Consider one of these approaches:
- Mock the
cookie()helper to capture and verify all parameters passed toset()- Add a spy/wrapper that records the flags for test inspection
Example approach using a mock
public function testWebSigninWithRememberSetsCookieWithSecureFlags(): void { // This would require refactoring to inject a mock Cookie or use a test double // that can capture the parameters passed to set() $cookieMock = $this->createMock(Cookie::class); $cookieMock->expects($this->once()) ->method('set') ->with( 'remember_token', $this->anything(), 2592000, // REMEMBER_TOKEN_LIFETIME '/', '', true, // secure true // httponly ); // Inject mock and call signin... }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Unit/Auth/Adapters/SessionAuthAdapterTest.php` around lines 66 - 74, The test testWebSigninWithRememberSetsCookie currently only checks presence/value; update it to also assert secure, httponly and expiration by either (A) mocking the Cookie helper used by SessionAuth::signin (mock the Cookie class or cookie() helper and expect cookie->set('remember_token', ..., REMEMBER_TOKEN_LIFETIME, '/', '', true, true)) and inject that mock into the code path used by SessionAuth, or (B) add a minimal test-only spy/wrapper around the Cookie class that records set() parameters into a public inspectable property and use that spy in the test to assert secure === true, httponly === true and that the expiration equals the REMEMBER_TOKEN_LIFETIME constant; locate the code around SessionAuth::signin, the Cookie class, and the test method testWebSigninWithRememberSetsCookie to implement the chosen approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/Unit/Auth/Adapters/SessionAuthAdapterTest.php`:
- Around line 66-74: The test testWebSigninWithRememberSetsCookie currently only
checks presence/value; update it to also assert secure, httponly and expiration
by either (A) mocking the Cookie helper used by SessionAuth::signin (mock the
Cookie class or cookie() helper and expect cookie->set('remember_token', ...,
REMEMBER_TOKEN_LIFETIME, '/', '', true, true)) and inject that mock into the
code path used by SessionAuth, or (B) add a minimal test-only spy/wrapper around
the Cookie class that records set() parameters into a public inspectable
property and use that spy in the test to assert secure === true, httponly ===
true and that the expiration equals the REMEMBER_TOKEN_LIFETIME constant; locate
the code around SessionAuth::signin, the Cookie class, and the test method
testWebSigninWithRememberSetsCookie to implement the chosen approach.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5e967e9a-8f8f-4f5b-9200-aa69c6bd6a03
📒 Files selected for processing (2)
src/Auth/Adapters/SessionAuthAdapter.phptests/Unit/Auth/Adapters/SessionAuthAdapterTest.php
Fixes #447
Summary by CodeRabbit