Docs Version v0.2
Docs menu

Second factors

SMS codes

Changed 8 min readv0.2

On this page

Introduction

A code sent by text message is the second factor many people already know. It is also the weakest one Signari offers.

Signari can send a code by Short Message Service (SMS) as a second factor. It records the factor as SMS everywhere, so that tokens, audit records and access policies can tell it apart from stronger factors.

You connect a gateway that sends the messages with the SIGNARI_SMS_ environment variables on this page. People then enrol their own number.

Connecting a gateway

Choose one of three gateways. Twilio needs its account details. A webhook covers anything else, including an in-house relay. A verification service makes, sends and checks the code itself:

ShellSIGNARI_SMS_GATEWAY=twilioSIGNARI_SMS_TWILIO_SID=AC...SIGNARI_SMS_TWILIO_TOKEN=...SIGNARI_SMS_FROM=+15550000000        # or a messaging service SID, MG...# or, for anything else -- including an in-house relaySIGNARI_SMS_GATEWAY=webhookSIGNARI_SMS_WEBHOOK_URL=https://sms.internal/sendSIGNARI_SMS_WEBHOOK_AUTH="Bearer ..."# or a verification service that makes, sends and checks the code itselfSIGNARI_SMS_GATEWAY=verify-webhookSIGNARI_SMS_VERIFY_URL=https://verify.internal/v1SIGNARI_SMS_VERIFY_AUTH="Bearer ..."

People enrol at /account/mfa/sms. They see and remove the number at /account/security, with their other sign-in methods. Removing it there or from the enrolment page is the same removal. The holder is told, and when it was the last second factor, the recovery codes go with it.

A delegated verification service

With verify-webhook, the engine never holds a code. The service makes it, sends it, and says whether the one typed is right. That keeps codes out of Signari's database and its logs. It also puts delivery where a provider's fraud and routing controls are.

The engine speaks one contract, version 1, to a service the administrator runs in front of whichever provider's verification API they use:

TextPOST {"version":1,"action":"start","to":"+447700900123"}     2xx, optionally {"id":"..."}   a code was sentPOST {"version":1,"action":"check","to":"+447700900123","id":"...","code":"123456"}     2xx {"approved":true}          the code is right; the service spends it     2xx {"approved":false}         it is not

A check carries to, id or both, as known. An organisation that keeps only hashes of numbers (below) sends the id alone. So a service that gives no id cannot serve it.

Anything else is an error. A check that errors is refused, not charged, so an outage of the service signs nobody in and disables nobody's factor.

Only a code of 4 to 10 digits is sent to the service. So an authenticator or recovery code tried first spends none of its checks.

The engine's own rules still apply on top: the countries, the daily allowances, the five-minute lifetime, five attempts per code and the consecutive-failure ceiling.

The service sends only codes, so account notices go by email alone, which signari doctor says. The URL must be https, as a check carries a live code.

Keeping only a hash of the number

By default, a person's number is stored. Then a code can be texted without being asked for, and account notices reach the phone. But a copy of the database then holds every person's number. That is where a "SIM swap" begins: somebody persuades a mobile provider to move the number to a SIM card they hold.

An organisation can instead keep only a keyed hash of each number:

Shellsignari instance sms-numbers -org <id> -sms-numbers hashed

The hash is made under the person's own subject key. That key is sealed under the root key, which is not in the database, so a copy of the database cannot test guesses. The same number in two accounts hashes differently. A root-key rotation leaves the hash as it was, and erasing the person destroys it.

What changes for the person: the code page asks for their number, and the code goes to the number typed when its hash matches. The page says the same whether it matched or not, because whoever is on that page has the password. Each try spends the code page's own budget, so nobody can try number after number.

No account notice is texted to a number that is not kept.

A number already stored is replaced by its hash at the person's next sign-in. That sign-in is still texted to the stored number.

Moving back to stored applies to numbers enrolled from then on. A hash cannot be read back, so it keeps working when typed, until the person enrols again.

Why it is offered at all

The National Institute of Standards and Technology (NIST) withdrew its recommendation of SMS for authentication in 2016. These are the weaknesses behind that:

  • SIM swap needs no technical exploit. Somebody persuades a mobile provider to move a number.
  • SS7 access, to the Signalling System No. 7 network that routes texts, is purchasable. That signalling network has weak authentication.
  • Forwarding to an email address is a checkbox in several mobile providers' portals.

