← Back to Blog

Unwrapping Redirect URLs Without Fetching Them (2026)

AnnMax · November 19, 20269 min read

The Obvious Implementation Is the Wrong One

A wrapped link looks like this: https://l.facebook.com/l.php?u=https%3A%2F%2Fexample.com%2Farticle&h=AT2.... Somewhere inside that query string is the URL you actually want. The obvious way to find it is to ask the server: issue a fetch() with redirect: 'manual', read the Location header, done. Every "unshorten" service on the web works this way, and for a server-side tool it is a fine design.

For a link cleaner that lives in your browser, it is the worst possible design. I build LinkClean, a small extension whose whole pitch is that links never leave your device. The moment the cleaner fetches a redirect to resolve it, that pitch is dead, and not in a subtle way:

So the rule in LinkClean is absolute: no redirect is ever fetched to find out where it goes. The question this article answers is what you can do instead — and it turns out the answer covers most of the wrapped links a normal person encounters.

Redirects Are Data, Not Destinations

The key observation is that the big wrapper networks do not hide the target. They carry it. The redirect exists so the wrapper can log the click, but the destination has to be in the URL itself, because the wrapper's server needs it to issue the 302. That means the destination is sitting in the string you already have — you just have to know where each network puts it.

These shapes are stable, public, and parseable:

LinkClean's Pro unwrapping recognises all of these, plus the outbound wrappers of YouTube, DuckDuckGo, LinkedIn, Douban, Jianshu, SSPAI, VK, Slack, Tumblr, Medium, Pocket and Weibo's sinaurl. None of that recognition needs a network. It needs a table of shapes and a URL parser — both of which the platform already gives you.

A Hop-Limited Local Unwrapper

Here is the core of the approach, simplified for the article. Each wrapper is a matcher: a host pattern, an optional path pattern, and the parameter that carries the target. One pass tries every matcher against the current URL and returns the decoded target if one fits:

// Illustrative and simplified — the real table has ~20 shapes,
// plus per-shape decoding rules (percent-encoding, base64, path prefixes).
const WRAPPERS = [
  { host: 'www.google.com',  path: /^\/url$/,        param: 'q' },
  { host: 'l.facebook.com',  path: /^\/l\.php$/,     param: 'u' },
  { host: 'out.reddit.com',  path: null,             param: 'url' },
  { host: 'link.zhihu.com',  path: null,             param: 'target' },
  { host: /\.safelinks\.protection\.outlook\.com$/,
    path: null, param: 'url' },
  { host: null, path: /\/redirect\/?$/, param: 'url' } // generic shape
];

function unwrapOnce(urlStr) {
  let u;
  try { u = new URL(urlStr); } catch { return null; }
  if (u.protocol !== 'https:' && u.protocol !== 'http:') return null;
  for (const w of WRAPPERS) {
    const hostOk = w.host === null ? true
      : typeof w.host === 'string' ? u.hostname === w.host
      : w.host.test(u.hostname);
    if (!hostOk) continue;
    if (w.path && !w.path.test(u.pathname)) continue;
    const raw = u.searchParams.get(w.param);
    if (!raw) continue;
    try {
      const target = new URL(raw); // searchParams already percent-decodes
      if (target.protocol === 'https:' || target.protocol === 'http:')
        return target.href;
    } catch { /* not a URL — this shape did not match after all */ }
  }
  return null;
}

Two details in that snippet are load-bearing. First, the protocol check on both ends: a "target" of javascript: or data: is not a redirect worth unwrapping, it is an injection attempt wearing a redirect's clothes. Second, the failure mode: when a shape matches but the parameter does not parse as a URL, the matcher declines rather than guessing. A cleaner that mangles a URL it does not understand is worse than one that leaves it alone.

Wrapped links are often wrapped twice — a newsletter wraps a social link that wraps the article. So the resolver is recursive, but with a hard ceiling of three hops:

function unwrapChain(start, maxHops = 3) {
  const chain = [start];
  let current = start;
  for (let hop = 0; hop < maxHops; hop++) {
    const next = unwrapOnce(current);
    if (!next || next === current) break;      // nothing left to unwrap
    if (sameSite(next, current)) break;        // target belongs to the wrapper itself
    chain.push(next);
    current = next;
  }
  return { clean: current, chain };
}

The hop limit is not a performance tweak, it is a termination guarantee. Local parsing cannot see cycles the way a fetcher eventually would (a redirect loop ends in a browser error); a wrapper whose target parameter contains another copy of itself would loop forever in a naive while. Three hops covers every real chain I have seen — newsletter → social → destination — and turns a pathological input into a bounded, boring result.

The Cross-Site Rule: When a ?url= Is Not a Redirect

The subtlest bug in this whole feature is the false positive. Plenty of legitimate pages take a ?url= or ?target= parameter that is part of the page's own function: a reader view, a preview tool, a download mirror selector. Unwrapping those destroys the link — you hand the user the parameter's value when the parameter was the point.

