Skip to content

VIA-942: Enforce Session Expiry Reliably After 10 Minutes of Inactivity#708

Open
liming-cheung-nhs wants to merge 4 commits intomainfrom
VIA-942/set-signout-cookie
Open

VIA-942: Enforce Session Expiry Reliably After 10 Minutes of Inactivity#708
liming-cheung-nhs wants to merge 4 commits intomainfrom
VIA-942/set-signout-cookie

Conversation

@liming-cheung-nhs
Copy link
Copy Markdown
Contributor

@liming-cheung-nhs liming-cheung-nhs commented Apr 27, 2026

Description

  • Created cookie on logout so when session refresher comes (every 60s), it would see this and not try to refresh.
  • This ensures logout action is honoured.
  • The cookie created holds the session id - this ensures it does not interfere with user having logged in again as it would be under different session id.
  • updated cookie text based on design spec - TBC

Testing on deployed to sandpit personal workspace

  • logged out -> waited 10 mins -> remains logged out (test QA highlighted in ticket)
  • logged in -> wait auto timeout 10 mins -> ignore dialogue box -> wait -> logs out as expected
  • seen new cookie in browser

Note: Existing issue under investigation: getToken will return null, but the MyVaccines app then currently tries to redirect the user to NHS App because they are not authenticated, meaning the user will never see the logout / session timeout screens. (at present this throws a cors error in the browser and the user never actually gets to NHS app but this is a quirk and the underlying issue still needs fixing; the user shouldnt be redirected at all for this part of the journey. The network tab shows the cors error and an error would be logged in our service logs).

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

donna-belsey-nhs and others added 2 commits April 23, 2026 11:29
… recently called

Precommit hooks bypassed; this is a work in progress commit

WIP commit: contains
* A Server Action to set the flag cookie
* Calling the server action from the user-logout method
* cherck the flag in getToken

Issue under investigation
1. getToken will return null, but the MyVaccines app then currently
tries to redirect the user to NHS App because they are not
authenticated, meaning the user will never see the logout / session
timeout screens. (at present this throws a cors error in the browser and
the user never actually gets to NHS app but this is a quirk and the
underlying issue still needs fixing; the user shouldnt be redirected at
all for this part of the journey. The network tab shows the cors error and
an error would be logged in our service logs).

const mockSessionId = "session-id-123";
const setCookie = jest.fn();
jest.mock("sanitize-data", () => ({ sanitize: jest.fn() }));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mock is required because our current Jest setup does not transpile the sanitize-data ESM package in tests, so replacing it with a stub avoids the module parse error and lets the tests run.

};

const setSignOutFlagCookieAction = async () => {
const SIGN_OUT_FLAG_COOKIE_MAX_AGE_SECONDS = 30;
Copy link
Copy Markdown
Contributor Author

@liming-cheung-nhs liming-cheung-nhs Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set it as 30s based on comments in the commit.
I wonder if we should have it higher as the session refresh is every 60s (see ClientProviders.tsx).

If we get a refresh, then a logout within next 30s, then the next refresh in 60s would not see the cookie as it has expired? 🤔

Co-authored-by: Copilot <copilot@github.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