Skip to content

fix(rules): Cloudflare email-protection links are not broken links #811 - #829

Merged
nc9 merged 3 commits into
mainfrom
fix/811-cf-email-protection-links
Oct 15, 2026
Merged

nc9 merged 3 commits into
mainfrom
fix/811-cf-email-protection-links

Conversation

@nc9

@nc9 nc9 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Closes #811.

What changes

With Cloudflare's Email Address Obfuscation on, every mailto: link becomes /cdn-cgi/l/email-protection#<hex>, and every address in the text becomes <a href="/cdn-cgi/l/email-protection" data-cfemail="<hex>">. A script puts the address back in the browser. Requested directly, the path answers an error, so links/broken-links listed one "broken internal link" per address, with every page carrying it in its footer as a source.

  • Parser: both link extractors (html.ts extractLinks, which feeds stored parsedData and the rules, and extractors/links.ts, which feeds the crawl queue and the external link collection) leave these links out on any host. So the crawl never queues one, the internal link check never sees one, and the external link check never requests one on another site.
  • Contact links: extractContactLinks records each one as the mailto: it stands for, with obfuscated: "cloudflare" (new optional field on ContactLinkData). The address is decoded the way Cloudflare's script does it (key byte XOR, UTF-8), or value: "" when the payload does not decode to an address. local/nap-consistency (via extractNapSignal) now sees these pages as having a mailto link.
  • Stored parses: a page parse stored before this change (incremental crawls reuse parsedData) still has the links in links. links/broken-links and the internal link check's target collection (audit-engine adapter) skip them by URL too.
  • Visible skip: every broken-links row carries details.emailProtectionLinks (anchors left out, from both sources) when there were any.
  • Only /cdn-cgi/l/email-protection is skipped, not every /cdn-cgi/ path as the issue's Expected section suggested. Cloudflare image-resizing URLs (/cdn-cgi/image/...) are real resources that sites do link to, and a broken one should still be reported. A test pins this.
  • New helpers in @squirrelscan/utils (cloudflare-email.ts, also exported at @squirrelscan/utils/cloudflare-email): isCloudflareEmailProtectionUrl, decodeCloudflareEmail.

Tests

  • packages/utils/tests/cloudflare-email.test.ts: path matching (relative, absolute, any host, case, not other /cdn-cgi/ paths), decoding, and malformed payloads.
  • packages/parser/tests/contact-links.test.ts: an obfuscated mailto link and a data-cfemail address (on the anchor and nested) become contact links and leave links empty. Also covers an undecodable payload, another host (extractLinks in both extractors), the crawl queue (extractCrawlableUrls), and an image-resizing link staying a link.
  • packages/rules/tests/cf-email-protection-811.test.ts: a stored-parse link the crawl or the internal check got a 404 for is not broken and is counted. Obfuscated contact links are counted on a pass and beside a real broken link. Plain mailto links are not counted. A broken /cdn-cgi/image/... link is still broken.
  • packages/audit-engine/tests/cf-email-protection-811-e2e.test.ts: real crawler, a local server whose /cdn-cgi/ answers 404, both rule engines, crawl following links and not. Nothing under /cdn-cgi/ is requested, broken-links passes, and emailProtectionLinks: 4. A stored pre-fix parse is never probed either. I confirmed that case fails with the adapter skip removed.
  • Re-ran: link-checks-not-run, rate-limited-links (rules), and link-targets-not-fetched-726-e2e, link-coverage-794-e2e, link-targets-fetched-798-e2e, site-query-nap-rule-golden (audit-engine). tsgo is clean for utils, parser, rules, audit-engine, core-contracts and apps/cli. test-suites.ts --check passes, and so does tangly check --strict.
  • CLI against a local fixture with both kinds of obfuscated link and a real /gone 404, at --level quick and --level full: the server log has no /cdn-cgi/ request, /gone is the only broken link, and details.emailProtectionLinks is 4.
  • Codex was unavailable (usage limit), so this got a written self-review instead.

Docs and skill

  • rules/links/broken-links: a bullet on why these links are skipped and what they are read as, plus emailProtectionLinks in the details list.
  • configuration/external-links: the internal and external "never requests" sections name these links.
  • CHANGELOG entry under Unreleased, Fixed.
  • The squirrelscan agent skill needs no change: it does not describe which links the link rules skip.

