Two Systems, One Login: Secure Session Management While PHP and Node.js Run Side by Side

Solution Architect

27 Nov 20267 min read

Two Systems, One Login: Secure Session Management While PHP and Node.js Run Side by Side

When old PHP and new services run side by side, weak session management logs customers out or leaves sessions open. How to keep one source of truth for sign-in.

Careful modernisation plans move a Legacy PHP application gradually. The old system keeps running, a routing layer sits in front of it, and pages or features move to new Node.js services one at a time. That avoids betting the business on one switch-over weekend, but it turns session management, the way an application remembers who is signed in, into a shared security responsibility between two systems.

It does create a new problem. For weeks or months, a customer's visit may touch both systems. They sign in on a page served by PHP, browse a catalogue now served by Node.js, and check out on a page that still runs on PHP. Each step depends on both systems agreeing on who that person is and whether they are still allowed in.

When they disagree, customers notice: they get logged out, lose their basket or see an error halfway through a payment. The less visible failures matter more to a CISO: a session that one system ended and the other still honours is a door left open.

The decision you're facing

When a user signs in, the application gives their browser a session: a long, random reference number, usually stored in a cookie, that the browser sends back with every request. Think of it as a wristband at an event: the guest shows it at every door, and the organisers keep the list of valid wristbands.

A Legacy PHP application usually has its own way of issuing those wristbands, often built years ago and rarely documented. Your new Node.js services need to recognise the same guests. That leaves a choice, made consciously or by accident:

  • Let each system keep its own sessions and try to keep them in step.
  • Teach the new services to read the old system's sessions for the time being.
  • Move the job of deciding who someone is to one shared place that both systems trust.

The right option depends on how your application is built. What matters is that someone decides, rather than letting each new service invent its own answer.

What goes wrong when it's done carelessly

The problems below are potential impacts to plan for, not a record of a specific published incident.

Users logged out without warning. If the two systems don't recognise each other's sessions, a customer who signed in on one page is treated as a stranger on the next. Some simply leave.

Broken checkouts and lost orders. A session often carries more than identity: a basket, a half-completed form, a delivery address. If that context lives in one system and the next step has moved to the other, the order can fail at the worst moment.

Sessions that never expire. OWASP's Session Management Cheat Sheet says every session should have an idle timeout, which ends it after a period of no activity, and an absolute timeout, which ends it after a fixed length of time no matter what. These limits must be enforced on the server. If PHP ends a session after 30 minutes but a new service quietly keeps it alive for days, the weaker rule wins, and a stolen session stays useful far longer than intended.

Logout that only half works. OWASP is explicit that clearing the browser's cookie is not enough: the session must be ended on the server, and every reference belonging to the same sign-in cancelled together. In a split system, a user who logs out on a PHP page may still be signed in to the Node.js part, which matters most on shared or stolen devices.

Sign-in bypasses through shortcuts. Under deadline pressure, one system may simply trust a value the other passes along, such as a user number in a header or a URL. If an outsider can set that value, they can claim to be someone else. OWASP's Top 10:2025 lists exposing session identifiers in the URL or another place the user can reach, and reusing the same session identifier after login, among its Authentication Failures, ranked number 7.

Weakened cookies. The quickest way to let two systems on different addresses share a cookie is to widen it to every part of your domain. OWASP warns against this: a weakness in any one subdomain, such as a forgotten marketing site, can then expose sessions for everything else.

The defensive approach to session management

None of this needs heroics: just a few decisions made early and applied to both systems.

One source of truth for identity. Decide which component is responsible for answering "who is this, and are they still signed in?" Both systems ask that one place rather than keeping competing records. OWASP's own advice is to use a server-side, secure, built-in session manager rather than something home-grown. Replacing a home-grown login with a standard identity service is a larger project; the point here is that there is only ever one answer.

The same rules for lifetime and logout everywhere. Agree one idle timeout, one absolute timeout and one definition of logout, and make both systems honour them. OWASP gives example ranges, such as idle timeouts of 15 to 30 minutes for lower-risk applications and shorter ones for high-value systems, but the right numbers depend on your risk. What matters is that a session ends at the same moment wherever the user is.

A fresh session at sign-in. OWASP says the session reference must be replaced whenever a user's privilege level changes, including when they sign in. Otherwise an attacker who plants a known reference in a victim's browser before login can use it afterwards; this is known as session fixation. Both systems must follow this rule.

Cookie properties agreed in advance. In plain words, OWASP recommends that the session cookie should only travel over encrypted connections (the Secure property), be hidden from scripts running in the page so that injected code cannot read it (HttpOnly), be held back when another website triggers the request (SameSite), and be sent to as few addresses and paths as possible. Settle these once, for both systems, before the first page moves.

Session references that can't be guessed. OWASP sets a minimum amount of randomness for session identifiers so that they cannot be guessed by trial and error. Every new service that issues sessions should meet that bar.

Where Node.js fits, and where it doesn't

A modern Node.js stack gives you well-maintained libraries for sessions and identity, and a chance to design sign-in deliberately instead of inheriting decade-old decisions.

It is not a guarantee. A Node.js service can just as easily set a weak cookie, forget to end sessions on the server or trust a value it should check. During the migration, your security is only as strong as the weaker of the two systems. The improvement comes from the decisions above, not from the choice of language.

What this means for your organisation

Before the first page moves, ask your team:

  • Which system decides who a user is today, and which one will decide during the migration?
  • Do the old and new parts end a session after the same period of inactivity, and after the same maximum lifetime?
  • If a user logs out on any page, are they signed out everywhere, on the server and not just in their browser?
  • Is the session cookie limited to the addresses that need it, or has it been widened for convenience?
  • Does anything rely on a user number passed in a link, a hidden form field or a header that a visitor could change?
  • Who owns sign-in end to end while both systems are live?

Unclear answers are normal for a system that has grown over many years, and the strongest reason to settle them before customers start crossing between old and new.

Recommended next step

Map every place your application signs users in, checks who they are and signs them out, including admin areas, mobile apps and partner integrations. Then agree, in writing, one owner and one set of rules for identity and session lifetime that both the old and new systems will follow throughout the migration. If you want an independent view first, our Free Security and Modernisation Review looks at where your current application is exposed, sign-in and sessions included, and the safest route to a modern platform.

Free Security and Modernisation Review

Sketchmonk is a security-led software engineering company. Our engineers have built software for a national defence research lab, global cyber security vendors and security-first product companies, with 16+ years of engineering behind them. In a free Security and Modernisation Review, we look at the application you run today: where it is exposed, what it depends on, and the safest route to a secure, modern platform. Want to see how we have handled problems like yours? Ask for a case study in the same email. There's no obligation to proceed.

Request your free Security and Modernisation Review

Build with us. Deploy with us. Win with us

We don't deliver projects and walk away. We build with you, inside your mission.

Book a strategic consultation