Skip to content

Step-up authentication

Experimental. Some actions deserve more than “the user is signed in”: sending money, changing where it goes, deleting records. Step-up authentication asks the user to confirm who they are right before such an action runs — typically a 6-digit code from an authenticator app — and the server refuses to run it without that confirmation.

You declare it on the action; Mateu does the rest, in every renderer and on every backend:

@Button
@StepUp(maxAge = "PT2M", method = "totp")
public Message send() { … }

They press Send. A dialog asks “Confirm it’s you — Enter the code from your authenticator app.” They type the code; the action runs. A wrong code is asked again with the reason; Cancel runs nothing. Every Mateu renderer draws that dialog with its own look: Vaadin (Lumo and Aura), Redwood, Primer, UI5, SLDS, the phone app and the desktop app.

The decision is the server’s, always. The browser never decides that a confirmation is enough.

  1. The client sends the action as usual. The server checks everything it always checks (access, validation) and, right before the method would run, sees @StepUp. With no valid proof it does not run the method: it answers a StepUpRequired command carrying a signed challenge (and a warning message, for renderers that do not know the command).
  2. The renderer asks the user and sends what they typed to the reserved action _step-up-verify. The server hands it to a provider (TOTP, your password check, your OIDC re-login…). If the provider confirms, the server answers a proof.
  3. The renderer repeats the same request with the proof in the X-Mateu-Step-Up header. The server checks it and runs the action, once.

A proof is:

  • signed by the server (HMAC-SHA256, no state to share between requests);
  • bound to the caller, the view, the action and the payload — a proof for “150 € to Ana” does not send 15 000 € to someone else;
  • single use — a replayed proof is refused;
  • short-lived — maxAge (default 5 minutes).

The check runs after every other check and before an Idempotency-Key is claimed, so a held action never takes the key of the request that will really run it.

An anonymous caller is refused (403): step-up confirms that the person at the keyboard is still the signed-in caller, so there has to be one. Failed confirmations are limited (5 in 5 minutes per caller), and a TOTP code is accepted once.

// one action
@Button
@StepUp(maxAge = "PT2M", method = "totp")
public Message send() { … }
// the writes of a CRUD (or an EditableView, a capability listing): name the actions
@StepUp(actions = {"create", "save", "delete"})
public class Payees extends AutoCrud<Payee> { … }

maxAge is an ISO-8601 duration. method names the provider; leave it empty when the app has only one. On a class, actions names the CRUD’s own actions: create, save, save-and-next, delete (bulk delete included), update-row (inline editing), restore-deleted.

A provider checks what the user typed. Mateu issues and checks the challenge and the proof; the provider only says yes or no.

TOTP (built in). Give Mateu the user’s authenticator secret and the totp provider is active (RFC 6238: SHA-1, 6 digits, 30 seconds, one step of clock drift):

@Component
public class MyTotpSecrets implements TotpSecrets {
@Override
public String secretFor(CallerIdentity caller) {
return enrolments.secretOf(caller.name()); // Base32, kept encrypted by you
}
}

Your own. A password re-check, a code sent by SMS, an OIDC re-authentication (prompt=login, max_age): implement StepUpProvider (.NET IStepUpProvider, Python StepUpProvider) — a method() name, the input() kind (code, password or text), an optional prompt and verify(response, caller, request). Register it as a bean (.NET a service, Python add_mateu(step_up_providers=[…])).

Mateu verifies no tokens of its own: an OIDC re-authentication is the app’s provider, checked with the app’s own libraries.

SettingWhat it does
mateu.step-up.secret / MATEU_STEP_UP_SECRET (.NET MateuOptions.StepUpSecret, Python add_mateu(step_up_secret=…))Signs the challenges and proofs. Without it a random key per process is used — fine for one instance; every instance behind a load balancer must share one.

Additive and backward compatible:

  • a new command type StepUpRequired whose data is {challenge, method, input, prompt, actionId};
  • the reserved action _step-up-verify with parameters {challenge, response}, answering data._stepUp = {proof} or {error};
  • the request header X-Mateu-Step-Up;
  • an optional stepUp: {maxAge, method} on a source catalogue entry.

A renderer that does not know the command shows the warning message the server sends with it, and the action does not run — never the other way round.

  • The used-proof and failed-attempt tables live in memory, per process: behind a load balancer, a proof could be replayed once on another instance within its maxAge. Keep maxAge short.
  • A static bundle (no server) cannot use step-up: there is nobody to hold the action.
  • An action queued offline (@Action(offline = QUEUE)) that needs step-up is not confirmed by the queue’s background sends; run it online.
  • A streamed (sse) action is held like any other, but the dialog only appears on the request/answer path: declare step-up on actions that answer at once.

demo/demo-bank (port 8650): a transfer and a payees CRUD that ask for a code. Its Authenticator page shows the demo key to add to your phone.