← Tous les articles

SaaS user impersonation for support teams, done safely

Seeing exactly what the customer sees saves your support team hours. Built carelessly, impersonation becomes the most dangerous door into your app. Permissions, time limits, blocked actions and audit trails.

SaaS user impersonation for support teams, done safely

Key points

  • Keep the support agent’s identity in the session: you log in on top of the user, not instead of them.
  • Block sensitive actions in support mode: password, email, billing, API keys.
  • Every impersonation session is time-limited, justified and written to the audit log.

“I can’t see the button you’re talking about.” When a customer reports a problem, nothing beats looking at their screen, with their data and their permissions. Most SaaS products eventually add a “Log in as” button to the back office. On the apps we build, we treat that button with the same care as the login form, because that’s what it is: a way to get someone else’s session.

Remember who is really at the keyboard

The usual mistake is to overwrite the user ID in the session and call it done. The app no longer knows a support agent is driving, the audit log blames the customer, and there’s no clean way back to the original account.

Keep two identities instead: the customer’s, used for permissions and display, and the admin’s, used for accountability. Regenerate the session ID on the way in and on the way out.

function startImpersonation(User $admin, User $target, string $reason): void
{
    if (!$admin->can('support.impersonate') || $target->isStaff()) {
        throw new AccessDenied();
    }
    if (!$target->account->allowsSupportAccess()) {
        throw new AccessDenied('Support access disabled by the customer');
    }

    session_regenerate_id(true);
    $_SESSION['impersonator_id'] = $admin->id;
    $_SESSION['user_id'] = $target->id;
    $_SESSION['impersonation_expires'] = time() + 30 * 60;

    audit_log('impersonation.started', actor: $admin->id, target: $target->id,
              meta: ['reason' => $reason]);
}

Set two rules from day one: only a specific role can impersonate, and nobody can impersonate another staff member. Otherwise one compromised support account opens every admin account.

Block what support never needs

Support needs to look around and sometimes fix a setting. It never needs to change the customer’s password, email or payment details, or to create API keys. List those actions and refuse them explicitly:

const BLOCKED_WHILE_IMPERSONATING = [
    'account.password', 'account.email', 'account.delete',
    'billing.update', 'api_keys.create', 'two_factor.update',
];

function impersonatorId(): ?int
{
    if (empty($_SESSION['impersonator_id'])) {
        return null;
    }
    if (time() > ($_SESSION['impersonation_expires'] ?? 0)) {
        stopImpersonation();
        return null;
    }
    return (int) $_SESSION['impersonator_id'];
}

function denyIfImpersonating(string $action): void
{
    if (impersonatorId() !== null && in_array($action, BLOCKED_WHILE_IMPERSONATING, true)) {
        http_response_code(403);
        exit('This action is not available in support mode.');
    }
}

The time limit takes care of the tab left open all afternoon on a customer account. Watch for side effects too: something done in support mode can email the customer as if they had done it. On one project, a quick check triggered a “your settings were changed” notification that understandably worried the client.

Make it visible and easy to leave

Show a permanent, hard-to-miss banner for the whole session: “You are signed in as Jane Smith. Return to my account.” It prevents editing a customer account while believing it’s your own.

function stopImpersonation(): void
{
    $adminId = $_SESSION['impersonator_id'] ?? null;
    if ($adminId === null) {
        return;
    }
    audit_log('impersonation.ended', actor: $adminId, target: $_SESSION['user_id']);

    session_regenerate_id(true);
    $_SESSION['user_id'] = $adminId;
    unset($_SESSION['impersonator_id'], $_SESSION['impersonation_expires']);
}

On the customer side, offer an “Allow support access” setting and show in their activity log who signed in, when and why. With business customers, that transparency builds trust rather than raising alarms.

FAQ

Should we ask for consent every time?

Not necessarily. A support-access toggle the customer controls, plus a visible record of every session, covers most products. For sensitive data, a one-off approval requested from the support ticket fits better.

Can the agent see the customer’s password?

No, and they should never need to. Passwords are hashed; impersonation works through the session, never through the customer’s credentials.

Building a SaaS and want support tooling that doesn’t weaken security? We can design and review these features with your team.

Partager LinkedIn Facebook X WhatsApp
</>

webtestudio

Agence web : sites WordPress sur mesure, thèmes premium et logiciels SaaS.

Parler de votre projet →