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() { … }What the user sees
Section titled “What the user sees”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.
How it works
Section titled “How it works”The decision is the server’s, always. The browser never decides that a confirmation is enough.
- 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 aStepUpRequiredcommand carrying a signed challenge (and a warning message, for renderers that do not know the command). - 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. - The renderer repeats the same request with the proof in the
X-Mateu-Step-Upheader. 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.
Declaring it
Section titled “Declaring it”// 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.
[Button][StepUp(MaxAge = "PT2M", Method = "totp")]public Message Send() { … }
[StepUp(Actions = new[] { "create", "save", "delete" })]public class Payees : Crud<Payee> { … }@button()@step_up(max_age="PT2M", method="totp")def send(self): ...
@ui("payees")@step_up(actions=["create", "save", "delete"])class Payees(Crud[Payee]): ...A REST source in sources.yaml can require it for every call:
- name: payments source: url: https://payments.internal/api/payments method: POST stepUp: maxAge: PT2M method: totpstepUp: true takes the defaults. A source declaring stepUp is always proxied: a call the
browser made by itself could not be held by the server.
Providers
Section titled “Providers”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):
@Componentpublic class MyTotpSecrets implements TotpSecrets { @Override public String secretFor(CallerIdentity caller) { return enrolments.secretOf(caller.name()); // Base32, kept encrypted by you }}builder.Services.AddSingleton<ITotpSecrets, MyTotpSecrets>();add_mateu(app, views, totp_secrets=MyTotpSecrets())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.
Settings
Section titled “Settings”| Setting | What 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. |
On the wire
Section titled “On the wire”Additive and backward compatible:
- a new command type
StepUpRequiredwhosedatais{challenge, method, input, prompt, actionId}; - the reserved action
_step-up-verifywith parameters{challenge, response}, answeringdata._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.
Limits
Section titled “Limits”- 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. KeepmaxAgeshort. - 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.
Try it
Section titled “Try it”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.