Course contentsShow
← Node.js
Lesson 1028 of 1,9809. Authentication and Identity ManagementFree lesson

Securing Internal Dashboards

Add layers of IP-based restriction and MFA to sensitive management endpoints.

In this lesson, you will learn how to harden your internal management dashboards by layering IP-based access control and Multi-Factor Authentication (MFA) on top of your existing identity provider.

Internal dashboards are high-value targets; even if your developers are authenticated, a compromised account or a leaked session token could grant an attacker full administrative control. To mitigate this, we treat these routes as "extra-sensitive" and require additional verification.

Layering IP-Based Restrictions

The first line of defense is ensuring traffic originates from your known corporate infrastructure (e.g., your office VPN or static office IP). In Node.js, you can use middleware to inspect the x-forwarded-for header or the request connection object.

const ipWhitelist = ['192.168.1.50', '10.0.0.5'];

const restrictByIP = (req, res, next) => {
  const clientIp = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
  if (!ipWhitelist.includes(clientIp)) {
    return res.status(403).send('Access restricted to internal network.');
  }
  next();
};

Enforcing Step-Up MFA

Even if the user is on the correct network, we should require "Step-Up Authentication" for sensitive endpoints (e.g., /admin/delete-user). Even if the user has an active session, the application forces them to complete a second factor (like an TOTP code) before performing the action.

When your application detects a request to an admin endpoint, check if the session contains a "high-assurance" claim. If it does not, redirect the user to a verification flow:

const verifyMFA = (req, res, next) => {
  if (req.user.authLevel !== 'MFA_VERIFIED') {
    return res.redirect('/mfa-challenge?redirect=' + req.originalUrl);
  }
  next();
};

// Protect the route
app.post('/admin/system-reboot', restrictByIP, verifyMFA, (req, res) => {
  // Logic here
});

By combining these layers, you move away from a "perimeter-only" security model toward a "defense-in-depth" architecture. Even if a bad actor bypasses your primary authentication provider, they are blocked by the IP restriction, and even if they spoof an IP, they are still challenged by the second factor.

Key Takeaway: Never rely on single-factor authentication for sensitive administrative actions; combine network-level gatekeeping with mandatory per-action MFA to ensure that your internal dashboard remains secure even if credentials are stolen.