How to Safely Expand Shortened URLs and Detect Phishing Redirect Chains in Bulk

Shortened links (bit.ly, tinyurl.com, t.co, or custom marketing redirectors) are everywhere in user-generated content, support tickets, and automated data pipelines. Unfortunately, attackers also rely heavily on multi-hop redirect chains to disguise phishing landing pages and bypass basic domain blocklists. If your application accepts, moderates, or scrapes external URLs, expanding short links safely is a critical defense layer. Why Naive fetch() Redirect Following Is Risky A common mistake is writing a quick helper script using fetch(url, { redirect: "follow" }) and reading response.url. In production, that approach introduces three serious problems: SSRF (Server-Side Request Forgery): A malicious short link can redirect your server to http://127.0.0.1, http://169.254.169.254 (cloud metadata endpoints), or internal RFC 1918 networks. Hidden Intermediate Hops: Standard redirect following only shows the final URL, hiding intermediate tracking domains, compromised redire

How to Safely Expand Shortened URLs and Detect Phishing Redirect Chains in Bulk

Shortened links (bit.ly, tinyurl.com, t.co, or custom marketing redirectors) are everywhere in user-generated content, support tickets, and automated data pipelines. Unfortunately, attackers also rely heavily on multi-hop redirect chains to disguise phishing landing pages and bypass basic domain blocklists.

If your application accepts, moderates, or scrapes external URLs, expanding short links safely is a critical defense layer.

Why Naive fetch() Redirect Following Is Risky

A common mistake is writing a quick helper script using fetch(url, { redirect: "follow" }) and reading response.url. In production, that approach introduces three serious problems:

  1. SSRF (Server-Side Request Forgery): A malicious short link can redirect your server to http://127.0.0.1, http://169.254.169.254 (cloud metadata endpoints), or internal RFC 1918 networks.
  2. Hidden Intermediate Hops: Standard redirect following only shows the final URL, hiding intermediate tracking domains, compromised redirectors, or cloaking hops.
  3. No Phishing Signal Analysis: Knowing the final URL is useful, but moderation pipelines also need automated heuristics—flagging IP-based hosts, deceptive subdomains, punycode/lookalike tricks, and high-risk URL patterns.

Designing a Safe URL Inspection Pipeline

A production-ready URL unshortener and risk scanner should:

  • Trace redirects manually (redirect: "manual"): Inspect each 3xx Location header hop-by-hop with a strict hop limit and request timeout, without executing JavaScript or downloading heavy page bodies.
  • Enforce SSRF filtering at every hop: Validate every resolved hostname before issuing the next request, blocking localhost, loopback, link-local, and private IPv4/IPv6 ranges.
  • Score phishing risk automatically: Evaluate the full chain and final destination to produce a structured risk score and actionable flags.

Scanning a Single URL via cURL

You can trace a single shortened or suspicious link immediately via GET /v1/scan (or POST /v1/scan):

curl -X GET "[https://bulk-url-unshortener-phishing-url-risk-api.p.rapidapi.com/v1/scan?url=https%3A%2F%2Fbit.ly%2Fexample-link](https://bulk-url-unshortener-phishing-url-risk-api.p.rapidapi.com/v1/scan?url=https%3A%2F%2Fbit.ly%2Fexample-link)" \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: bulk-url-unshortener-phishing-url-risk-api.p.rapidapi.com"

Batch Scanning Multiple URLs in Node.js

For content moderation webhooks, SOC triage, or AI agent workflows, send multiple URLs in one call using POST /v1/batch:

const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY;
const RAPIDAPI_HOST = "bulk-url-unshortener-phishing-url-risk-api.p.rapidapi.com";

async function inspectSuspiciousLinks(urls) {
  const response = await fetch(`https://${RAPIDAPI_HOST}/v1/batch`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-RapidAPI-Key": RAPIDAPI_KEY,
      "X-RapidAPI-Host": RAPIDAPI_HOST
    },
    body: JSON.stringify({ urls })
  });

  if (!response.ok) {
    throw new Error(`Scan request failed: ${response.status}`);
  }

  const report = await response.json();

  for (const item of report.results ?? []) {
    console.log({
      input: item.input,
      finalUrl: item.final_url,
      hops: item.redirect_count,
      riskScore: item.risk_score,
      riskLevel: item.risk_level
    });
  }
}

inspectSuspiciousLinks([
  "[https://bit.ly/example-link](https://bit.ly/example-link)",
  "[https://t.co/example-hop](https://t.co/example-hop)"
]);

Common Production Use Cases

  • UGC & Comment Moderation: Automatically expand and quarantine high-risk shortened links before they appear publicly.
  • Security & SOC Triage: Inspect suspicious links from phishing reports in bulk without exposing analyst browsers.
  • AI Agents & Web Scrapers: Validate unknown URLs in n8n, Make, or MCP agent pipelines before passing them to a headless browser.
  • Affiliate & Marketing QA: Verify that third-party tracking links resolve cleanly to the expected destination without broken redirects.

Try It Yourself

Never trust hop 1 of a shortened URL—always trace the full redirect chain and score the final destination before your users or crawlers touch it.

Share