Signari offers it because some people will enrol SMS and nothing else, and without it they would have no second factor. SMS still defeats credential stuffing, a common attack. "Credential stuffing" is trying passwords leaked from other sites.

Tokens and audit records name SMS

The amr value is sms, never otp. The session and the audit record both say so:

Textsession: acr=2  amr={pwd,sms}audit:   login.succeeded  {"acr": "2", "amr": ["pwd", "sms"]}

RFC 8176 defines both values. Recording a text message as otp would make it indistinguishable from an authenticator app in every token, every audit record and every policy decision.

Requiring a stronger factor

mfa: true accepts any second factor, including a text message. Two conditions exist for when that is not enough:

YAMLpolicies:  - name: finance-needs-a-security-key    when: {client: finance}    require: {phishing_resistant: true}    message: Finance requires a passkey or security key.  - name: admin-no-text-messages    when: {client: admin}    require: {factors_any_of: [otp, hwk]}

phishing_resistant is satisfied only by hwk, a hardware-backed credential bound to the origin by the browser.

It is not satisfied by otp. A one-time code is typed by a person into whatever page asked for it, including the attacker's, which is how real-time phishing works.

Nor is it satisfied by the generic mfa value. A provider asserting mfa has said several factors were used, and nothing about which.

For example, a session proved with pwd,sms gets these answers:

TextGET /oauth2/authorize?client_id=thirdparty…   400   "This application requires a passkey or security key."GET /oauth2/authorize?client_id=webapp…       303 → code issued

The second line shows that the same session still reaches an application with no such rule, so the policy is not denying everything.

Enrolment is two steps, and the second is not optional

A number is enrolled, a code is sent to it, and the factor counts only once that code comes back. After the person enters the number, the database holds it unverified:

Textdb: +447700900123 | verified=f     ← after entering the number    counts as a factor: f

If enrolling and trusting were one step, a typo would send a person's codes to a stranger's phone. They would find out only when they could not sign in.

Moving to another number works the same way. The new number is held as pending. The number that already works stays the factor, and keeps receiving sign-in codes, until a code sent to the new one comes back. Then the old number is texted to say codes will no longer come to it.

The send step used to overwrite the working number, and mark the factor unverified at once. So one request from any signed-in session switched SMS off for the account. It also aimed SMS at a number of that session's choosing, without a code being entered.

An enrolment code and a sign-in code are kept apart, and neither is accepted in place of the other.

Numbers are E.164 or refused

E.164 is the international form of a phone number: a +, then the country code, then the number. A number in any other form is refused with this message:

Textgive the number in international form, starting with a + and the country code(got "07700900123")

Signari does not guess a country code for a national-format number. A wrong guess would send the code to a number in another country, and the person would never receive it. The format is enforced in the database as well, because the engine is not the only thing that writes there.

Numbers are shown redacted, as ••• ••• 23. The last two digits let somebody recognise their own number. The whole number would tell anybody who has stolen a password which number to attack at the mobile provider.

Operational choices

These are the limits on an SMS code. Sign-ins over the Lightweight Directory Access Protocol (LDAP) and the Remote Authentication Dial-In User Service (RADIUS) take none, as the table says:

code lifetime5 minutes, shorter than email's ten, because a text arrives in seconds and sits on a lock screen
resend interval60s within one sign-in, because every message costs money. Another sign-in is texted a code of its own at once, within the daily allowances per number and per organisation
taken forthe sign-in, or the password reset, it was sent for, and no other: as for email codes. An LDAP bind, a RADIUS request and the desktop sign-in take none
attempts per code5
wrong codes in a row, across codes100, then the factor is switched off and the holder told, as an authenticator app is. No code is sent or accepted until a number is proved again. A right code resets the count
one live code"send another" replaces, never accumulates

A misconfigured gateway stops Signari at startup, rather than leaving SMS turned off:

Textsignari: configuring the SMS gateway: SIGNARI_SMS_GATEWAY must be twilio,webhook or verify-webhook (got "twilo")

If Signari ignored a typo in the gateway name, no code would be delivered until somebody noticed.

A plaintext webhook URL is refused, because the body carries a live one-time code.

The MFA gate checks every factor

HasSecondFactor is the single gate between a correct password and a session. A factor missing from it would not apply: the person would turn on multi-factor authentication (MFA), see it in their settings, and still sign in with a password alone.

HasSecondFactor consults every table that holds second-factor credentials, core.sms_otp_credentials among them. So a verified number makes the sign-in flow ask for a code, rather than signing the person in on a password alone.