@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Review of #829 (Cloudflare email-protection links are not broken links)

I read the diff only. I did not run the tests or check CI.

The change is well scoped. It filters at the parser, the crawler queue, the site-asset collector and the rule. The rule also filters by URL, so parses stored before this change are handled. Tests cover the helper, the parser, the rule, and an end-to-end run on both engines and both crawl modes.

  • (low) packages/parser/src/html.ts (extractContactLinks): the MAX_CONTACT_LINKS = 32 cap now also applies to obfuscated links. details.emailProtectionLinks is therefore a lower bound on pages with many addresses. The docs say it counts links "left out". Either document that it can undercount or count before the cap.
  • (low) packages/rules/src/links/broken-links.ts: emailProtectionLinks counts stored-parse links entries and parser contactLinks entries. It counts per occurrence, not per unique address. That is fine, but the docs should say so. A page with both old and new parse data would also be counted twice, though that case is unlikely.
  • (nit) cloudflareEmailContact returns value: "" when the payload does not decode. Consumers of contactLinks that assume a non-empty value should be checked. The obfuscated flag helps with that.
  • (nit) isCloudflareEmailProtectionUrl builds a URL for every link. The cost is small, but a cheap includes('/cdn-cgi/') pre-check would avoid it on the hot path.
  • (nit) decodeCloudflareEmail rejects control characters, which is good. There is no length bound on the payload, though the HTML size already bounds it.

I found no correctness or security problems.

@nc9

nc9 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Review triage (fixed in afb7bc2):

  • Secret scan (red): the e2e fixture's literal hex payloads hit detect-secrets' "Hex High Entropy String" check. The test now builds them with the same encode() helper the other tests use, so there are no hex literals left in the new files. I ran the CI hook command locally and it comes back clean, with .secrets.baseline unchanged.
  • Cap undercounts emailProtectionLinks (low): documented. The details bullet now says each page carries at most 32 contact links (tel:, mailto: and these together), so a page with more counts 32 at most. I kept the shared cap rather than counting before it. The count only makes the skip visible, and an uncapped list on every parsed page is what the cap exists to prevent.
  • Per occurrence, not per address (low): documented ("counted once for each link on each page rather than once per address"). A page cannot be counted twice. A parse stored before this change has the links in links and no obfuscated contact links, and a fresh parse has the reverse, so each page contributes from one source only.
  • value: "" consumers (nit): checked. The only contactLinks reader is extractNapSignal (utils/src/nap.ts), which sets mailtoLink = true for a mailto entry and never reads its value. links/tel-mailto reads the DOM, not contactLinks.
  • URL parse per link (nit): done. isCloudflareEmailProtectionUrl returns early unless the string contains /cdn-cgi/.
  • Payload length (nit): done. decodeCloudflareEmail refuses payloads over 1,024 hex digits, which is longer than any address, and a test covers it.

@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Review of #829 (skip Cloudflare email-protection links in broken-links). I read the diff and the new cloudflare-email.ts. I did not run the tests.

I found no high or critical problems. The approach holds up: the parser drops these links, the stored-parse path is still covered in broken-links and the adapter, and the end-to-end tests check that the path is never requested in Quick, Surface or Full.

  • (low) packages/parser/src/html.ts (extractContactLinks): obfuscated links share the 32-item MAX_CONTACT_LINKS cap with tel: and mailto: links. On a page with more than 32 contact links, emailProtectionLinks undercounts. The docs say this, so it is acceptable, but the cap can now push out real tel: or mailto: links that the NAP-consistency rules use. Consider a separate cap for obfuscated links.
  • (low) packages/utils/src/cloudflare-email.ts: isCloudflareEmailProtectionUrl matches on any host. That is intended, and the external link check should skip these too. A test with an external-host /cdn-cgi/l/email-protection link would pin that down, if there isn't one already.
  • (nit) cloudflareEmailContact takes decoded.split(/[?;]/)[0]. A ; is legal in an email local part, so this could truncate rare addresses. It is also unclear whether a plain mailto: is handled the same way, so check that the two behave alike.
  • (nit) The adapter.ts skip and the broken-links.ts skip duplicate the same check. That is fine for stored parses, but a shared comment or a pointer to one place would help whoever removes the legacy path later.

The CHANGELOG entry and docs look good.

@nc9

