Skip to content

feat(rules): images/hotlinked reports content images loaded from other sites' servers #932 - #1028

Closed
nc9 wants to merge 2 commits into
mainfrom
feat/932-hotlinked-images
Closed

nc9 wants to merge 2 commits into
mainfrom
feat/932-hotlinked-images

Conversation

@nc9

@nc9 nc9 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #932

New rule images/hotlinked (page scope, no network, URL parsing on markup the page already has): reports, as info, a content image that loads from another site's server, grouped per host. Every finding is info and the rule severity is info: it never lowers the score.

What counts: <img> (data-src and data-lazy-src before a placeholder src, then src and srcset), <picture> <source>, inline style background; nothing inside <noscript>. Relative URLs resolve against <base href> when set. Pages on localhost or a loopback address are skipped.

Not a hotlink

  • first-party (same registrable domain via the PSL, the site's baseUrl domain too);
  • the built-in CDN, site-builder and object or app storage list (images/optimized's list, extended per the review: r2.dev, convex.cloud, railway, herokuapp, onrender, laravel.cloud, strapiapp, beehiiv, wsimg, optimole, shortpixel, gumlet, flagcdn, framerusercontent, jsdelivr, simpleicons, gstatic, raw.githubusercontent, s.w.org, buymeacoffee, plus img.youtube.com, trustpilot.net, kajabi-cdn, oraclecloud, myqcloud, aliyuncs, vsassets, itch.zone, slack-edge). The bare tenant domains (wordpress.com, webflow.io, webflow.com, shopify.com, squarespace.com, ghost.io, contentful.com, sanity.io) are gone: only their CDN hosts stay, so another tenant's site is a hotlink;
  • launch directories and badge sites (producthunt.com, trendshift.io, dmca.com, capterra.com, legitscript.com, fazier.com, peerpush.com, launchbuff.com, startupfa.me, findly.tools, twelve.tools, nicklaunches.com, launchstag.com), and any image whose path or alt matches badge|embed|widget|featured|launch|seal|banner-ad;
  • a host the page also loads a script or stylesheet from, or preconnects, dns-prefetches or preloads (exact host, whole document; documented as a connection signal, not an ownership test);
  • listed in allowed_hosts.
  • Skipped: tracking pixels (1x1, display:none, analytics hosts incl. mc.yandex.ru, visitorbadge.io, getclicky.com, umami.is, simpleanalyticscdn.com, and platform pixel paths only: facebook.com/tr, pinterest.com/ct, tiktok pixel, snapchat, t.co/i/adsct), avatar services (Gravatar, ui-avatars.com, icon.horse, ...), data/blob URLs.
  • The fix advice no longer says only "download and self-host": for a dynamic badge or widget the other site keeps current, embedding it is how it is meant to work.

Corpus (reviewer's eval, 50,000-page target: 45,547 stored pages, 16,935 projects)

  • Before (warning): 15.2% of projects, with 28% of warn pages from api.producthunt.com; hand-judged precision 10-20%.
  • After: 1,792 pages carry a hotlink finding (3.9% of pages), 931 projects (5.5%); plus 1,086 pages (2.4%) with a share-image info; 23,959 pass, 18,931 no content images. The 3% info-share target is not met: 3.9% of pages. 137 microseconds per page.
  • Hand judgement of 40 random hits (seed 5, taken before the last host additions): 11 real third-party content images (Bing thumbnails, Discord CDN, Wikimedia, pngimg, postimg, a GitHub Pages icon set, YouTube thumbnails), 29 not (a site's own CMS or sibling domain, partner directory logos, an analytics pixel, form and widget images, object storage). About 28% precision, which is why it is info only. I then added the obvious hosts from that sample (analytics CDN, YouTube thumbnails, Trustpilot, Kajabi, Oracle, Tencent and Aliyun storage, VS Marketplace, itch.zone, Slack) and the numbers above are after them.
  • The residual is mostly a site's own infrastructure host on a different registrable domain, which no list can know; allowed_hosts is the escape hatch and is documented.

Registry and counts: rule, images/index.ts, docs page with options, nav, images card, images "(16 rules)" in both indexes, constants.ts 309 to 310, golden pin (perRuleTally 310, findings +500, health score unmoved at 51), varyingRules for both corpora.

Tests: hotlinked-932.test.ts (26: the issue's fixtures, per-host grouping, invariant message, picture/srcset/lazy/background, first-party and lookalikes, the CDN list and the new hosts, bare tenants, badges by host path and alt, platform pixel paths, loopback, <base href>, allowed_hosts spellings, share images, robustness, 3,000 images under 1.5 s). Registry-wide rule tests and the golden pass by explicit path; tsgo packages/rules clean; tangly check --strict passes. Agent skill: no change needed.

Merge note: this and #1024 both bump the same count literals and golden pin, so the second to land needs a trivial rebase.

@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Reviewed the diff for images/hotlinked. The rule is well structured: no network access, bounded output, a stable message, and good test coverage. I could not run the tests here. Findings:

  • (medium) packages/rules/src/images/hotlinked.ts (connectedHosts): preload and modulepreload count as "the site connects to this host on purpose". A <link rel="preload" as="image" href="https://other.org/hero.jpg"> is how a hotlinked LCP image is commonly preloaded, so that hotlink is silently exempted. The docs only mention "preconnects or prefetches". Restrict preload to as=script|style|font, or drop it, and align the docs with the code.
  • (medium) hotlinked.ts (img loop): an image is counted once, by its first usable URL (src, then data-src, and so on). A lazy-loaded image with a local placeholder src="/placeholder.gif" and a remote data-src or srcset is attributed to the local host and never flagged. This is the typical lazy-loader pattern the docs say is supported. Consider preferring data-src and data-srcset over a src that is first-party or a placeholder, or consider every candidate host.
  • (low) TRACKING_HOSTS is applied to every image, not just 1x1 pixels. It includes facebook.com, pinterest.com, tiktok.com, snapchat.com and t.co, so a real content image hosted there is never reported. Likewise KNOWN_IMAGE_HOSTS allows the whole of amazonaws.com, fastly.net, akamaized.net, shopify.com, wordpress.com and webflow.com. Anyone's bucket or blog on these hosts passes, which makes the rule lenient. That is probably an acceptable false-negative tradeoff, but the docs should say so.
  • (low) isOnePixel only matches when both width and height attributes are present and <=1. A tracker with only width="1", or sized with CSS, is reported as a content image. The docs also claim "hidden with display:none", but only an inline style on the <img> itself is checked, not a hidden parent.
  • (low) Background images are only read from [style] attributes, not <style> blocks. The docs state this correctly, but it is a known limitation.
  • (nit) The 3,000-image test asserts < 1500ms wall-clock, which can flake on a slow CI runner. A looser bound would be steadier.
  • (nit) The CHANGELOG entry is long compared with the neighbouring entries.

@nc9
nc9 force-pushed the feat/932-hotlinked-images branch from 286510d to 8c35958 Compare October 22, 2026 13:13
@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Review of images/hotlinked. I read packages/rules/src/images/hotlinked.ts in full. I skimmed the docs, changelog and fixtures and did not run the tests. Overall the rule is well structured: it uses no network, every finding is info, and the false-positive guards are thorough. I found no blocking issues.

  • (low) hotlinked.ts BADGE_WORDS: /badge|embed|widget|featured|launch|seal|banner-ad/i is tested against the whole path and the alt text. Ordinary content images match easily, e.g. /featured-image.jpg, /uploads/launch-day.png, or an alt like "Featured in the press". Those hotlinks are then silently skipped, and they also don't count toward contentImages. This is a false-negative bias that is probably acceptable for an info rule, but I would consider matching on path segments or filename tokens only, or dropping featured and launch, which are the broadest words.
  • (low) hotlinked.ts the fallback "No content images found" check has status info. That includes pages whose only images were badges, tracking pixels or display:none. A page with nothing to report would be better served by skipped or no check at all. As written, every image-free page emits an info finding, which could be noisy in reports.
  • (low) hotlinked.ts connected.has(host) is an exact-host match. A page that loads a script from cdn.partner.com still reports images from img.partner.com. The docs describe this as a connection signal, so this may be intentional, but the limitation is worth stating in the solution text.
  • (nit) registrableDomain and isLoopbackHost are imported from ../content/dev-leakage. They are general URL helpers and would fit better in @squirrelscan/utils. The cross-rule import couples this rule to an unrelated one.
  • (nit) srcsetUrls splits on ,\s+, so a data: URL inside a srcset gets mangled. It is harmless because parseImage rejects the fragments, but a short comment would help.
  • (nit) check_social_images is not mentioned in the PR description. Please document it there and in docs/rules/images/hotlinked.mdx. I did not confirm whether the doc covers it.
  • (nit) KNOWN_IMAGE_HOSTS and the other host lists are exported or declared inline. The list is long, so moving it to a shared constant that images/optimized also imports would stop the two lists drifting. The header comment says it extends that list, so they will drift unless one is derived from the other.

Test coverage: hotlinked-933.test.ts and the golden and template-invariance fixtures are updated. A case for <base href>, one for allowed_hosts normalisation (scheme, port and *. prefix) and one for the badge-word false negatives above would be a good addition if they are not already covered.

@claude

claude Bot commented Oct 22, 2026

Copy link
Copy Markdown

Correction to my review above: the test file is packages/rules/tests/hotlinked-932.test.ts, not hotlinked-933. I did not open that test file, so my suggestions for extra test cases (<base href>, allowed_hosts normalisation, badge-word false negatives) may already be covered. Please check before adding them. No findings in my review are (high) or (critical).

@nc9 nc9 mentioned this pull request Oct 26, 2026
@nc9

nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Landed in the v0.0.135 batch (#1151), main commits 6f383f0..f70b22e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New rule: images/hotlinked - content images loaded from other sites' servers

1 participant