Skip to content
Sniptide

Engineering8 min read

Designing short, unguessable share links

An 8-character link has 46.7 bits of randomness. That is plenty against collisions and too little to be the only secret, so we put the secret somewhere else.

How many characters does a share link need before nobody can guess it? Sniptide's generated links are 8 characters long, such as sniptide.com/Ab3xY9qr. That gives about 111 trillion possible links, which sounds like a lot until you do the math for someone scanning for any live paste instead of one particular paste. This post walks through how we generate the link, the collision and guessing numbers, and why we decided the link is an address and the secret has to live somewhere else.

A paste's link is a random string from a 57-character alphabet. It's the 26 uppercase and 26 lowercase letters and the digits, minus the characters people misread when they copy a link off a screen: I, O, l, 0 and 1.

apps/web/lib/pastes/links.ts
export function randomSlug() {
  const alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"
  const length = 8
  const bytes = new Uint8Array(length * 2)
  // Each character gets the same number of possible bytes; discard the uneven tail.
  const ceiling = 256 - (256 % alphabet.length)
  let slug = ""
  while (slug.length < length) {
    crypto.getRandomValues(bytes)
    for (const byte of bytes) {
      if (byte >= ceiling) continue
      slug += alphabet[byte % alphabet.length]
      if (slug.length === length) break
    }
  }
  return slug
}

Two details matter here. The bytes come from crypto.getRandomValues, a cryptographically secure generator, because Math.random() is predictable once you've seen enough of its output. And the loop throws away bytes from 228 to 255. A byte has 256 values, which doesn't divide evenly by 57, so a plain byte % 57 would make the first 28 characters of the alphabet slightly more likely than the rest. Rejecting the top 28 values discards about 11% of bytes and leaves every character exactly equally likely. Drawing 16 bytes for 8 characters means one call almost always fills the link.

Creating a paste then checks the database for the new link and draws again if it's taken. Two requests can still pick the same unused link at the same moment, so the paste_slug_unique index on the column is what finally guarantees one paste per link. The second insert fails instead of overwriting the first.

Collisions are a solved problem

Eight characters from 57 gives 57⁸, about 1.11 × 10¹⁴ links, which is 46.7 bits of randomness. The chance that a new link lands on an existing one is the number of live pastes divided by that space:

Live pastes
Chance a new link is taken
100,000
1 in 1.1 billion
1,000,000
1 in 111 million
10,000,000
1 in 11 million

The birthday bound says that somewhere across all links ever drawn, a collision becomes likely (50%) after about 12.4 million pastes. That sounds alarming, but it only means one creation, somewhere, takes a second database lookup. The retry loop exists for exactly that case. Collisions decide whether the link works, and at this length the answer is yes.

Guessing is the number that matters

An attacker doesn't have to guess one particular link. They have to find any live link, and every live paste makes that easier. With n live pastes and g guesses, the expected number of hits is g × n / 57⁸.

Unlisted is the default visibility for pastes made in the editor, so assume a million live unlisted pastes and a scanner that makes 1,000 requests a second:

Link at 1,000 guesses a second, 1,000,000 live pastes
Time to find one paste
8 characters from 57 (46.7 bits)
About 31 hours
10 characters from 57 (58.3 bits)
About 11 years
22 base64url characters (132 bits)
Longer than the age of the universe

At 8 characters, a patient scanner finds a real paste every day or two. This is the honest result of the design, and it's why our sharing docs say that with an unlisted paste the link itself is the secret, so don't rely on it to protect anything sensitive.

The obvious fix is a longer link. Sniptide already does that where the link is the only thing protecting something: a secret share for an env group uses 32 random bytes, a 43-character token, and still asks for a password on top.

For pastes we kept 8 characters, and that choice gives something up. A paste link gets pasted into chat, read off a screen in a meeting, dropped into a commit message or typed from a phone, and sniptide.com/Ab3xY9qr survives all of those. A 43-character token doesn't fit in a sentence anymore. The price is that an unlisted link resists a targeted guess and does not resist a broad scan. Ten characters would buy a factor of 3,249 and make the link a little worse to read, and it would still be a weak secret next to a real key. We'd rather keep the link short and move the secret out of it completely.

Where the secret actually lives

The path finds a paste, and only the fragment can open an encrypted one. Illustration.

