Send Passwords Securely with One-Time Secret Links
Resumo
Pixel shares a guide to sending passwords through one-time secret links instead of leaving them in chat history. It explains browser-side AES-GCM encryption, how URL fragments keep keys out of server requests, and why expiration and link handling matter for safer sharing.
DEV Community
How to Send a Password Without Leaving It in Your Chat History
You need to give a coworker the Wi-Fi password, or a family member the login for a shared account. The fastest way is to paste it into a chat. The trouble is that chat messages are built to last. They sync to every device you're signed in on, they get backed up, they show up in search, and they're still there years later when someone borrows your laptop or a backup leaks. A password pasted into a chat lives as long as the chat does. This post walks through a simple fix, the one-time secret link: how it works, the browser crypto that makes it possible, and the limits worth knowing before you rely on it. The idea: a link that works once A one-time secret link (also called burn-after-reading) turns a piece of text into a link that the recipient can open exactly once. After that it's destroyed, and if nobody opens it before it expires, it's destroyed too. What's left in the chat history is a dead link. Anyone scrolling back later finds a link that no longer opens anything. Plenty of tools offer this. The interesting part is how you build one so that the service in the middle can't read the secret either. How it works under the hood A good design has four pieces. 1. Encrypt in the browser, before anything is uploaded The sender's browser generates a random key and encrypts the text locally, using AES-GCM via the Web Crypto API. Only the encrypted bytes (the ciphertext) go to the server. 2. Put the key in the URL fragment The key goes into the link, after the #: https://example.com/s/abc123#k=Q3VyaW91cyBhcmVuJ3QgeW91
The part after # is the fragment. Browsers don't send the fragment to the server when they request the page, and they leave it out of the Referer header too. So the server stores ciphertext it has no key for, and the key travels only inside the link you send. The fragment does stay in the browser's address bar and history, and in the chat as part of the link. That's exactly the copy that goes dead once the secret is burned. 3. Burn on read, and expire When the recipient opens the link, the server hands over the ciphertext once and deletes it. If the link is never opened, a timer deletes it anyway. 4. Don't burn on page load Chat apps often fetch a link in the background to build a preview card. If merely loading the page reveals and burns the secret, a preview bot can use up the one view before your recipient ever sees it. The fix is to load the page with zero requests to the secret, and fetch the ciphertext only when a person presses an "open" button. A minimal sketch in JavaScript Here's the core of both sides using the Web Crypto API. upload and fetchAndBurn stand in for your own server calls. // helpers: bytes <-> URL-safe base64
const toB64Url = (bytes) =>
btoa(String.fromCharCode(...bytes)).replace(/+/g, "-").replace(/\//g, "").replace(/=+$/, "");
const fromB64Url = (s) =>
Uint8Array.from(atob(s.replace(/-/g, "+").replace(//g, "/")), (c) => c.charCodeAt(0));
// Sender: encrypt locally, upload only ciphertext, keep the key for the link
async function createLink(secret) {
const key = await crypto.subtle.generateKey({ name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, new TextEncoder().encode(secret));
const rawKey = new Uint8Array(await crypto.subtle.exportKey("raw", key));
const id = await upload(iv, new Uint8Array(ciphertext)); // server sees iv + ciphertext only
return https://example.com/s/${id}#k=${toB64Url(rawKey)};
}
// Recipient: runs only after the person clicks "open"
async function openLink(id) {
// base64url has no & or =, so URLSearchParams can parse the fragment safely
const k = new URLSearchParams(location.hash.slice(1)).get("k");
const key = await crypto.subtle.importKey("raw", fromB64Url(k), "AES-GCM", false, ["decrypt"]);
const { iv, ciphertext } = await fetchAndBurn(id); // server returns once, then deletes
const plain...

Powered by Readybot.io