Who should choose how a token gets checked: the server, or the token itself? With JWT, it's often the second. The token's header says "alg": "HS256", and a careless server (one that doesn't decide the algorithm itself) trusts it.
PASETO (Platform-Agnostic SEcurity TOkens) was made so that choice doesn't exist. PASETO is a token like a JWT, but without the choices that can be misused. Its version and purpose are written at the front of the token, and each version has exactly one algorithm. Picture an official school letter. A JWT is like a letter whose letterhead says "check it with the stamp written here", so the checker has to trust what the letter says about itself. PASETO is like a letter with a fixed letterhead: the receiving office accepts one kind of letterhead only, and has one way to check it. In this picture, the letter is the token, the letterhead is the prefix at the front of the token, the stamp is the algorithm, and the receiving office is the server.
Anatomy of a token
This is the token the Lab makes for Siti, valid for 15 minutes:
v4.public.eyJzdWIiOiIxIiwicm9sZSI6InN0dWRlbnQiLCJpc3MiOiJodHRwczovL3BvcnRhbC5zY2hvb2wudGVzdCIsImlhdCI6IjIwMjYtMTAtMDlUMDc6MDA6MDArMDc6MDAiLCJleHAiOiIyMDI2LTEwLTA5VDA3OjE1OjAwKzA3OjAwIn3YBAtjzhaZBalsxMbQsmVAIW6MOiM-q70WTPEXzhWYPjXoc_AH3fQ5i-039Sc1ePVE9b3aiTpLiVOH2wkStIAO
The token has three parts, separated by dots. Ed25519 in the table is a digital signature algorithm:
| Part | What it holds |
|---|---|
v4 |
the version. The version decides the algorithm, the token can't choose |
public |
the purpose: signed, its content is readable |
| the rest | base64url of the JSON message (131 bytes) followed directly by the Ed25519 signature (64 bytes) |
The message:
{"sub":"1","role":"student","iss":"https://portal.school.test","iat":"2026-10-09T07:00:00+07:00","exp":"2026-10-09T07:15:00+07:00"}
A small difference from JWT: in PASETO, iat and exp are ISO 8601 dates (a standard date format, such as 2026-10-09T07:15:00+07:00), not Unix seconds.
Why there is no alg header
Careless servers trust the alg in a JWT's header, and that's where famous bugs such as alg: none came from (none means no signature). The attack side is covered in the JWT Security lesson. PASETO removes the algorithm choice from the token. That's what opinionated means: the important decisions are already made by the specification (PASETO's official rules).
v4.publicis always Ed25519, a digital signature with a key pair: a private key to sign and a public key to check.v4.localis always XChaCha20 for encryption, plus BLAKE2b to make sure the content wasn't changed.
The server is set up with the rule "only accept v4.public with this public key". A token with any other prefix is refused before its content is read at all.
local and public
The table compares these two purposes. Symmetric means one key for both jobs, asymmetric means a key pair:
v4.local |
v4.public |
|
|---|---|---|
| Keys | 1 secret key to make and to check (symmetric) | a private key to sign, a public key to check (asymmetric) |
| Content | encrypted, the client can't read it | only signed, anyone can read it, nobody can change it |
| Fits | one app that makes and checks its own tokens | many services checking tokens from one login server |
So if someone else gets Siti's v4.public token, they can read what's inside, exactly like a JWT payload. Only local keeps the content secret.
Making and checking v4.public
Ed25519 is in the Web Crypto of modern browsers, so the Lab makes a real v4.public token. The signature isn't computed over the message alone but over its PAE (pre-authentication encoding). The PAE joins four pieces, each preceded by its length: the v4.public. prefix, the message, the footer (an extra note at the end of the token) and the implicit assertion (data that is signed but not sent). Here the footer and the implicit assertion are empty. Because the prefix is one of the joined pieces, a changed prefix makes the signature fail to match.
const enc = new TextEncoder();
const b64url = (bytes) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
function le64(n) { // a length as 8 little-endian bytes
const out = new Uint8Array(8);
for (let i = 0; i < 8; i++) { out[i] = n % 256; n = Math.floor(n / 256); }
return out;
}
function pae(...pieces) { // the number of pieces, then each piece's length + content
const parts = [le64(pieces.length)];
for (const piece of pieces) parts.push(le64(piece.length), piece);
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
let at = 0;
for (const p of parts) { out.set(p, at); at += p.length; }
return out;
}
async function signV4Public(claims, privateKey) {
const h = enc.encode("v4.public.");
const m = enc.encode(JSON.stringify(claims));
const empty = new Uint8Array(0); // empty footer and implicit assertion
const sig = new Uint8Array(await crypto.subtle.sign("Ed25519", privateKey, pae(h, m, empty, empty)));
const body = new Uint8Array(m.length + 64);
body.set(m);
body.set(sig, m.length);
return "v4.public." + b64url(body);
}
le64 writes each length as 8 bytes. signV4Public joins the message and the 64-byte signature, then writes the result as base64url after the prefix.
The server checks it in order, and refuses with 401 at the first step that fails:
- The token starts exactly with
v4.public., the only format the server accepts. - The last 64 bytes are the signature.
crypto.subtle.verify("Ed25519", publicKey, sig, pae(h, m, empty, empty))must betrue. expis later than the server clock.issequalshttps://portal.school.test.
v4.local needs XChaCha20 and BLAKE2b, which aren't in Web Crypto yet. That's why the Lab only models a local token (it imitates one with random bytes), and makes the public token for real.
In Laravel: what BelajarWeb.dev uses
The BelajarWeb.dev API (the server that answers its app's requests) uses PASETO v4.local with the paragonie/paseto library, because the same app makes and checks its tokens. A short version of its PasetoService:
$key = new SymmetricKey(base64_decode(config('auth.paseto.key')), new Version4);
$token = (new Builder)
->setKey($key)
->setVersion(new Version4)
->setPurpose(Purpose::local())
->setIssuedAt(now()->toDateTimeImmutable())
->setExpiration(now()->addDays(90)->toDateTimeImmutable())
->setIssuer(config('app.url'))
->setSubject((string) $user->id)
->setClaims(['jti' => $tokenId])
->toString(); // "v4.local...."
$claims = Parser::getLocal($key, ProtocolCollection::v4())
->addRule(new IssuedBy(config('app.url')))
->parse($incoming) // throws when broken, expired, or from another issuer
->getClaims();
- The key comes from the environment (
PASETO_KEY, a server setting outside the code), never written in the code. Buildermakes the token, andParserreads and checks it.Parseralready checksexpby itself, so no manual check is needed.- The
jti(a unique token id) is stored in theapi_tokenstable. Logging out deletes its row, so the token stops working at once even though itsexpis far away. The result: a stateless token (one that can be checked without looking anything up in a store) plus a list of live tokens, so it can be revoked at any time. - It is valid for 90 days. In its last 7 days it is renewed automatically: the server sends a new token in an
X-New-Tokenheader.
PASETO or JWT?
- You hold both sides, the side that makes tokens and the side that checks them (an internal API, your own mobile app, a small team, no third-party login): PASETO. Less to misconfigure.
- You must talk to other systems: Google login or SSO (single sign-on, one login for many apps) through OpenID Connect, whose ID tokens are JWTs, or a partner whose library only knows JWT: JWT.
PASETO is not an RFC standard. Its specification lives at paseto.io, and it has fewer libraries than JWT.
⚠️ What can still go wrong, opinionated or not
- Thinking
publiccontent is encrypted. Onlylocalis encrypted. The message in apublictoken must hold no secrets. - Sharing the
localkey with services that only need to check. Whoever holds that key can also make tokens. Usepublic, and share only the public key. - Accepting several versions "for compatibility". That brings the algorithm-choice problem back. Accept one version and one purpose.
- Forgetting that a stateless token can't be revoked. Store the
jtias BelajarWeb.dev does, or keep the life short.
TL;DR: PASETO is a token like a JWT, shaped version.purpose.content (the purpose is what the token is for): one algorithm per version and no alg header. v4.local uses one secret key and encrypts its content; v4.public is signed with Ed25519 (a signature made with a private key), readable by anyone, and checked with a public key. The server accepts one format only, checks the signature over the PAE (the prefix and the message joined together), then exp (an ISO date) and iss (the issuer). Pick PASETO when you hold both sides (the token maker and the checker), JWT when you must talk to other systems. BelajarWeb.dev uses v4.local plus a jti (unique token id) table so logout revokes a token at once.
⚡ The version decides the algorithm
Meaning: A PASETO token starts with its version and purpose, such as v4.public.. Each version has exactly one algorithm, and there is no alg header as in a JWT, so the token can't choose how it is checked. That's what opinionated means: there is no algorithm choice to misuse, because the specification (PASETO's official rules) already made the decision.
⚡ local or public
Guess first: v4.public is only signed, not encrypted. Someone else gets Siti's v4.public token. Can they read what's inside?
Yes, exactly like a JWT payload (its content part). public is only signed (Ed25519): anyone can read it, but nobody can change it. Only local encrypts its content.
Meaning: v4.local uses one secret key to make and to check tokens. v4.public is signed with a private key (held by the token maker) and checked with a public key (anyone may hold it).
⚡ What Siti's token holds
Write:
{"sub":"1","role":"student","iss":"https://portal.school.test","iat":"2026-10-09T07:00:00+07:00","exp":"2026-10-09T07:15:00+07:00"}
Meaning: This is the JSON message inside Siti's v4.public token. In PASETO, iat (when it was made) and exp (when it ends) are ISO 8601 dates, not Unix seconds. The server checks in order: the v4.public. prefix, the signature over the PAE (the prefix and the message joined together), exp, then iss (the issuer). As soon as one fails, the answer is 401.
⚡ PASETO or JWT
Meaning: When you hold both sides, the side that makes tokens and the side that checks them (an internal API, your own mobile app), pick PASETO: less to misconfigure. When you must talk to other systems, such as Google login or SSO (one login for many apps), use JWT.