Repository navigation
fix(audit-engine): external link check never requests action or token links, nor redirect hops into them (repo#2759) - #767
Conversation
d1fd79e to
ab0a9fa
Compare
|
Reviewed the engine changes: The approach is sound. Links that look like actions or carry tokens are filtered before any request, including the cloud bulk path. Redirects are now followed by hand. Old cached verdicts and stale rows from incremental crawls are suppressed. The reported URLs are masked.
Tests are added in both |
|
Review of #767 (external link check never requests action/token links). I read the diff and the egress helper. I didn't run the tests, and CI was still pending when I looked. I found no blocking problems. The approach holds up: filtering before the cache, the bulk checker and the local fetch means no path can send these links. Redirects are followed by hand and every hop goes through the egress guard.
Tests: there are new engine, rules and utils tests, which is good coverage for the core behaviour. I'd add two cases. One is a redirect that lands on a link-local or metadata IP. The other is a re-audit where the cache holds a stale verdict for a link that is now skipped. |
… links, nor redirect hops into them squirrelscan/repo#2759 The external link checker requested every external link an audit found, with HEAD then GET and redirect: "follow", so a third party's one-click unsubscribe link, magic sign-in link or signed download URL, where the URL is the credential, was requested, and so was any redirect into one. - checkCollectedExternalLinks splits the links with the internal link probe's rules (looksLikeAnAction on the URL, linkTextLooksLikeAnAction on any occurrence) before anything is sent: the not-requested ones never reach the local check or the cloud bulk checker, do not count against max_links, and are recorded in stats.externalLinkCheck as a count plus a sample of 50 (10 source pages each). - The checker follows redirects by hand (up to 20 hops, then "too many redirects" as before); a hop into an action or token link, or a non-http Location, is not followed and the 3xx is the answer. checkExternalLinks also refuses action URLs any other caller hands it. - links/broken-external-links reports them in a new info check, not-requested-external-links, never as working or broken; the over-cap count leaves them out. - The classifier moves verbatim from link-target-probe.ts to @squirrelscan/utils/link-actions (re-exported where it was), pure and dependency-light, so the cloud's dead-links service can apply the same rules server-side. Signed-off-by: Nik Cubrilovic <[email protected]>
…ollow no longer widens external text, mask tokens squirrelscan/repo#2759 From review: - An incremental re-audit copies a reused page's link rows from the earlier crawl, so a 404 an older engine stored for an unsubscribe link was still reported as broken. Both rule-data builders now leave out external rows that isNotRequestedExternalLink matches (URL, or the stored anchor text). - rel=nofollow on an external link marks a paid or untrusted link ("Buy on Amazon", "Follow us"), not an action: external text is checked as plain text only. - Redirects: only 301/302/303/307/308 are followed (300 and 304 are answers), and the limit is 20 followed hops. - The direct-call guard runs before the link cache, so an old cached verdict is not returned for an action URL. - The not-requested sample masks query values and token-like path segments (maskLinkTokens in @squirrelscan/utils/link-actions) and carries pageCount; the rule and dead-links counts leave the not-requested links out of the over-limit and no-results lines. - Docs say redirect protection applies to links squirrel checks itself. Signed-off-by: Nik Cubrilovic <[email protected]>
…nd token keys, merge masked collisions squirrelscan/repo#2759 From the second review: - An incremental crawl copies a reused page's link rows but not their appearances, so a stale verdict for a link left out only by its text ("Log out") had no text to match. The external phase now writes the appearances of the links it never requested (no row), so the rule-data builders can leave those rows out too. The re-audit test covers a text-only link; without the appearances it fails on v1 and v2. - maskLinkTokens also masks token-like or long query keys, matrix and encoded-slash parts, UUIDs and short mixed ids (file names keep their name), and is documented as a best effort. - Sample entries that mask to the same URL are merged, pages unioned. - Docs: the dead-links message, the over-limit second number, the 3xx table, the check list wording. Signed-off-by: Nik Cubrilovic <[email protected]>
…ps), tests for ordinary paths squirrelscan/repo#2759 Signed-off-by: Nik Cubrilovic <[email protected]>
… through the egress guard squirrelscan/repo#2759 The external checker had no address check on any hop. Its local requests now go through egressGuardedSend under the third-party probes' policy: public addresses only (private ones too when the audited site is itself private), never link-local or cloud metadata, http(s) only, pinned to the vetted address unless the transport pins (egressPinnedByTransport, passed from the pre-rules resource overrides). A refused first request leaves the link unresolved (never broken, never cached); a refused redirect hop is not followed and the redirect is the answer. Requests still carry only User-Agent and Accept. Tests (external-link-egress-2759): per-hop vetting by name and pinning with Host kept, redirects into private/metadata/link-local/file refused, a refused first request never sent or cached, header allowlist, and the phase pinning on the CLI but going by name when the transport pins. Signed-off-by: Nik Cubrilovic <[email protected]>
d80736a to
168da2d
Compare
|
Review of #767. I read the diff but did not run the tests, and CI was still pending when I looked.
Tests were added for the egress behaviour, the not-requested split, the rules and link-actions. The skip-before-request design, the manual redirect handling and the masking of reported URLs look sound overall. |
…rop a no-op escape CodeQL flagged squirrelscan/repo#2759 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of the core changes in The design is sound: a pre-filter before anything is sent, manual redirect following with a per-hop action check, and an egress guard on every hop. Findings:
No critical or high issues found in the parts I reviewed. |
…olicy; tests on loopback pass a private-site policy squirrelscan/repo#2759 requestFollowingSafeRedirects now always sends through egressGuardedSend: a caller that gives no policy gets DEFAULT_EGRESS (public addresses only, pinned), never an unguarded fetch. The audit's entry point still builds its own (private allowed for a private site, transport pinning in the container). Tests whose targets are on loopback pass allowPrivateNetwork: true, as a private site's audit does, and the CLI dead-links test's crawl is on localhost for the same reason (CI failed on its public example.com base once the guard refused 127.0.0.1). A new test pins the fail-closed default. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of #767 (external link check never requests action/token links, with egress-guarded manual redirects). I read the diff: the checker, adapter, link-actions move and docs. I did not run the tests, and CI was still pending when I looked. The design is sound. The skip happens before the cloud bulk checker and the cache are reached, redirect hops are re-vetted, and refused requests are never cached or reported as broken. The new tests cover the main paths.
|
…k cache and bulk checker #770 Follow-ups to #767's egress guard on the external link check: 1. A link whose address the policy refuses (a private, link-local or metadata address on a public site's page) was stored unresolved and left out of every report line. checkCollectedExternalLinks now records them in stats.externalLinkCheck (refused, refusedLinks: masked sample with pages, the same builder as the not-requested sample), and links/broken-external-links lists them in a refused-external-links info check, never as working or broken. 2. checkExternalLinks consulted the link cache and the bulk checker before the guard, so a verdict a private site's audit cached for the same URL could be served into a public site's report, and the URL sent to the cloud. A new refusedWithoutLookup (@squirrelscan/utils/public-egress) settles what the URL alone decides (scheme, allowHost, refused IP literal, metadata name, non-public name the policy does not allow) before either is asked. 4. Docs list the headers the check sends, Accept-Encoding included. Signed-off-by: Nik Cubrilovic <[email protected]>
Fixes squirrelscan/repo#2759 (private).
What changed
The external link checker requested every external link an audit found, with
HEADand thenGET(whenHEADfailed), usingredirect: "follow". That included a third party's one-click unsubscribe link, a magic sign-in link or a signed download URL, where the URL itself is the credential, and any redirect into one. The internal link probe already skips such links (#721). The external checker now uses the same rules.checkCollectedExternalLinks,packages/audit-engine/src/adapter.ts).splitNotRequestedExternalLinkssets aside every link for whichisNotRequestedExternalLinkis true: the URL failslooksLikeAnAction, or a page words the link plainly as an action ("Log out", "Unsubscribe", "Delete account").rel="nofollow"does not widen the text rule here, as it does for internal links. On an external link it marks a paid or untrusted link ("Buy on Amazon", "Follow us"), not an action.max_links.stats.externalLinkCheckrecords them asnotRequested(a count) andnotRequestedLinks: the 50 most-linked, each with 10 source pages and itspageCount, and its URL masked bymaskLinkTokens. That masks query values, token-like or long query keys, and token- or id-like path parts (including matrix parameters, encoded slashes and UUIDs) as…. It is a best effort for reports that may be published. Links that mask to the same URL are merged, with their pages combined.isNotRequestedExternalLinkmatches, by URL or by that anchor text.external-checker.ts).fetchUndecodedwithredirect: "manual".too many redirects. Bun's own limit was higher, and its error text differed.looksLikeAnAction, is not followed. The 3xx is the link's status, andredirectTargetis the Location that was not followed.checkExternalLinksalso refuses action URLs that any other caller hands it, before the link cache, the bulk checker or a local request, and returns them unresolved.egressGuardedSendunder the third-party probes' policy. With no policy given, the checker fails closed (DEFAULT_EGRESS, public addresses only); the audit's entry point always builds its own. What is left (refused links missing from the report, the cache and bulk checker running before the guard) is External link check: refused links vanish from the report, and the cache and bulk checker run before the egress check #770, and other CLI paths that follow redirects are tracked privately.egressPinnedByTransport, passed from the pre-rules resource overrides, as the hosted container sets it).links/broken-external-links): a new info check,not-requested-external-links, with the message templateN external link(s) were not requested because they look like actions (log out, unsubscribe) or carry a token or signature in the URL, so their status was not checked.pageCountwhen an item lists fewer source pages than link it, anddetails.listedwhen the sample is shorter than the count.links/dead-linkssaysNo external links were verified: all N look like actions or carry a token, so they were not requested.looksLikeAnAction,linkTextLooksLikeAnActionand their word lists move verbatim fromlink-target-probe.tstopackages/utils/src/link-actions.ts, exported as@squirrelscan/utils/link-actions, withmaskLinkTokensappended.isHttpOrHttpsUrl, so a Worker can use it.link-target-probe.tsre-exports both functions, so existing imports are unchanged.git diff --color-movedshows it as a move.Not changed, on purpose: the GET fallback
For a link that passes the filter, the checker still sends
GETwhenHEADanswers 400 or above, or errors. It does not switch to the internal probe's "GET only on 405/501". The internal probe can afford that because it first sendsHEADto a page the crawl fetched, to detect hosts whoseHEADis unreliable. The external checker has no such per-host control. Many third parties answerHEADwith 403 or 404 andGETwith 200, and the 403GETbody is what WAF detection reads. LimitingGETwould report working links as broken, and the filter already removes the URLs where a request is the danger. Most frameworks routeHEADto theGEThandler anyway.Cloud follow-up
The hosted service side (its own filter on entry and per redirect hop, and the paths that submit links without this engine) is tracked on squirrelscan/repo#2759, for a private PR after this merges and the gitlink is bumped.
@squirrelscan/utils/link-actionsis the shared rule set it will use: import those helpers, no second normaliser or word list.Acceptance criteria
/unsubscribe?token=…, a?sig=download URL and a "Log out" link, records zero requests to them: directly, through a short link that redirects into the unsubscribe URL, and through the bulk checker (packages/audit-engine/tests/external-links-not-requested-2759.test.ts).docs/configuration/external-links.mdx, with the "careful default" caveat and the scope of the redirect protection; plus the new check indocs/rules/links/broken-external-links.mdx.Verification
packages/audit-engine:external-links-not-requested-2759.test.ts(12 pass). It covers:packages/audit-engine:external-link-egress-2759.test.ts(7 pass, including the fail-closed default), against a real socket. Each hop is vetted by its own name and pinned to the vetted address with Host kept. A redirect into a private,169.254.169.254,metadata.google.internal,fe80::1orfile:target is not followed. A first request to a private address on a public site's audit is never sent, never broken and never cached. No request carries a header outside the allowlist. The audit phase pins on the CLI and goes by name when the transport pins. Against the previous head, 5 of the 6 fail.packages/audit-engine:link-checks-not-run-e2e,bulk-checker-unanswered-753,fetch-deadline,undecoded-probe-fetches,streaming-pre-rules-golden,streaming-rules-canonical-golden,link-probe-safety-2729andexternal-link-cap-2729pass. One run ofbulk-checker-unanswered-753hit the 5 s default timeout under load (load average about 4); it passed on 3 reruns, in about 400 ms each.packages/rules:external-links-not-requested-2759.test.ts(8 pass),link-checks-not-run.test.tsanddead-links.test.ts.packages/utils:link-actions.test.ts(5 pass), covering masking (token keys, matrix parameters, encoded slashes, UUIDs, short ids, file names, and ordinary paths and slugs that must keep their shape) and the moved rules.tsgo --noEmitinpackages/utils,packages/core-contracts,packages/audit-engineandpackages/rules: clean. The new test files andrules/src/types.tsare oxfmt-clean. oxlint reports nothing new.docs/:tangly check --strictpasses.Agent skill
No change needed.