liveBook · Manning

Magic link

As explained in Software Security for Developers

Magic link authentication verifies a user's identity through a login link delivered to a previously associated email address instead of a memorized password.

Magic link authentication lets a user sign in without a memorized password: the application sends a unique, short-lived login link to the user’s email address, then creates a session after validating the link. section 14.0 section 14.1

A secure login flow follows these steps:

  • Accept the user’s email address and return a generic response such as “If an account exists, we’ve sent a login link,” without revealing whether the address is registered. section 14.1 section 14.3
  • Generate a unique, cryptographically signed token containing an expiration time and a nonce, and attach it to the login link. section 14.1
  • Send the link by email, validate the token and its expiration when clicked, then establish a secure session. section 14.1

Reduce the main failure modes by:

  • Making tokens expire quickly, storing them in a database or cache, and invalidating them after use to limit replay and support revocation. section 14.3
  • Using recognizable emails, avoiding plaintext links, and limiting link requests to reduce phishing, exposure, and automated abuse. section 14.3

A passwordless login

Alice enters her email address on ACME’s login page. An email arrives with a button to log in. After she clicks it, the application validates the short-lived token and admits her without asking for a password. section 14.1

Figure 14.1 Authenticating through magic links. At the user’s request, the app generates a unique link and sends it to the user by email. The user clicks the link to authenticate.
figure

Trace the complete magic-link authentication sequence from the user’s request through email delivery and link-based authentication. section 14.1

How Software Security for Developers covers it

How deep it goes
Explains the request, token, email, validation, session, enumeration, replay, phishing, and storage safeguards without protocol internals.
Examples
Uses Alice’s ACME login, signed-token claims, a sample authentication URL, best-practice guidance, and review questions.
What it assumes
Assumes basic login and email concepts while teaching the authentication sequence and its security risks from zero.
What you can do after
Operate/configure a safer magic-link flow with generic responses, signed short-lived tokens, storage, single use, and request limits.
How it connects
Connects passwordless authentication with email enumeration, phishing, replay attacks, token storage, and one-time passwords.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Security for Developers. The section links point to the parts of the book it draws on.