nc9 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Second review round (fixed in 46702f3):

  • Shared cap can push out tel: links (low): fixed. Obfuscated addresses now count against a 32-link cap of their own, separate from tel: and mailto:. A new parser test has 40 obfuscated links followed by a tel: link: 32 obfuscated are kept and the tel: link still comes through. The docs now say the count tops out at 32 per page.
  • External-host test (low): already there. parser/tests/contact-links.test.ts > "one on another host is not an external link either" checks that https://other.example/cdn-cgi/l/email-protection#… stays out of links in both extractors (html.ts and extractors/links.ts, the one the external link collection uses) and comes through as a contact link instead.
  • ; in the local part (nit): this is deliberate, so both cases behave alike. A plain mailto: contact goes through the same split(/[?;]/)[0] in extractContactLinks, and the obfuscated value follows the same rule. A quoted local part containing ; would be truncated the same way in both.
  • Duplicate skip in adapter and rule (nit): each comment already points at the other ("links/broken-links skips them the same way" in the adapter, and the rule's comment names the stored-parse case). Both go through the one helper, isCloudflareEmailProtectionUrl, so removing the legacy path later means deleting two lines that are easy to find.

nc9 added 3 commits October 16, 2026 05:28
With Cloudflare's email obfuscation on, every mailto: link and address
in the text becomes /cdn-cgi/l/email-protection, which answers an error
when requested, so links/broken-links listed one broken link per address
sourced from every page. The parser now leaves these out of the link
graph (so the crawl, the internal link check and the external link
check never request them) and carries each as the mailto: contact link
it stands for, decoded and flagged obfuscated. links/broken-links and
the internal link check also skip them in parses stored before this,
and the broken-links row reports details.emailProtectionLinks. Other
/cdn-cgi/ links (image resizing) are still checked.

Signed-off-by: Nik Cubrilovic <[email protected]>
…e decoder #811

The e2e fixture's hex payloads tripped the secret scan; they are now
encoded by a helper. isCloudflareEmailProtectionUrl skips the URL parse
for links without /cdn-cgi/, decodeCloudflareEmail refuses payloads
longer than any address, and the docs say how emailProtectionLinks
counts (per link per page, at most 32 contact links a page).

Signed-off-by: Nik Cubrilovic <[email protected]>
A footer of Cloudflare email-protection links could fill the 32-item
contact list and push out the tel: links local/nap-consistency reads.
Obfuscated links now count against a cap of their own.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/811-cf-email-protection-links branch from 46702f3 to 111ed09 Compare October 15, 2026 18:29
@claude

claude Bot commented Oct 15, 2026

Copy link
Copy Markdown

Reviewed the full diff. I didn't run the tests, only read the code.

The change is small and well scoped. isCloudflareEmailProtectionUrl matches only the exact /cdn-cgi/l/email-protection path (case-insensitive, optional trailing slash), so /cdn-cgi/image/... links are still checked. The tests cover that. The hex decoder bounds its input and rejects invalid UTF-8 and control characters. Obfuscated contact links get their own 32-item cap, so they can't push out tel: links. utils/src/nap.ts only reads scheme from mailto contacts, so the empty value on an undecodable payload is safe there.

  • (low) packages/audit-engine/src/adapter.ts:813 The skip only covers internal links (!link.isInternal returns first). A parse stored before this change can still hold an external email-protection link on another host, and the external checker may request it. The parser now drops these on any host, so this only affects old stored parses. Dropping the check from the external path too would make the behaviour symmetric.
  • (low) packages/parser/src/html.ts cloudflareEmailContact takes the first [data-cfemail] inside the anchor, so an anchor wrapping several obfuscated addresses reports only one. It's an edge case and harmless, but the emailProtectionLinks count is per anchor, not per address. The docs say "per link", so that is consistent.
  • (nit) packages/utils/src/cloudflare-email.ts The /\/cdn-cgi\//i pre-check before new URL is a useful fast path. A one-line comment saying it is there for speed would help.
  • (nit) The obfuscated?: "cloudflare" field on ContactLinkData is new in core-contracts. It's optional, so old stored parses stay compatible, and the broken-links rule handles a missing field.

Test coverage is good: unit, parser, rule and end-to-end tests for both the v1 and v2 engines and for stored old parses. I have no blocking concerns.

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.

links/broken-links reports Cloudflare email-protection links (/cdn-cgi/l/email-protection) as broken internal links

1 participant