How it works
The gate lives in your server. PreviewLatch decides whether a password is good; your server does everything else.
Before anything is sent
The middleware runs in your site's own server before any response is produced. A visitor without a valid session gets a 401, and nothing from your site:
- A normal page visit gets the login screen, at the same address (no redirect). The response is the same for every path, whether or not the page exists.
- Everything else, such as built files, images, API calls, prefetch and data requests, and other methods, gets a short plain text
401. - Every one of these responses tells search engines not to index it, and is marked not to be cached.
robots.txtgets the same401, because aDisallowwould stop crawlers from ever seeing that signal.
The login screen is one self-contained page with no scripts and no outside requests. It never shows your site's name, address, title or content. It says "This site is private.", asks for a password, and has a small "Protected by PreviewLatch" line.
Signing in
- The visitor types a password. The form posts to a reserved path on your own domain,
/_previewlatch/login. Their browser never talks to PreviewLatch. - Your server checks that the form came from your own site, then asks PreviewLatch, server to server, whether the password is good.
- If it is, your server creates the session cookie and sends the visitor back to the page they asked for. If not, they see one generic error, whatever the reason: wrong, expired, used or revoked.
Failed attempts are limited per site and per address: 10 per address and 200 per site in each 10 minute window. Over the limit, the password is not even checked.
The cookie
The session cookie is signed by your server with a key derived from your site key. That signing key never leaves your server, and PreviewLatch never has it. The cookie holds a session id, the site, a role, and times. No name, no email, nothing personal.
It is HttpOnly and SameSite=Lax. On HTTPS it is called __Host-pl_session and marked Secure; on plain HTTP during local development it is pl_session.
Every request is checked against the cookie locally, with no network call. The cookie also carries a "check again at" time. Once that passes, the middleware asks PreviewLatch whether the session is still good and, if it is, signs a fresh cookie. That recheck is how revocation reaches your site.
Revocation
Revoking a session, a password or a person, or signing everyone out, takes effect within the site's recheck interval: 60 seconds by default, provided your site's server can reach PreviewLatch. You can set the interval per site from 15 seconds to 15 minutes. Shorter means faster revocation and a few more checks.
When a password expires it stops working for sign in, and sessions made with it end too. A one-time password works for exactly one sign in, even if two people try it at the same moment.
If PreviewLatch is down
If PreviewLatch cannot be reached (a network error, a timeout, a server error, or rate limiting), people who are already signed in keep working. A session keeps working until its own expiry or until it has gone offlineGraceSeconds without a successful check, whichever comes first. The default grace is 24 hours. Setting it to 0 locks people out on the first failed check.
New sign ins need PreviewLatch. While it is down, the login screen says sign in is unavailable.
A definite "no" from PreviewLatch, such as a revoked session or a key that is no longer valid, ends the session at once. Only "could not get an answer" counts as an outage.
There is no uptime guarantee. We will publish measured uptime.
What PreviewLatch stores
- For your site key: its id and a hash of the half used to call the API. Not the half that signs cookies.
- For each password: a keyed hash. The password itself is shown to you once and never stored or logged.
- For each sign in: the session, when it was last seen, a hash of the address, the browser's user agent, and the host name it was made on.
So a leak of the PreviewLatch database gives no working keys and no working passwords. Your site's name stays in the dashboard; it is never sent to the login screen.
What is trusted
- Your site's server and its environment variables.
- PreviewLatch, for sign in decisions. A fully compromised PreviewLatch could approve a sign in. It could not read your site's content or forge a cookie without going through sign in.
- Your platform's client address header, for the per-address limit. See what it does not protect.
Signing out
/_previewlatch/ on your site shows a sign out button to anyone signed in. Signing out clears the cookie and tells PreviewLatch to end the session.