Sniptide has four places to put the secret, and each one changes what a scanner gets for a hit.

  • Private pastes look missing. A private paste answers a stranger with the same "not found" page as a link that never existed (canOpenLink returns missing for both). A scanner can't learn that a private paste is there, let alone read it.
  • Passwords are rate-limited. A password paste shows an unlock form, so a scanner learns the link is live. Guessing the password is capped at 8 attempts per visitor per paste every 15 minutes, and 60 attempts per paste per hour from everyone together. Each attempt counts before the password is checked, so parallel requests can't slip past the limit.
  • End-to-end encryption puts a 256-bit key in the fragment. The browser generates a random 32-byte key, encrypts the files with AES-256-GCM using a key derived from it with HKDF, and puts the key after the # in the link. The server stores ciphertext and a public key id. A scanner who finds sniptide.com/Ab3xY9qr gets the envelope and a "Key needed" page, and now has to guess 256 bits instead of 46.7.
  • Burn after read limits the damage to one read. A burn-after-read paste is deleted the first time someone reveals it, and the owner gets a notification that it was read.

The encrypted case is the one that changes the math. The link's 46.7 bits only decide which ciphertext you download, and the key's 256 bits decide whether you can read it.

Paste a link into Slack, Discord or iMessage and a bot fetches it before any person clicks. For most pages that's harmless, but for a one-time link it's a real failure: the bot would use up the only read.

Sniptide splits a burn-after-read paste into two steps. Opening the link with a GET shows a sealed page that says the paste can be read once. Only an explicit POST from the reveal button claims the paste, inside a row lock so two readers can't both win. Unfurlers make GET requests, so they see the sealed page and nothing burns. For an encrypted burn-after-read paste, the page also checks that the reader has the right key before spending the read, so a link with a missing key doesn't destroy the paste.

Previews also decide what leaves the server. A public or unlisted paste without a password, burn after read or encryption gets an Open Graph card that shows its first lines. That's useful in a team channel and surprising if the paste holds something you didn't mean to post, which is why the docs suggest making a paste private before posting its link if its first lines shouldn't appear in the chat. Crawlers, unfurlers, uptime monitors and prefetches are also left out of view counts, so the numbers show people who read the paste.

The key stays out of logs and referrers

A link leaks in more places than the chat you send it to. The path, /Ab3xY9qr, is part of every request, so it ends up in our access logs, in any proxy in between, and in the browser's history. That's acceptable only because the path is an address.

The fragment behaves differently. Browsers never send the part after # to a server and never include it in the Referer header, so the encryption key stays out of requests and logs. Sniptide's own analytics drop it too. Three other choices keep the path from spreading further:

  • Pages send Referrer-Policy: strict-origin-when-cross-origin, so clicking an outside link from a paste tells the other site sniptide.com and nothing more. The env secrets pages go further and send no-referrer.
  • When a reader arrives from another site, the analytics keep only the referring host and drop its path and query, since those can carry tokens of their own.
  • A reader's share page never stores the key. Only the owner's own screens keep it in the browser's storage, so they can reopen the paste from their lists.

The fragment still sits in the address bar and in browser history, and anything that syncs history, such as a signed-in browser profile, syncs the key with it. Encryption keeps the paste from the server, and keeping the link out of the wrong hands is still up to whoever holds it.

What this design doesn't cover

  • Unlisted pastes can be found by scanning. The numbers above are the whole story. Use private for anything only named people should see, and encryption for anything the server shouldn't see either.
  • An encrypted paste's title is readable. The title stays outside the envelope so lists and search work, and a chat app that unfurls the link still shows it. Keep secrets out of titles.
  • Custom links are guessable on purpose. A link like sniptide.com/@dino/deploy is chosen to be memorable, so it should never be the only thing protecting a paste.
  • A leaked link can't be swapped for a new one. Sniptide has no action that replaces a generated link with a fresh random one. Today the fix for a leaked unlisted link is to make the paste private or delete it.

If you're designing share links of your own, the order we'd suggest is the one above. Pick the link length for collisions and readability, then decide which secret actually protects the content, and give that secret 128 bits or more, a rate limit, or both.

Sources

Checked on 29 November 2026 against Sniptide's code. The probabilities are computed from the alphabet and length the generator uses, not measured.

Pick where your library lives.

Use sniptide.com

Save your first pattern in the app, then connect Claude Code, Cursor or Codex with one sign-in in the browser.

Run it on your own server

One image and a database give you the app, the API and the MCP endpoint. Sniptide is open source under AGPL-3.0.

$docker compose up -d