LinkClean's rule is simple: a redirect is only unwrapped when the target sits on another site than the wrapper. If tools.example.org/redirect?url=https://tools.example.org/files/report.pdf points back at its own site, the URL is left exactly as it is. The sameSite check in the snippet above is where this lives, and in production it compares registrable domains, not raw hostnames — comparing foo.co.uk and bar.co.uk by "last two labels" would call two unrelated sites the same one. You need the public-suffix notion of a site, or the rule quietly misfires on half the British web.

This is also why the generic /redirect?url= matcher is safe to ship at all. On its own it is an aggressive guess; combined with the cross-site rule and the known-shape table taking priority, it only fires on URLs that really look like outbound hops.

Show the Chain, List Every Removal

Local resolution has one more advantage over fetching that I did not expect to care about as much as I do: it is explainable. A fetch-based resolver can only tell you the final answer — it cannot tell you why, because the answer came from a server's mood that day. A parser can show its work.

LinkClean's unwrap result displays the full chain it walked: the original wrapper, each intermediate hop, and the final destination. You can see that the link went Outlook → a marketing tracker → the actual article, and decide for yourself whether the destination is where you wanted to go. The same philosophy governs parameter stripping: every removed parameter is listed by name, together with the value the site would have received. Nothing disappears silently. If the cleaner ever removes something you needed, you can see exactly what it was — and in Pro, click it once to keep that parameter on that site from then on.

Tracking Parameters: A Curated Blocklist, Not a Guessed Allowlist

Stripping the wrapper is half the job; the destination URL usually arrives wearing its own tracking jewellery. Here the design debate is allowlist versus blocklist. An allowlist — keep only parameters known to be functional — sounds safer for privacy and is a disaster in practice: the web has no registry of functional parameters. page, q, sort, variant, t (a YouTube timestamp), id, ten thousand CMS-specific names — an allowlist breaks all of them by default, and a link cleaner that breaks links is uninstalled by lunchtime.

LinkClean goes the other way: a curated removal list of 61 named marketing parameters plus 12 prefix families — the utm_, ga_, mtm_, piwik_, _hs and spm_ families among them — and everything not on the list survives. Filters, page numbers, product options and search terms are untouched because the cleaner has never heard of them, which is exactly the point. The honest cost of a blocklist is that a brand-new tracker parameter survives until the list learns it; the honest cost of an allowlist is that your users' links break today. I chose the failure mode that errs toward the user's intent.

Pro adds the escape hatch that makes a blocklist livable long-term: per-domain keep/remove rules where the most specific domain wins and subdomains inherit — shop.example.com overrides example.com — so Amazon can keep th and psc while everything else is stripped. Rules, custom parameters and keep-lists travel between machines as one JSON bundle.

AMP Is the Same Trick in a Different Costume

An AMP URL is a redirect that happens at the content layer instead of the HTTP layer: google.com/amp/s/example.com/article or example-com.cdn.ampproject.org/c/s/example.com/article serves a cached, re-hosted copy of the page. The canonical URL is embedded in the path, so recovering it is the same local-parsing idea — strip the known prefix shapes (cdn.ampproject.org/c/s/, google.com/amp/s/, a trailing /amp), restore the original scheme and host, and drop the AMP leftovers (amp_js_v, outputtype, usqp) that ride along in the query.

No fetch, again. The canonical page is not discovered by asking Google where it lives; it is decoded from the string Google already handed you. LinkClean treats AMP resolution as part of the same Pro unwrapping pass, so a wrapped AMP link — a social wrapper around a Google AMP cache URL — resolves in one chain walk.

What This Looks Like as a Product

All of the above ships in LinkClean, a Manifest V3 extension built for Firefox 140 and later, with Chrome, Edge and Firefox store listings still coming soon — the product page is the place to watch. The split is deliberate: single-link cleaning with the full built-in parameter list, Markdown copy, clipboard paste, batch up to 10 links — lists or whole paragraphs — and a small history is free, permanently. Redirect and AMP unwrapping, per-site rules, unlimited batch with no 10-link cap and history search are the optional Pro licence — one key, two browsers, validated at most about every two hours, working offline from the cached licence, and a failed check never locks you out.

The privacy architecture is the part I would defend in a review: no content script at all, no tabs, scripting or debugger permission. The extension sees only the URL you hand it — pasted, or prefilled from the tab you clicked via activeTab. The clipboard is read only when you press Paste. Without a licence key it makes no network request of any kind; with one, the only request is the licence check. Every technique in this article exists because "zero network" is a promise, and promises constrain code.

The Honest Limits

Local parsing has a real boundary, and it would be dishonest to write this article without it. An opaque shortener — bit.ly/xyz and its relatives — carries no target in the string. The mapping lives in a database on the shortener's server, and the only way to learn it is to ask, which is precisely what LinkClean refuses to do. Those links are left alone rather than resolved through a fetch, a third-party API, or a "privacy-preserving" resolver that is neither. The same goes for wrappers whose shape changes or whose targets are encrypted server-side: if the string does not contain the answer, the cleaner says so by doing nothing.

That is the trade, stated plainly: everything that can be resolved from the URL alone is resolved locally, instantly, offline, and with a visible chain — and everything else is untouched. For the links that arrive through newsletters, social shares and corporate mail gateways, that covers most of the trail worth removing. The rest was never yours to fetch.