Front-end15 min read
How to share passwords securely: inside Yush
Why sending passwords and tokens in chat is risky, and how Yush, the app I built, encrypts it all in the browser: key after the #, AES-GCM, HKDF, self-destructing links.

Every team has this moment: someone needs the staging database password, an API key or a service token, and it ends up in Slack, WhatsApp or Teams. It solves the problem right away. And it stays there forever.
I built Yush for that moment. You paste the secret, get a link, send the link. The person on the other end clicks, the secret goes straight to their clipboard and the link dies. And the most important part: the Yush server never sees the secret, not even for a second.
In this post I show the app in action and explain, with the real code, how that's possible using only what the browser already has.
TL;DR#
- A password sent over chat turns into copies in a lot of places: the app's server, backups, notifications, history. And it never expires.
- In Yush, everything is encrypted in the browser with the Web Crypto API: AES-GCM-256, HKDF-SHA256 and, with an extra passphrase, PBKDF2 with 600 thousand iterations.
- The key lives after the
#in the link. The browser never sends that part of the URL in an HTTP request. - The server only stores the ciphertext, metadata and the hashes of two proofs (
linkProofandaccessProof). - Opening the link doesn't use up a view. Using one takes a
POST, a click and proof of the key, so the WhatsApp preview bot can't burn the secret. - The secret goes straight to the clipboard and is never drawn on the screen.
- It's not magic: whoever has the full link has the secret, and malware on the recipient's computer is still malware.
Why sending passwords over chat is a problem#
The problem isn't that chat is insecure. Many apps encrypt messages in transit. The problem is that the message doesn't go away. A password sent over chat turns into several copies, each with a life of its own:
- The app's server stores the message. If the chat doesn't have end-to-end encryption (Slack and Teams, for example), the service itself can read it and, depending on the plan, whoever administers the workspace can export it.
- The backup of your phone or cloud takes the conversation along with it.
- The notification shows the password on the lock screen, to whoever is standing next to you.
- History and search find the password months later. So does anyone who breaks into the account.
- Whoever joins the group later can often see the history.
- One screenshot and the password becomes an image, beyond anyone's control.
And almost nobody goes back to delete it. The staging database password from 2024 is still sitting in the #dev channel.
The idea of a single-use link fixes this: what stays in the chat is a dead link. Once the person has copied it, or once it expires, there's nothing left to find.
Yush in 30 seconds#
On the sender's side, it's a text field and three choices: how long the secret lives (from 1 hour to 30 days), how many times it can be copied (1, 5, 10 or 25) and the extra options.
You hit send, the browser encrypts everything and hands back the link. The link is hidden by default (again: so it doesn't end up in a screenshot), and you can reveal it with the eye icon:
Take a look at the link. It has two parts, and the difference between them is the heart of the app:
http://localhost:5173/s/317yFlKeQyqSttkkk45_hoqM#k=Tupf9Ege-5H227VRp0wy72E2MPU_SOv_KjX5wUyTAuA
└── secret id ─────────┘ └── key (32 bytes) ────────────────────────┘The rest of this post is about how those two parts work together.
The server doesn't know the secret#
Yush's rule number one: the plaintext and the key exist only in the browser. The server stores the ciphertext, metadata that reveals nothing, and the hashes of two proofs.
This is the request the browser sends when you create a secret (I shortened the values):
{
"ciphertext": "7TK66-zY5asPtCEXK--_DvCGJeLLwMdJy8oDL_91zke820rv-5oncBwgtUihGL...",
"iv": "gH3tupn6kX87cn32",
"kdf": null,
"linkProof": "bPi5MXkmB3C6Ql2_YC1mRfmUZRg8-74maec5w-XuacM",
"accessProof": "ygxSepD_0Ut2_37sww4y...",
"expiresIn": 604800,
"maxViews": 1,
"allowImmediateDeletion": true,
"requireConfirmation": true
}No secret, no key. And the server even swaps the proofs for their SHA-256 before saving them. Not even the database has the original proofs.
On the other side, the server log doesn't keep anything sensitive either: just the method, the route pattern, the status and the timing. A line looks like this:
{"method":"POST","route":"/api/secrets/:id/consume","statusCode":200,"ms":1,"msg":"request completed"}The key lives after the ##
This is the most elegant part, and it's plain web standard: the URL fragment (everything after the #) isn't sent in HTTP requests. RFC 3986 defines the fragment as something handled only by whoever has the page open. The browser asks the server for /s/317yFl... and keeps the #k=... to itself.
In the code, building the link takes one line:
// https://host/s/{id}#k={key}: the key lives in the fragment, which browsers never send to servers
export function buildSecretLink(origin: string, id: string, linkKey: Uint8Array): string {
if (!SECRET_ID_PATTERN.test(id)) throw new RangeError('Invalid secret id');
return `${origin}/s/${id}#${encodeKeyForURL(linkKey)}`;
}The key is 32 random bytes from crypto.getRandomValues, in base64url. The id is something else: 18 random bytes (144 bits), generated by the server. Guessing an id isn't feasible, and even if you got one right it wouldn't help, as you'll see with the proofs.
One more precaution: when the link opens, Yush removes the #k= from the address bar with history.replaceState. That way the key isn't visible to whoever walks behind you, and it doesn't come back when tabs are restored. The trade-off is that reloading the page means opening the original link again.
One key, three derivations#
With the 32 bytes of the key in hand, Yush doesn't use it directly to encrypt. It derives three different values with HKDF-SHA256, changing only a label (the info) for each one:
encKey: the 256-bit AES-GCM key that encrypts the secret. It's created as non-extractable: not even the page's own JavaScript can read its bytes.linkProof: the proof that "I have the link". It's derived from the link key alone.accessProof: the proof that "I have the link and the extra passphrase" (when there is one).
This is the snippet that does it:
export async function deriveSecretKeys(linkKey: Bytes, passphrase: PassphraseInput | null): Promise<SecretKeys> {
const linkBase = await hkdfBase(linkKey);
const linkProof = await hkdfBits(linkBase, INFO_LINK_PROOF); // "yush/v1/link-proof"
let ikm: Bytes = linkKey;
if (passphrase) {
const stretched = await pbkdf2(passphrase); // PBKDF2-SHA256, 600k iterations
ikm = new Uint8Array(KEY_BYTES * 2);
ikm.set(linkKey, 0);
ikm.set(stretched, KEY_BYTES);
stretched.fill(0); // wipe the intermediate bytes
}
const base = passphrase ? await hkdfBase(ikm) : linkBase;
const encryptionKey = await crypto.subtle.deriveKey(
{ name: 'HKDF', hash: 'SHA-256', salt: HKDF_SALT, info: INFO_ENCRYPTION_KEY },
base,
{ name: 'AES-GCM', length: 256 },
false, // non-extractable
['encrypt', 'decrypt'],
);
const accessProof = await hkdfBits(base, INFO_ACCESS_PROOF);
return { encryptionKey, linkProof, accessProof };
}(I trimmed it to fit: the real file also checks the key length and has a try/finally that wipes the ikm.)
The extra passphrase#
The extra passphrase is optional and covers one specific case: the link leaking. If you send the link by email and the passphrase over the phone, whoever grabs only the link can't copy anything.
Human passwords are weak, so it goes through PBKDF2-SHA256 with 600 thousand iterations and a random 16-byte salt. That's the number OWASP recommends for PBKDF2 with SHA-256. Before that, the passphrase is normalized to NFC, so that an "ã" typed on a Mac and on Windows gives the same bytes.
Why two proofs#
This is the design decision I like the most. The proofs stop three attacks at once:
- Someone who only knows the id (from a proxy log, a truncated history) can't download the ciphertext, can't burn the secret and can't delete it: they're missing the
linkProof, which depends on a 256-bit key. - A wrong extra passphrase is caught before the view is used up. The
accessProofdoesn't match, the server responds with 403 and counts the attempt. After 10 failures, the secret self-destructs. - A leaked database is useless: it only has hashes of the proofs (you can't recreate the proofs from them) and it doesn't have the key (you can't attack the passphrase offline).
Encrypting and hiding the size#
The cipher is AES-GCM, with a random 12-byte IV per secret and a fixed piece of associated data (yush/v1). Besides encrypting, GCM authenticates: if someone changes a single byte of the ciphertext, decryption fails instead of returning garbage.
But encryption doesn't hide the size. An 8-character password and a 3,000-character private key would produce ciphertexts of very different sizes. That's why Yush puts the secret inside a fixed-size frame before encrypting it:
frame = u32be(length) ‖ utf8(plaintext) ‖ zeros up to the next power of 2 (min. 256, max. 32,768 bytes)The sample secret in the screenshots, STRIPE_KEY=sk_test_exemplo_nao_e_real_51Hx9, has 43 characters. Its ciphertext is 272 bytes: the minimum 256-byte frame plus the 16 bytes of the GCM tag. An 8-character password would come out at exactly the same size.
Opening the link costs nothing#
Here's a problem few people think about: bots open links. WhatsApp, Slack, Discord and Telegram visit the link to build the preview. Email antivirus scanners do too. If opening the link used up the view, a single-use secret would die before it ever reached the person.
So, in Yush, opening and consuming are separate things:
- The page (
GET /s/:id) is just the app's HTML. It doesn't even touch the database. - The status (
GET /api/secrets/:id/status) only reads: expiration, remaining views and whether a passphrase is required. - Consuming (
POST /api/secrets/:id/consume) is the only step that uses a view, and it requires both proofs in the body. It only runs after a click.
There's still one case left: a scanner that runs JavaScript and clicks. For that one there's the confirmation step option, which asks for a second click before copying:
On the server, consuming is atomic: in SQLite with BEGIN IMMEDIATE, in Postgres with SELECT ... FOR UPDATE. Two people clicking a single-use secret at the same time don't both get it. I covered this with a 12-thread test on SQLite and another with a pool of 30 connections on Postgres. And on the last view the row is deleted in the same transaction: not even the record that it existed is left behind.
Straight to the clipboard, never on screen#
The secret is never drawn on the screen. Not in React state, not in a hidden <input>, not through text selection. It goes from the decryption result straight to the clipboard.
There's a browser detail here. Safari only lets you write to the clipboard if the call starts inside the click, before any await. But the secret hasn't even arrived yet: it still has to be fetched and decrypted. The way out is ClipboardItem, which accepts a Promise:
export async function writeSecretToClipboard(text: Promise<string>): Promise<void> {
if (!isClipboardAvailable()) throw new ClipboardUnavailableError();
if (typeof ClipboardItem === 'function' && typeof navigator.clipboard.write === 'function') {
try {
const blob = text.then((value) => new Blob([value], { type: 'text/plain' }));
await navigator.clipboard.write([new ClipboardItem({ 'text/plain': blob })]);
return;
} catch {
await text; // surface the real failure (wrong passphrase, unavailable secret)
}
}
await navigator.clipboard.writeText(await text);
}(I simplified it: in the app, the clipboard environment is injected so it can be tested.)
The page calls this synchronously on click, passing in the Promise that fetches and decrypts. Safari sees the click, and the rest arrives later. In other browsers, writeText does the job.
And there are two more safeguards I find really nice:
- The clipboard is checked before using up a view. If the browser can't copy, the secret isn't consumed.
- If the browser denies the copy after consuming, the app keeps only the ciphertext in memory for 2 minutes, for another click, without using up another view.
To make sure of it, there's a test that watches every DOM change with a MutationObserver during the copy.
Opening the same link again, this is what shows up:
The "we never say why" is on purpose: the server returns the same 404 for an id that doesn't exist, that expired, that was consumed, that's malformed or that came with the wrong proof. Anyone trying to guess learns nothing from the response.
The server defends itself too#
Even without seeing the secret, the server has work to do:
- The schema rejects any extra field. If the creation request arrives with an extra
"plaintext"in the JSON, the response is400 Invalid request.. That way, a bug that sends the secret by mistake never gets to store anything. - Rate limiting per IP on every route.
- Strict headers: CSP with
script-src 'self'and Trusted Types,frame-ancestors 'none',Referrer-Policy: no-referrerandCache-Control: no-store. The build has no inline or third-party scripts. No analytics. - A database that really cleans up: in SQLite,
secure_deletezeroes out deleted pages. Expired secrets are never returned and get removed periodically.
What Yush doesn't solve#
Every security app should say what it doesn't protect. These are Yush's limits:
- The link is the credential. Whoever has the full link copies the secret. For extra protection, use the extra passphrase and send it through a different channel.
- The recipient's device. Malware, a malicious extension or a clipboard manager are out of reach for any web app.
- An actively malicious server could serve modified JavaScript that sends the key away. That's the limit of every end-to-end encryption app delivered over the web. You can reduce it with reproducible builds and published file hashes.
- JavaScript strings can't be zeroed out. The byte buffers are wiped, but the decrypted text is an immutable string, and it's the garbage collector that removes it from memory.
And a few trade-offs I chose on purpose:
- Rate limiting is in memory, per instance. On Vercel, each function instance has its own. For a global limit, you'd need Redis or the Vercel firewall. The real protection comes from the entropy of the id and the proofs.
- Anyone with the link can delete the secret (if the option is on), including the recipient. There are no accounts, so there's no "owner".
- The status shows how many views are left to anyone with the id. It doesn't reveal content, but it is information.
What I learned#
The web already has what it needs. Yush doesn't use any cryptography library: it's all crypto.subtle. AES-GCM, HKDF, PBKDF2 and non-extractable keys are in every modern browser.
The # is a free private channel. Knowing that the fragment doesn't go to the server changes the whole design: you can deliver the key along with the link without the server seeing it.
Think about the bots. The most likely attack on a single-use link isn't a hacker, it's the WhatsApp preview. Separating "open" from "consume" was the decision that made the app work in the real world.
Not showing is also an interface choice. Sending it straight to the clipboard keeps the secret off the screen, out of screenshots and away from extensions that read the page. And it took more work than it looks, because of Safari.
Write down what you don't protect. Writing down the list of limitations forced me to think through every attack and decide: do I mitigate it, or do I accept it and warn people?
References#
- Yush, the app from this post
- MDN: Web Crypto API and SubtleCrypto.deriveKey
- RFC 5869: HKDF
- RFC 3986, section 3.5: the URL fragment
- OWASP: Password Storage Cheat Sheet (PBKDF2 iterations)
- MDN: ClipboardItem
- MDN: Trusted Types API
Read next

Front-end16 min read
Multilingual SEO in React: hreflang, prerendering, sitemap

Front-end15 min read
How I make AI videos with Remotion: a real case study

Front-end13 min read
Vite 8 vs Vite 7 with Rolldown: I benchmarked my build