
Short Link Design: Why Deleted Slugs Must Never Be Reused
Short link design lesson from the November 2026 Bitly link hijacks: keep tombstones, return 410, and block slug reuse. Tested Python code included.
- Problem: A short link’s identifier gets freed on deletion, so anyone can claim it and redirect every old copy.
- Pattern: Never delete slug rows. Mark them gone, answer 410, and refuse every new claim.
- When to use: Any service that issues public identifiers that outlive their owner: short links, QR codes, vanity URLs.
- Trade-off: You store one small row per dead link forever and give up slug recycling.
Short link design must treat a slug as permanent. Keep the row after deletion as a tombstone, return 410 Gone, and reject any new claim on it. Freeing the slug lets an attacker re-register it and redirect every old tweet, QR code and email that still points there.
Short link design is the architecture of a service that maps a short identifier (a slug, or “back-half”) to a destination URL and redirects visitors. Its core invariant is that one slug maps to at most one owner for its entire lifetime.
Short link design became a front-page topic on 15 November 2026. A Ransomnews report says old Bitly links in 2011 tweets from Burger King and McDonald’s had been created again and now pointed at unrelated pages. The tweets were unchanged. Only the redirects behind them moved. The post also shows up on the Hacker News front page, where it sat at 214 points and 114 comments when we fetched it. This article explains the failure, a design that prevents it, and a tested code sample. We label what is reported, what is confirmed, and what is our own opinion.
What happened with the old Bitly links?
According to the Ransomnews report, the Burger King link from a 24 July 2011 tweet was created again at 05:32 UTC on 15 November, and the McDonald’s link from 7 June 2011 at 05:14 UTC. The report says nobody hacked those accounts. The links simply led somewhere new.
The same report checked 97 Bitly links in Donald Trump’s tweets from 2009 to 2013. It counted 40 unchanged, 49 re-created but still pointing where the tweet implied, 7 pointing somewhere unrelated, and 1 blocked by Bitly. By its later check, Bitly had deactivated the Burger King and McDonald’s links and most of the seven.
Two cautions. First, this is one outlet’s analysis, and the report says it found no public statement from Bitly at the time. Treat the exact mechanism as reported, not confirmed by Bitly. Second, Bitly’s own help page says back-halves on bit.ly links “cannot be re-used”, whether generated or custom. The report’s creation dates contradict that claim. A February 2025 report describes a similar bug, where Bitly allowed a custom ending to be claimed after the original link or account was deleted or deactivated, and says Bitly fixed it.
Why does a freed identifier become an attack?
A short link is a pointer that people copy into places you cannot edit: old posts, printed QR codes, emails, PDFs. The owner may be gone, but the pointer still works. Whoever controls the slug controls every one of those copies.
Security teams call this class of problem broken link hijacking. Acunetix defines it as an attack that “exploits external links that are no longer valid”, and lists a lapsed link shortener as one example. In this case the dangling thing is not a domain. It is a slug inside a service that keeps running.
The naive design looks harmless. Deleting an account deletes its links to save storage and honour privacy requests. Once the row is gone, the unique-key check passes for the next person:
def delete_account(self, owner):
self.db.execute("DELETE FROM links WHERE owner=?", (owner,)) # slug is free again
def create(self, owner, dest, slug):
self.db.execute("INSERT INTO links VALUES(?,?,?)", (slug, dest, owner)) # succeeds for anyone
The flaw is a modelling error. The database treats “no row” as “never existed”, but the real world treats the slug as taken, because copies are still out there.
What are the requirements for a safe short-link service?
Functional requirements: create a link with a generated or custom slug, redirect, disable, and delete an account. Non-functional requirements: a slug never changes owner, redirects stay fast, and creation is safe under concurrent claims.
- Identity: The slug is the primary key. It is unique across all time, not only among live links.
- Lifecycle: A link moves from active to gone. No path returns it to unclaimed.
- Atomic claim: Creation is a single INSERT that fails on duplicates. Do not do “check, then insert”.
- Honest responses: Unknown slug returns 404. Tombstoned slug returns 410.
- Privacy: Delete the destination URL and owner data on tombstoning. Keep only the slug and state.
Back-of-envelope sizing
These numbers are our assumptions, not measured data. Suppose a service has created 1 billion links over its life (assumption) and a tombstone row costs 100 bytes including index overhead (assumption). Then 1,000,000,000 × 100 bytes = 100 GB. That is small next to the cost of a hijack. For random slugs, 7 base62 characters give 62^7 = 3,521,614,606,208 values, which we computed in the sandbox. Six characters give 62^6 = 56,800,235,584.
How does the tombstone design work?
Data path: client requests /slug, the edge or cache asks the resolver, the resolver reads one row by primary key, and returns 302, 404 or 410. Writes go through one INSERT on the same primary key. The database enforces uniqueness, not application code.
| Slug state | Row exists? | Resolve result | New claim on same slug |
|---|---|---|---|
| Never used | No | 404 | Allowed |
| Active | Yes, with destination | 302 to destination | Rejected |
| Deleted by owner or account | Yes, destination cleared | 410 Gone | Rejected |
We use 302 here because MDN describes it as a temporary redirect, which keeps you in control. For the gone case, MDN says a 410 means the server expects the removal to be permanent, and advises 404 when permanence is unknown. A tombstone is precisely the knowledge that makes 410 correct.
What does the working code look like?
The sample below is Python 3 with only the standard library and SQLite. We ran it in a sandbox on Python 3.13.18. The primary key does the heavy lifting, and tombstoning updates the row instead of deleting it.
import secrets, sqlite3, string
ALPHABET = string.ascii_letters + string.digits # base62
class SlugTaken(Exception):
pass
class Safe:
"""Slug rows are never deleted. Deleting changes state to 'gone'."""
def __init__(self, db):
self.db = db
db.execute("CREATE TABLE IF NOT EXISTS links(slug TEXT PRIMARY KEY, dest TEXT,"
" owner TEXT, state TEXT NOT NULL DEFAULT 'active')")
def create(self, owner, dest, slug=None):
for _ in range(5):
s = slug or "".join(secrets.choice(ALPHABET) for _ in range(7))
try:
self.db.execute("INSERT INTO links(slug,dest,owner) VALUES(?,?,?)", (s, dest, owner))
return s
except sqlite3.IntegrityError:
if slug:
raise SlugTaken(slug) # tombstones count as taken
raise RuntimeError("could not allocate slug")
def delete_account(self, owner):
self.db.execute("UPDATE links SET state='gone', dest=NULL WHERE owner=?", (owner,))
def resolve(self, slug):
r = self.db.execute("SELECT dest,state FROM links WHERE slug=?", (slug,)).fetchone()
if r is None: return (404, None)
if r[1] != "active": return (410, None)
return (302, r[0])
Generated slugs use secrets.choice, so they cannot be predicted. If a random slug collides, the INSERT fails and the loop retries. A custom slug never retries, because the caller asked for that exact value.
How do you test that the slug cannot be reclaimed?
Write the attack as a test. This is the core regression test:
def test_safe_blocks_reclaim():
db = sqlite3.connect(":memory:"); s = Safe(db)
s.create("brand", "https://brand.example/store-locator", "19BFiM")
s.delete_account("brand")
assert s.resolve("19BFiM") == (410, None)
try:
s.create("attacker", "https://evil.example/", "19BFiM"); assert False
except SlugTaken:
pass
assert s.resolve("19BFiM") == (410, None)
We also ran three more tests. The first confirms the naive version lets an attacker reclaim a deleted slug. The second creates 2,000 generated slugs, deletes the account, and checks that all return 410. The third starts 20 threads claiming one slug and asserts exactly one wins. All four tests passed. Command and result from our run: python3 -I shortlinks.py printed PASS for each of the four test functions.
Idempotency matters here too. A retried “create link” request should not create a second link or fail confusingly. Our idempotency keys guide covers that pattern.
What are the trade-offs and failure modes?
Tombstones cost storage and remove slug recycling. If your slug space is tiny, say three characters, you will exhaust it, so size the space for the life of the product. Custom vanity slugs are the sensitive case, because people pick short, memorable words and then abandon them.
Other failure modes are worth testing. Backups restored from before a deletion can resurrect a slug as free, so restores must replay tombstones. Cache layers must not serve a stale 302 after tombstoning, so purge on state change. A privacy law request may require deleting more than the slug. Keep the identifier, drop everything personal, and document why.
Resolve endpoints also deserve abuse protection. Attackers enumerate short slugs to find abandoned ones, which a rate limiter slows down. See our rate limiter design guide.
When should you not use permanent tombstones?
Skip them for identifiers that never leave your system, such as internal job IDs, or links that are explicitly temporary and never printed or posted. If a link is meant to expire in an hour and is used once, recycling a random 128-bit value is not a hijack risk. The danger exists when copies live outside your control for years.
How does it compare with other approaches?
| Approach | Hijack risk | Storage cost | Main weakness |
|---|---|---|---|
| Hard delete, free the slug | High: anyone can claim it | Lowest | Old copies redirect to strangers |
| Quarantine for N days, then free | Delayed, not removed | Low | Copies outlive any chosen N |
| Permanent tombstone (this design) | Low for claims through the service | One small row per link | Slug space shrinks over time |
| Own the domain only, ignore slugs | Does not address slug claims | None | Misses the failure above |
Is there a real-world precedent for this class of failure?
Yes, two, both linked above. The February 2025 Disruptionist report describes memecoin promoters redirecting old links in posts on President Trump’s X account, which it says reached about a $1 million market cap for one token at one point. The November 2026 Ransomnews report describes the same pattern with brand tweets. We do not know the root cause beyond what those reports and Bitly’s help page say, and we will not guess at Bitly’s internals.
Interview questions this topic prepares you for
How would you design a URL shortener that survives account deletion?
Make the slug the primary key and never delete its row. On account deletion, set state to gone, clear the destination and owner data, and keep the slug. Resolve returns 410 for tombstones. New claims fail on the unique key, so reuse is impossible. Mention storage sizing as a stated assumption, not a fact.
Follow-up they may ask: How would you handle a legal request to remove all trace of a link?
How do you generate slugs safely at scale?
Use a cryptographic random generator over base62 and rely on the unique constraint for collisions, retrying on conflict. Seven characters give 62^7 values, so random collisions are rare early on. For custom slugs, never retry; return a conflict. Rate-limit creation and lookup to slow enumeration of abandoned slugs.
Follow-up they may ask: Why not a counter encoded in base62?
Which status codes should a shortener return?
Return 302 for active links when you want control, 404 for slugs never issued, and 410 for tombstoned ones. 301 signals a permanent move, so clients may keep following a link you later disable. Choose per product, and explain the cache implications of each choice.
Follow-up they may ask: How would you invalidate a CDN cache after a takedown?
The NexGismo verdict: My recommendation: treat every public identifier as permanent, and make “deleted” a state rather than an absence. A tombstone row is cheap, boring and testable, and it removes a whole attack class. Add the hijack test to your suite before your next release. Quarantine windows only delay the problem.
- A short link’s slug is a pointer copied into places the owner cannot edit, so its owner must never change.
- Deleting a slug row makes a unique-key check pass for the next claimant; marking it gone does not.
- Bitly’s help page says back-halves “cannot be re-used”, yet a November 2026 report found re-created links.
- Return 410 Gone for tombstoned slugs and 404 only when you have never issued the slug.
- Seven base62 characters give 62^7 = 3,521,614,606,208 possible slugs.
- Test the attack directly: delete, reclaim, assert the claim fails and the redirect stays dead.
Frequently Asked Questions
Can a deleted short link be re-registered by someone else?
It can if the service frees the identifier on deletion. Bitly’s help page says back-halves “cannot be re-used”, yet a November 2026 report found re-created links, and a February 2025 report described a bug that allowed this. The design fix is to keep the slug row as a tombstone forever.
Should a deleted short link return 404 or 410?
Return 410 Gone when you know the removal is permanent. MDN says 410 signals the resource is gone for good and that a 404 fits when permanence is unknown. A tombstone row gives you exactly that knowledge, so 410 is the accurate answer.
Is a 302 or 301 better for a link shortener?
It depends on whether you need control. MDN describes 302 as a temporary redirect, which leaves clients asking you again, so you can disable a link later. A 301 is a permanent redirect, so clients may keep following it after you disable the link; test your cache headers before choosing it.
Do tombstones make the slug space run out?
Not in practice for random slugs. Seven base62 characters give 62^7, about 3.5 trillion values. A tombstone only costs one row, so the real cost is storage, which the back-of-envelope estimate in this article puts at about 100 GB under stated assumptions.
How do you stop attackers guessing short-link slugs?
Use random slugs from a cryptographic generator, rate-limit lookups and creations, and alert on bursts of misses. Our rate limiter guide covers token bucket and sliding window designs you can apply to the resolve endpoint.
Short link design looks simple until deletion enters the picture. The fix is small: keep the slug, drop the data, answer 410, and let the database enforce uniqueness. If you run any service that issues public identifiers, audit your delete path this week. Then read our Microsoft 365 outage breakdown for another case where an assumption in a basic check failed in production.
Sources
- Ransomnews — Old Bitly links hijacked in brand and Trump tweets (15 Nov 2026)
- Bitly Help Center — What happens to links after an account is deleted
- Disruptionist — Crypto scammers hacked Trump’s tweets via bug (3 Feb 2025)
- Acunetix — Broken link hijacking
- MDN Web Docs — 410 Gone
- MDN Web Docs — 302 Found
- Hacker News — Front page, 16 Nov 2026