URL Expanders vs. Link Safety Scanners: What Each Can Tell You
Short links are convenient, but they hide the most important detail: the destination. A link that looks like https://short.example/abc can redirect through several domains before it lands somewhere else. When developers
Short links are convenient, but they hide the most important detail: the destination. A link that looks like https://short.example/abc can redirect through several domains before it lands somewhere else. When developers need to inspect that path, two tools come up: URL expanders and link safety scanners. They are often used together, but they answer different questions.
A URL expander tells you where a link goes
URL expanders follow HTTP redirects. They start with the URL you provide, read the Location header from each 3xx response, and continue until the server returns a non-redirect response or the tool hits a limit. The useful output is the redirect chain: each hop, status code, and final URL.
Typical uses include checking where a shortened URL leads, debugging campaign links, verifying that an HTTP link upgrades to HTTPS, spotting unexpected cross-domain hops, and finding redirect loops or broken chains.
What it cannot tell you is whether the destination is safe. A clean redirect chain can end on a phishing page, a malware host, or a page that asks for credentials. The expander reports the path. It does not assess intent.
Expansion also has blind spots. Many shorteners and marketing platforms choose a destination based on user agent, geography, time, cookies, or click history. A server-side expander may see a different destination than a real browser. Some links redirect with JavaScript, a meta refresh, or a form submission rather than an HTTP 3xx response. A simple expander will stop at the first HTML page and may miss the next step.
A link safety scanner tells you how risky a link looks
Link safety scanners evaluate a URL or domain against reputation data, blocklists, heuristic rules, and sometimes page content or sandboxed browsing. The exact method depends on the scanner. The output is usually a verdict, score, category, or list of signals: phishing, malware, suspicious domain, newly registered domain, or no known issue.
They are useful when you need a risk gate. If users submit links to your app, a scanner can flag known bad destinations before anyone clicks. If you moderate a forum or review pull requests that include external links, a scanner can add context that an expander cannot provide.
A scanner cannot prove that a link is safe. False positives happen when a legitimate domain shares infrastructure with a bad one or when a scanner has stale data. False negatives happen with new domains, compromised sites, cloaking, and links that only turn malicious after a certain condition. A clean result means the scanner found no known problem within its coverage. It does not mean the destination is trustworthy.
Scanners also have privacy and operational costs. Sending a URL to a third-party service may expose tokens, internal hostnames, or unpublished content. Some scanners fetch the page, execute JavaScript, or follow redirects on your behalf. Decide whether that is acceptable for the links your system handles.
Side-by-side: what each tool answers
| Question | URL expander | Link safety scanner |
|---|---|---|
| Main question | Where does this link go? | Does this link look risky? |
| Main output | Redirect chain, status codes, final URL | Verdict, score, category, or reputation signals |
| Method | Follows HTTP redirects | Reputation, blocklists, heuristics, content or sandbox checks |
| Deterministic? | Mostly, for HTTP redirects | No; probabilistic and coverage-dependent |
| Best for | Transparency, debugging, link audits | Risk screening and user-submitted link checks |
| Blind spots | No risk judgment; conditional, JS, or meta-refresh redirects | False positives, false negatives, privacy, scanner evasion |
| Does it show the final destination? | Often, when the link uses HTTP redirects | Not always; depends on the scanner and the link |
| Does it detect phishing or malware? | No | Sometimes, within the scanner's coverage |
Inspect a short link with curl
If you only need the final URL and the status codes, curl is enough for a first pass. This command follows up to 10 redirects, discards the body, and prints the response headers:
curl -sS -o /dev/null -D - -L --max-redirs 10 -A 'Mozilla/5.0 (compatible; LinkCheck/1.0)' https://short.example/abc
To get a compact summary:
curl -sS -o /dev/null -w 'final=%{url_effective} code=%{http_code} redirects=%{num_redirects}' -L --max-redirs 10 https://short.example/abc
Look for Location headers and the final URL. A hop to an unrelated domain, a drop from HTTPS to HTTP, or a redirect into a raw IP address deserves a closer look. None of those signals is proof of malice on its own.
Trace redirects in Python
When you need the full chain in code, disable automatic redirects and follow each hop yourself. This makes it easier to log each URL and apply limits:
import requests
from urllib.parse import urljoin
def trace_redirects(url, max_hops=10):
for _ in range(max_hops + 1):
response = requests.get(url, allow_redirects=False, timeout=10, stream=True)
print(response.status_code, url)
if not response.is_redirect:
response.close()
return url
url = urljoin(url, response.headers['Location'])
response.close()
raise RuntimeError('too many redirects')
Run this in an isolated worker with a short timeout, a redirect limit, and no access to credentials or internal metadata services. If you build a link-checking service, validate every hop, not just the first URL. Block loopback, private, link-local, and cloud metadata addresses to reduce SSRF risk. Do not send cookies or authorization headers to destinations you do not trust.
How to combine them in a link-checking workflow
For developer-facing systems, a two-stage check is usually clearer than pretending one tool does everything:
- Parse and normalize the URL. Reject malformed input and unsupported schemes before any network call.
- Expand the link in a constrained fetcher. Record status codes,
Locationheaders, and the final URL. Stop on too many hops. - Run a safety scan on the final URL and, when useful, on intermediate domains. Keep the scanner result separate from the expansion result.
- Apply a policy. A link can be allowed, warned, blocked, or sent to manual review depending on your risk tolerance.
- Log enough for debugging, but redact tokens and sensitive query parameters. Link logs often contain more data than teams expect.
For a short link such as LinkBit, expansion exposes the redirect target, while a scanner evaluates that target's reputation. The two outputs belong in different fields in your logs.
Common mistakes
Treating HTTPS as a safety signal. TLS protects the connection; it does not tell you who owns the destination or what the page will do.
Assuming every user gets the same redirect. User-agent, location, cookies, and time can change the destination.
Using a scanner as the only defense. A clean scan is not a guarantee, and attackers can rotate domains faster than blocklists update.
Following redirects without SSRF protections. A user-supplied URL can point at internal services or cloud metadata endpoints; a redirect can do the same.
Storing full URLs with secrets. Query strings often contain tokens; redact them before logging.
Takeaway
Use a URL expander to answer where a link goes. Use a link safety scanner to estimate whether the destination looks risky. For code that handles user-submitted links, keep those steps separate: expansion is the transparency layer, scanning is the risk layer, and policy decides what to do with both. Neither tool replaces the other, and neither output should be treated as a guarantee.
WebSecurity #URL #Security #Python #Redirects
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.