A few years ago a client's support team got a call from a customer whose payout bank account had been changed overnight. The login itself looked normal: correct password, a known browser, a session that had been open for eleven days on a shared office machine. Someone had simply walked up to an unlocked laptop, opened the billing page and swapped the IBAN. Nothing in our stack asked "are you still you?" before a change that moved real money. The fix was not a stronger password policy. It was step-up authentication on the handful of actions that actually matter.
I wrote this with help from AI tools and checked every snippet against current OWASP Authentication and Session Management cheat sheets, NIST SP 800-63B, the WebAuthn Level 3 spec, Laravel 11 and Node 22. I am a Principal Software Engineer in Karachi with 9+ years across PHP/Laravel, Vue, Node and .NET microservices, and I build the free developer tools at PixelValut. This is the final part of the series, and everything here is about hardening an app you own.
๐ Series Navigation โ Passkeys & Session Hardening for Web Apps
- Part 1: Rolling Out Passkeys Without Locking Users Out
- Part 2: Session Lifecycle Hardening: Rotation, Timeouts & Server-Side Revocation
- Part 3: CSRF in 2026: SameSite, Fetch Metadata & Origin Checks
- Part 4: Account Recovery Hardening: The Side Door Next to Your Passkey
- Part 5: Protecting Login Endpoints: Credential-Stuffing Signals & Adaptive Rate Limits
- Part 6 (This Post): Step-Up Authentication for Sensitive Actions
Related earlier posts: Browser Secrets That Leak: Token Storage, Quotas & Outbound Controls ยท OAuth 2.1, OIDC ID Tokens & PKCE Forensics
What is step-up authentication and when should you use it?
Direct answer: Step-up authentication asks an already signed-in user to prove their identity again, freshly and often more strongly, before a sensitive action. Use it for money movement, credential and MFA changes, data exports, role changes and destructive deletes. Record when and how the user re-authenticated, allow the action only within a short window, and log every elevated action.
Classify actions before writing code
The mistake I see most is protecting everything or nothing. If every settings page asks for a passkey, users learn to click through prompts and complain until you remove them. Start by putting actions into tiers:
| Tier | Example actions | Required proof | Freshness window | Notify user? |
|---|---|---|---|---|
| 0 โ Normal | Read dashboards, edit profile name | Valid session | Session lifetime | No |
| 1 โ Sensitive | View API keys, export personal data, invite users | Re-auth with any enrolled factor | 15 minutes | Optional |
| 2 โ Critical | Change email, password, MFA, payout account; create API keys | Phishing-resistant factor (passkey) preferred, else TOTP | 5 minutes | Yes, to old and new contact |
| 3 โ Destructive | Delete organisation, transfer ownership, disable audit log | Passkey + typed confirmation; optional second approver | Single use | Yes, to all admins |
Keep this table in your repository. When someone adds a new endpoint, the review question becomes "which tier is this?" instead of a debate.
Record how and when the user authenticated
Step-up only works if the server knows how fresh and how strong the current authentication is. OpenID Connect already has the vocabulary: auth_time for when the user last actively authenticated, amr for the methods used and acr for the assurance level. Even if you do not use OIDC, store the same facts in your session.
In Laravel, I set them on every successful login or re-auth:
// app/Support/AuthContext.php
final class AuthContext
{
public static function record(Request $request, string $method, int $level): void
{
$request->session()->put('auth.time', now()->timestamp);
$request->session()->put('auth.amr', $method); // 'pwd', 'otp', 'hwk'
$request->session()->put('auth.level', $level); // 1 = password, 2 = passkey/otp
$request->session()->regenerate(); // new ID on privilege change
}
public static function satisfies(Request $request, int $level, int $maxAgeSeconds): bool
{
$time = (int) $request->session()->get('auth.time', 0);
$have = (int) $request->session()->get('auth.level', 0);
return $have >= $level && (now()->timestamp - $time) <= $maxAgeSeconds;
}
}
Regenerating the session ID on elevation matters for the same reason as on login: privilege changed, so the identifier should too (Part 2 covers rotation in detail).
Enforce it with middleware, not page logic
Put the check in one middleware so no controller forgets it. When the check fails, return a clear machine-readable error that tells the frontend what to ask for:
// app/Http/Middleware/RequireStepUp.php
public function handle(Request $request, Closure $next, int $level = 2, int $maxAge = 300)
{
if (AuthContext::satisfies($request, $level, $maxAge)) {
return $next($request);
}
$request->session()->put('stepup.intended', $request->fullUrl());
return response()->json([
'error' => 'step_up_required',
'acr_values' => $level >= 2 ? 'passkey otp' : 'any',
'max_age' => $maxAge,
], 401)->header('WWW-Authenticate', 'Bearer error="insufficient_user_authentication"');
}
// routes/web.php
Route::put('/billing/payout-account', UpdatePayoutAccount::class)
->middleware(['auth', 'stepup:2,300']);
Route::delete('/org', DeleteOrganisation::class)
->middleware(['auth', 'stepup:2,60', 'confirm.typed']);
The insufficient_user_authentication error code comes from RFC 9470 (OAuth 2.0 Step-Up Authentication Challenge). If you run an API with access tokens, follow that RFC and let the client request a new token with acr_values and max_age.
Node/Express version with short-lived elevated tokens
For APIs and SPAs, I avoid making the whole session elevated. Instead, the re-auth endpoint issues a separate, short-lived token scoped to the action:
// stepup.js
import { SignJWT, jwtVerify } from 'jose';
const key = new TextEncoder().encode(process.env.STEPUP_SECRET);
export async function issueElevation(userId, action, amr) {
return new SignJWT({ act: action, amr: [amr] })
.setProtectedHeader({ alg: 'HS256' })
.setSubject(String(userId))
.setIssuedAt()
.setExpirationTime('5m')
.setJti(crypto.randomUUID())
.sign(key);
}
export function requireElevation(action) {
return async (req, res, next) => {
try {
const token = req.get('X-Step-Up-Token');
const { payload } = await jwtVerify(token, key, { algorithms: ['HS256'] });
if (payload.sub !== String(req.user.id) || payload.act !== action) throw new Error('scope');
if (await usedJti(payload.jti)) throw new Error('replay'); // single use
await markJtiUsed(payload.jti, payload.exp);
return next();
} catch {
return res.status(401).json({ error: 'step_up_required', action });
}
};
}
app.put('/billing/payout-account', requireElevation('payout.update'), updatePayout);
Binding the token to one user, one action and one use stops an elevated token from being reused for something else. When I debug these, I paste the token into the JWT decoder to check sub, act and exp, and use the JWT signature verifier with a test key to confirm the signing setup. Never paste production secrets into any web tool.
Use passkeys for the re-auth itself
Passkeys from Part 1 make step-up fast: one fingerprint or face check. The important detail is to require user verification, not just presence, so the authenticator actually confirms the person:
// Browser: request a fresh assertion for step-up
const options = await fetch('/webauthn/stepup/options', { method: 'POST' }).then(r => r.json());
const assertion = await navigator.credentials.get({
publicKey: {
...decodeOptions(options),
userVerification: 'required', // biometric or PIN, not just a tap
allowCredentials: options.allowCredentials, // only this user's credentials
},
});
await fetch('/webauthn/stepup/verify', { method: 'POST', body: JSON.stringify(encode(assertion)) });
On the server, verify that the UV flag is set, the challenge is fresh and single-use, and the credential belongs to the signed-in user. Only then record auth.level = 2 and the new auth.time. If the user has no passkey, fall back to TOTP; avoid SMS for critical tiers where you can.
UX rules that keep step-up from becoming nagware
- Ask at the moment of action, not on page load. Show what is about to happen: "Confirm to change payout account ending 4421."
- Reuse a fresh elevation within its window, so three related edits do not trigger three prompts.
- Keep the user's input. After re-auth, replay the pending request instead of making them fill the form again.
- Show a clear cancel path that leaves nothing half-changed.
- For destructive actions, add a typed confirmation (the organisation name) on top of re-auth.
Log, notify and allow undo
Every tier 2+ action should produce an audit entry and a notification:
{
"event": "payout_account.updated",
"user_id": 4821,
"auth_time": 1763271840,
"amr": "hwk",
"ip": "203.0.113.24",
"user_agent_hash": "9f2cโฆ",
"old_value_suffix": "1180",
"new_value_suffix": "4421",
"request_id": "a1b2c3"
}
Send the notification to the old contact details as well as the new ones, include a "this wasn't me" link that freezes the change and revokes sessions, and for payout changes consider a short hold before the first transfer. This is the same side-door thinking from Part 4: assume one control will eventually fail and make the damage reversible.
Diagnostic checklist
- [ ] Every sensitive endpoint is assigned a tier in a version-controlled table
- [ ] Sessions record
auth_time, method (amr) and level after login and re-auth - [ ] Session ID rotates on every elevation
- [ ] Step-up enforced in middleware, not in individual controllers or the UI
- [ ] API responses use a clear
step_up_required/insufficient_user_authenticationerror - [ ] Elevated tokens are bound to user, action and single use, with โค5 minute expiry
- [ ] Passkey step-up requires user verification and a fresh challenge
- [ ] SMS not accepted for critical or destructive tiers where alternatives exist
- [ ] Pending request is replayed after re-auth; elevation reused within its window
- [ ] Tier 2+ actions audited and notified to old and new contacts with a freeze link
- [ ] Payout and ownership changes have a short delay or second approver
FAQs
Isn't a short session timeout enough?
No. Short timeouts annoy everyone and still leave the riskiest minutes unprotected. Step-up lets normal sessions stay comfortable while the few critical actions get fresh proof.
What if the user has no second factor enrolled?
Ask for the password again at minimum, and use the moment to prompt passkey enrolment. For tier 3 actions, consider requiring enrolment before allowing the action at all.
How does this work with SSO users?
Send the user back to the identity provider with prompt=login or max_age=0 and the desired acr_values, then check auth_time and acr in the returned ID token before allowing the action.
Should admins be exempt?
The opposite. Admin and support accounts can do the most damage, so they should face step-up on impersonation, role changes and data exports, with every use logged.
Can I store the elevated state in localStorage?
Avoid it. Keep elevation server-side in the session, or in a short-lived token held in memory and sent per request. My earlier token-storage post explains why long-lived secrets in browser storage are risky.
How do I test step-up flows?
Write feature tests that call each protected endpoint with a stale auth_time, a low level and a replayed token, and assert a 401 step_up_required. Then test the happy path within the window.
That wraps up Passkeys & Session Hardening for Web Apps. The thread across all six parts: authentication is not a single gate at login. It is a lifecycle โ enrolment, sessions, CSRF, recovery, login defences and step-up โ and each stage needs its own control.
Follow & Connect
- Website: PixelValut Tools
- Watch on YouTube: Resume Boost AI ยท PixelValut ยท Daily AI News By Ali
- TikTok: PixelValut (@pixelvalut007)
- GitHub: Muhammad Ali Mughal (@ali111887)
- LinkedIn: Muhammad Ali Mughal

Top comments (0)