Saving a paste, and sharing an unlisted one
Illustrative exampleNumbers here are illustrative: round figures to reason with, not measurements.
The link is the only lock on an unlisted paste, so the id must be impossible to guess. Each paste gets 128 bits from the operating system’s cryptographically secure generator, written as 22 letters and digits. With about 2 billion live pastes, a random guess finds one about once in 10^29 tries. A UUIDv4 from a secure generator, with 122 random bits, works too; RFC 9562 warns that UUIDs are not to be treated as hard to guess (RFC 9562 (opens in a new tab)), which is why the generator must be a secure one and every other check still applies.
What fails: a counter (the next link is the next paste), a timestamp plus a machine number, a hash of the text, and six characters from any generator: about 57 billion ids against 2 billion pastes means about one guess in 28 lands. OWASP’s advice for enumerable ids is the same: check access, and use long random values in URLs (OWASP (opens in a new tab)). Unlisted pastes also stay out of the recent list, search engines and the sitemap.
| Id | Possible ids | A random guess hits |
|---|---|---|
| A counter in base62 | Unlimited, but in order | The next paste, every time |
| Six base62 characters | About 57 billion | About once in 28 |
| Eight base62 characters | About 218 trillion | About once in 100,000 |
| 128 random bits (22 characters) | About 3.4 × 10^38 | About once in 10^29 |
- A user saves a 3 KB log as unlisted; the app server makes a 128-bit id, stores the text and the row, and returns the link.
- The user sends the link to a colleague, who opens it.
- Someone tries made-up links one after another; each is a 404.
- A public paste is added to the recent list; unlisted ones are not.
Read:Learn: Rate limiting and abuse preventionLearn: Data model design
Keep reading+1 min
Why not short codes, as in a link shortener?
A link shortener picks short codes and handles collisions because its links are meant to be shared publicly; Design a URL shortener covers that. An unlisted paste’s link is a secret, so length wins, and at 128 bits a collision is so unlikely that no counter or retry is needed. GitHub says the same of its own unlisted gists: they aren’t private, since anyone who discovers the URL can see them (GitHub Docs (opens in a new tab)).
Check yourself