Skip to content

feat(rules): add reliability/broken-resources and the Reliability category #703 - #714

Merged
nc9 merged 1 commit into
mainfrom
claude/703-broken-resources
Oct 12, 2026
Merged

nc9 merged 1 commit into
mainfrom
claude/703-broken-resources

Conversation

@nc9

@nc9 nc9 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the reliability/broken-resources rule and the reliability category (name "Reliability", group Performance, rule prefix reliability/).

The rule reads the statuses the asset phase records for every script, stylesheet and font the pages reference. It runs in HTTP-only audits and renders nothing.

  • Error: a first-party script or stylesheet answers 4xx/5xx, including a bare 503, 502 and 504. First-party is the same registrable domain as the site (tldts, private suffixes on), plus the site host and its subdomains: a site on www.example.com owns example.com/app.js and cdn.example.com/app.js, while a.vercel.app does not own b.vercel.app.
  • Warning: a third-party script or stylesheet, or any font, answers 4xx/5xx; or a request fails at the network level.
  • Info (unverified): 429, 430, a 503 with Retry-After, and a WAF or bot challenge are throttling or blocking, not broken.
  • Info (partial): a skipped fetch, a fetch cap that dropped referenced URLs, or an unmeasured resource kind is named in an unchecked-resources note, so a pass never claims full coverage.
  • One finding per resource URL, listing every page that references it.

Engine changes:

  • Scripts, stylesheets and fonts on any host other than the site host and its subdomains are collected into a separate externalAssets field and checked by status only (HEAD first, no body stored). The same-site maps and the size, compression and script rules are unchanged.
  • Those status checks are capped at RESOURCE_SIZE_LIMITS.MAX_EXTERNAL_ASSETS_TO_CHECK (50) per kind, and never above the caller's resourceCheckMaxItems, so an audit sends at most 150 extra requests. The cap is named in the docs, and URLs past it show in the partial note. They run only while the rule is enabled (same isRuleEnabled call and defaults as the runner): disable it and none are sent.

Security (credential leak and SSRF on the third-party probes):

  • No credentials to third parties. The probes drop customHeaders (Web Bot Auth, Authorization, Cookie, any [crawler] headers) and the prior-crawl cache: they send squirrel's User-Agent and Accept only, on the HEAD, the GET fallback and every redirect hop. The site's own assets keep the headers (fix(engine): resolve renamed item locators on a still-failing page #474 #494), and safeRedirectFetch still strips them when a redirect leaves the origin.
  • No requests to private networks. New @squirrelscan/utils/public-egress: egressGuardedSend is the per-hop send of safeRedirectFetch, so every hop, the first included, is vetted by vetEgressTarget before it is sent. It refuses non-http(s) schemes; private, loopback, link-local, CGNAT, documentation, benchmarking, multicast and reserved IP literals (decimal, hex, octal and short IPv4 spellings arrive canonicalized by the URL parser and are tested); IPv6 forms that embed one (mapped, translated, NAT64, 6to4, IPv4-compatible); the cloud metadata addresses and names; non-public names (localhost, *.internal, dotless); and any name that resolves (system resolver, memoized per asset phase, failures forgotten) to no address or to any refused one.
  • Pinned to the vetted address (DNS rebinding). A guarded hop never hands fetch the name: it connects to the IP that was vetted, with the original Host header and, over TLS, the original name as tls.serverName. Measured on Bun 1.3.14: the certificate is verified against serverName (a mismatch is ERR_TLS_CERT_ALTNAME_INVALID, wildcards follow the one-label rule), directly and through a CONNECT proxy, and keep-alive TLS connections are reused only for the same server name. tls.checkServerIdentity is not relied on: Bun does not block when it returns an Error. An answer that cannot be pinned (a name, a scoped IPv6 address) is never used, and a trailing root dot is dropped from the server name. The first vetted IPv4 address is tried, then the first vetted IPv6 one, and only when the connection was never made (ConnectionRefused, FailedToOpenSocket and the other connect-phase codes): a ::1-only localhost dev server (Vite on macOS) stays reachable, at most two addresses are ever tried, and a request that may have been received (a reset, a truncated answer) is never re-sent. Each redirect is resolved against the original URL, so every hop is vetted and pinned by its own name. ResourceCheckOverrides.egressPinnedByTransport lets a runtime whose fetch already resolves once and pins (the hosted egress proxy, which rewrites a plain-http Host from its absolute target) vet without pinning again; the CLI default pins. A site that is itself on a private network (localhost:3000, RFC1918, by the existing isNonPublicHostname) may probe private hosts, never link-local or metadata ones; an unknown base URL takes the strict policy. Redirect hops stay capped at 10 by safeRedirectFetch. A refused URL is never retried and reads as "not checked", never broken.
  • Status only. A HEAD below 400 ends the check; the GET fallback's body is cancelled unread.
  • Fetch budget. A refused probe is recorded as an answer (only the latency of hops actually sent can strike), never as an error strike that could mark a host as tarpitting. The refusal reads refused by the egress policy.
  • Documented limits: behind an HTTP_PROXY, a pinned plain-http probe goes out in absolute form with the address, so the proxy may answer with that address's default vhost (correctness, not reach); only the vetted address picked (IPv4 first) is tried. Two pre-existing gaps the review found (the sitemap-orphan pool sends custom headers to any host a sitemap lists; same-site pools follow a redirect to the metadata address) are tracked in squirrelscan/repo#2764.
  • Reviewed by an Opus security pass (two medium, five low, three nits: all fixed or documented above), a delta re-review (verdict ship; its four low nits fixed: 401/407 downgrade limited to sibling first-party hosts, local-use NAT64 and 192.0.0.192 always refused, rule gate defaults matched to the runner), an Opus review of the pinning (no hole, verdict ship; its trailing-dot and unpinnable-answer nits fixed), and a review of the address-fallback and fetch-budget backport (verdict ship; its stale-comment, scoped-IPv6 and aborted-signal nits fixed).
  • Private follow-up before the next gitlink bump: the cloud runtime must pass egressPinnedByTransport: true in its resource overrides, or hosted plain-http third-party probes reach the right IP with the wrong vhost.
  • Each asset records rateLimited (429/430, or 503 with Retry-After) and wafBlocked (403 or 503 with WAF headers, using the same detectWaf the link checker uses). Only those are unverified; a bare 503 stays broken.
  • Referenced URLs each cap dropped are counted per kind (assetCapDropped, computed by assetCapDroppedOf, unit-tested).
  • The budget-skip placeholder is the shared ASSET_FETCH_SKIPPED_ERROR constant, not a string literal in three places.

Category wiring: RuleCategory in core-contracts, the rules and report category mirrors, the rule loader, the rules index export, and the docs rules index and nav. The category count goes from 21 to 22 in README.md, docs/index.mdx and docs/rules/index.mdx, with a Reliability row in both category tables, and reliability is listed in the report category filters (docs/cli/report.mdx, docs/reports.mdx).

Golden gate (rebased on main 1e3842c, the 0.0.111 release, which includes pub#721): streaming-rules-canonical-golden.test.ts moves 101736 -> 101737 findings and 301 -> 302 tally rows. The rule adds one whole-crawl check, which is info on the harness (its empty assets carry no fonts or third-party lists), and its tally row is pinned. healthScore.overall stays 51.

Agent skill: yes, the squirrelscan agent skill (squirrelscan/skills) needs a change: its SKILL.md says "300+ rules in 21 categories", and it should know the Reliability category. The maintainer files that as a private issue.

Private follow-up (not a merge blocker): hosted report ingest validates RULE_CATEGORIES as a z.enum, so reliability must be added there, to the web rules slug list, and to the rule catalog in the gitlink-bump PR before the next CLI release.

Closes #703

Verification

bun install --frozen-lockfile
(cd packages/rules && bun test tests/broken-resources.test.ts)                         # 27 pass, 0 fail
(cd packages/audit-engine && bun test tests/broken-resources-fixture.test.ts)          # 13 pass, 0 fail
(cd packages/utils && bun test tests/public-egress.test.ts)                            # 112 pass, 0 fail (incl. a real-TLS pin test, CA made with openssl at run time)
(cd packages/utils && bun test tests/non-public-host.test.ts tests/url.test.ts)       # pass
(cd packages/audit-engine && bun test tests/streaming-rules-canonical-golden.test.ts)  # 1 pass, 0 fail
(cd packages/audit-engine && bun test tests/streaming-rules-golden.test.ts tests/streaming-pre-rules-golden.test.ts tests/link-probe-safety-2729.test.ts tests/external-link-cap-2729.test.ts)  # pass
(cd packages/audit-engine && bun test tests/asset-compression-capture.test.ts tests/resource-checker-416.test.ts tests/resource-checker-image-header.test.ts tests/undecoded-probe-fetches.test.ts tests/fetch-budget.test.ts)  # 43 pass, 0 fail
(cd packages/report && bun test tests/merged-message-numbers-2231.test.ts tests/locked-rules-coverage.test.ts tests/severity-and-groups.test.ts)  # 51 pass, 0 fail
bash scripts/test-changelog-extraction.sh         # OK
(cd apps/cli && bun test tests/rules/categories.test.ts tests/rules/loader.test.ts)    # 42 pass, 0 fail
(cd packages/rules && bun run typecheck)          # clean
(cd packages/audit-engine && bun run typecheck)   # clean
(cd packages/utils && bun run typecheck)          # clean
bun run scripts/test-suites.ts --check            # every test file covered
(cd docs && bun run check)                        # tangly check --strict: all checks passed

The touched packages define no format or lint script. oxfmt --check and oxlint (apps/cli's binaries) are clean on the new rule, egress, test and fixture files.

The egress fixture tests were A/B checked: with the header strip and the egress policy removed from the probe options, the public-site, private-site-redirect and custom-header tests fail (requests reach 127.0.0.1 and the metadata address, the secret header arrives); with the per-hop guard removed from fetchResource, the redirect test fails too. Fixture coverage: a public site's references to 127.0.0.1, localhost, [::1], 169.254.169.254, 10.0.0.1 and metadata.google.internal send zero requests (global fetch spy and server both see nothing); public-to-private, public-to-metadata and public-to-privately-resolving-name redirects stop before the private hop; a private site may probe 127.0.0.1 but its redirect to the metadata address is refused; third-party HEAD, GET fallback and redirect hops carry no custom headers while the site's own assets do; the rule disabled sends nothing; an unknown base URL is strict.

Acceptance criteria

  • A reliability category exists (name "Reliability", in the Performance group) and appears in reports, scoring and the docs rule index
  • Fixture: a page with <script src="/app.js"> where /app.js returns 404 produces an error finding naming the URL, the 404 status and the referencing page, in an HTTP-only audit (broken-resources-fixture.test.ts, real HTTP)
  • Fixture: a first-party stylesheet returning 500 produces an error finding (same fixture test)
  • Fixture: a third-party script returning 404, and a font returning 404, each produce a warning, not an error (same fixture test)
  • A resource answering 429, 503 with Retry-After, or a WAF challenge is reported as unverified (info), never as broken (fixture test covers the WAF challenge and the 503 with Retry-After; unit tests cover 429 and 430)
  • The same broken URL referenced from 5 pages produces one finding listing those pages, not 5 findings (unit test; the fixture test checks one URL across two pages)
  • When the asset fetch cap left referenced resources unchecked, the result says so (fixture tests: a resourceCheckMaxItems cap drops a stylesheet, and 51 third-party scripts stop at 50 requests; both results are partial with the cap named)
  • Broken images stay with images/broken-images and are not reported twice (the rule never reads images; unit test)
  • The rule has a docs page under docs/rules/reliability/

Known limits

  • WAF detection reads response headers only. A genuine 403 from a first-party asset behind a WAF fingerprint is reported as unverified rather than broken, which is the same bias the link checker has.
  • The 429, 430 and bare-503 classifications are unit tests, not fixture tests.
  • Third-party files add one status request each, at most 50 per kind per audit. They are not gated by [external_links].

Checklist:

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #714 (reliability/broken-resources). I read the diff only and did not run the tests or check the asset phase.

The rule is clear and well documented. It makes no new requests. Skipped fetches and unmeasured kinds are reported as partial instead of passing silently. The category wiring covers the core-contracts, rules and report mirrors, the loader, and the docs.

  • (medium) broken-resources.ts:isFirstParty — it treats only the exact host and its subdomains as first-party. If baseUrl is www.example.com, assets on cdn.example.com or the apex domain count as third-party. A broken first-party bundle there is then only a warning, so the merge gate won't catch it. The comment says this matches the asset collector's test. Please confirm that, or consider comparing registrable domains.
  • (low) verdictOf — a status-less error other than "skipped" is a warn. This relies on the asset phase using the literal string "skipped" for budget and tarpit skips. Any other skip reason would be reported as a network failure. A shared constant or enum would make this safer.
  • (low) verdictOf — only 429, 430 and 503 are treated as unverified. 502 and 504 are often transient too, and as first-party 5xx they will be errors. That is arguably correct, but the docs should say so explicitly.
  • (nit) KIND_LABEL maps each kind to its own name, so it can be dropped.
  • (nit) The pass message says "No same-site scripts…" but the rule also covers third-party resources. "No scripts, stylesheets or fonts to check" would be accurate.
  • (nit) Tests: I saw coverage of wiring and basic verdicts. Please check there are cases for the subdomain and apex first-party boundary, 503 on a first-party script, and a duplicate URL across pages (the sourcePages merge).

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review: reliability/broken-resources (#703)

I read the diff (adapter, asset-status, resource-checker, script-fetcher, the rule, docs and tests). I did not run the test suite, and CI was still pending when I looked. The design is clean: separate externalAssets keeps size and compression rules unaffected, the verdict logic reuses the shared rate-limit helpers, and a bare 503 stays an error.

  • (medium) packages/audit-engine/src/adapter.ts (~L940): the new externalCss, externalScripts and externalFonts checks pass every referenced third-party URL to checkResourceSizes with no explicit .slice(...), unlike the same-site lists and the sitemap list. Sites with many third-party assets get an unbounded set of extra outbound requests to hosts the user did not ask to audit. assetCapDropped suggests resourceCheckOptions caps this internally. Please confirm that, and add a test for the external cap. Otherwise add an explicit limit.
  • (low) docs/rules/reliability/broken-resources.mdx says the rule "makes no extra requests". The PR does add status requests for third-party scripts, stylesheets and fonts, which the page itself says later ("checked by status only"). Reword so the two statements agree. The comment at the top of broken-resources.ts has the same tension.
  • (low) packages/rules/src/reliability/broken-resources.ts isFirstParty: this duplicates the collector isSameDomainResource and isSameDomainScript logic. If the two ever disagree (for example, www. vs apex handling), a resource can be fetched as same-site but classed as third-party here, which silently downgrades an error to a warning. Export and reuse one helper, or add a test for the apex/www case.
  • (low) assetCapDropped computes occurrences.size - results.length. The comment admits that budget-skipped rows still count as fetched. That is fine because they surface as unchecked. A cap that dedupes differently from the occurrence map would under- or over-count, though, so a unit test on the arithmetic would help.
  • (nit) PreFetchedAssets repeats the same eight-line mapping for scripts, css and fonts (externalAssets and resourceSizes). A small helper would cut about 60 lines.
  • (nit) AssetCapDropped is declared between the doc comment for PreFetchedAssets and the interface itself. This detaches that comment from its interface.
  • (nit) docs/docs.json nests the Reliability group inside the Performance rules group, while docs/rules/index.mdx lists it as its own card. That is consistent with the "performance" score group, but check that the nav renders as intended.

Test coverage is good: unit tests for the rule, category count updates, and an HTTP fixture test covering 404, 500, third-party, font, WAF, and the 503 split on Retry-After. I would add a test where externalAssets is large enough to hit the cap.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer review (2026-10-12)

Verdict: needs fixes (medium). Reviewed at head 07ffeb2 against main 2dca3b9. Main CI is green at that sha, so the red checks below come from this PR.

Acceptance criteria (#703)

8 of the 9 boxes are met.

  • AC1 is partly met. The category is wired: packages/rules/src/categories.ts, packages/report/src/categories.ts, RuleCategory in core-contracts, the loader, plus a docs card and nav entry. But the category counts were not updated (fix 2).
  • AC2-AC4: covered by packages/audit-engine/tests/broken-resources-fixture.test.ts ("404 script, 500 stylesheet, third-party 404 and font 404 ..."). It runs the real asset phase over HTTP.
  • AC5: covered by the fixture test "a WAF challenge is unverified, and 503 splits on Retry-After". 429 and 430 are covered by unit tests.
  • AC6: covered by the unit test "one URL referenced from five pages yields one finding listing all five pages".
  • AC7: covered by the fixture test "a stylesheet fetch cap drops referenced URLs ...".
  • AC8: covered by the unit test "broken images are left to images/broken-images".
  • AC9: docs/rules/reliability/broken-resources.mdx.

Fixes

  1. The golden gate fails both "Audit engine golden tests" and "CLI tests". The apps/cli tests step itself passes (2975 pass, 0 fail). The CLI job is red because its "Audit engine tests" step runs the golden file again.
    • File: packages/audit-engine/tests/streaming-rules-canonical-golden.test.ts.
    • expect(v1.findings.length).toBe(101736); (line 154): CI got 101737. reliability/broken-resources is site-scoped and adds exactly one whole-crawl check. Raise the number by 1. Add a comment line in the existing style: // 101736 -> 101737: reliability/broken-resources is site-scoped and adds one whole-crawl check (#703). <its status on the fixture>.
    • expect(v1.perRuleTally.length).toBe(301); (line 176) is the next assertion, so it fails as soon as the first one is fixed. Raise it by 1 and extend the tripwire comment with 301 -> 302 reliability/broken-resources.
    • These numbers are relative to the main you rebase on. Other rule PRs edit the same two lines, so after any merge, rebase and read them again.
    • Verify with cd packages/audit-engine && bun test tests/streaming-rules-canonical-golden.test.ts (one file, about 25 s). healthScore.overall must stay 51, or the comment must explain why it moved.
  2. Change the category count from 21 to 22 everywhere it appears.
    • README.md:28 and README.md:66.
    • docs/index.mdx:109, :226 and :252.
    • docs/rules/index.mdx:6.
    • Add a Reliability row (1 rule) to the category tables in README.md and docs/index.mdx.
    • Update the comment in packages/core-contracts/src/index.ts ("a coarse layer above the 23 categories" becomes 24).
  3. First-party should mean the same registrable domain, as New rule: broken scripts, stylesheets and fonts (no render needed) #703 specifies. Today isFirstParty (like the collector's isSameDomainResource/isSameDomainScript) accepts only the exact host and its subdomains. So a site at www.example.com whose /app.js lives on cdn.example.com or example.com gets a warning instead of an error, and that is the main deploy-breakage case.
    • Compare registrableDomain() on both sides. It is exported from packages/rules/src/content/dev-leakage.ts and uses tldts with private domains on.
    • Add tests for www-to-apex and for a cdn subdomain.
  4. Fix the docs.
    • The page says "It makes no extra requests", and the header comment of broken-resources.ts says "no new requests". Both are no longer true now that third-party assets get a status request each. Reword both.
    • Quote the message template {count} first-party script or stylesheet(s) answer with an error status instead of the filled 1 first-party script ....
  5. Third-party request volume. externalCss, externalScripts and externalFonts go to checkResourceSizes with no explicit slice. The only limit is the default MAX_RESOURCES_TO_CHECK of 500 per pool, which allows up to 1,500 new third-party requests per audit, plus retries. External link checking does not gate them either.
    • Add an explicit, lower per-kind cap, for example 50, with a test that hits it.
    • Name the cap in the docs.
  6. Nits from the review bot that are still open.
    • AssetCapDropped sits between the PreFetchedAssets doc comment and its interface, so that comment now documents the wrong type.
    • The three external mappings repeat the same 8 lines each; a small helper would remove that.
    • There is no unit test for the assetCapDropped arithmetic.
    • verdictOf relies on the literal string "skipped".
    • The docs should say that 502 and 504 count as broken.

PR hygiene

  • CHANGELOG: add one line under ## [Unreleased] / ### Added, ending with squirrelscan/squirrelscan#703, as recent merged PRs do.
  • PR description: add a line saying whether the squirrelscan agent skill (squirrelscan/skills) needs a change. It does: it states the category count.
  • Attribution:
    • Remove the Co-Authored-By: and Claude-Session: trailers from every commit, and keep Signed-off-by:.
    • Remove the "Generated with Claude Code" footer and the session URL from the PR body.
    • No attribution lines of any kind go in commit or PR text.
  • Docs: quote message templates with placeholders, never filled examples. No em-dashes.

Merge order

This PR goes first, because it creates the reliability category. #719 and #720 are stacked on its first commit, f9cf073.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of the reliability/broken-resources rule and the external asset checks. The rule logic reads cleanly and the verdict split (fail, warn, unverified, unchecked) is sensible. I only had time to read the rule, asset-status.ts and the engine diff, so I did not review the test files or docs.

  • (high) packages/audit-engine/src/adapter.ts:905-927 — resourceCheckOptions carries config.crawler.headers as customHeaders. The new externalCss, externalScripts and externalFonts checks reuse those options, so those headers (Authorization, cookies, Web Bot Auth signatures, per fix(engine): resolve renamed item locators on a still-failing page #474 #494) are now sent on the first request to arbitrary third-party hosts such as CDNs, analytics and font providers. safeRedirectFetch only strips secret headers on cross-origin redirects, not on the initial request. Before this PR the checks only fetched same-site URLs. Build separate options for the external checks with no customHeaders. A test asserting that third-party requests carry no custom headers would pin this.
  • (low) broken-resources.ts:82-83 — isFirstParty treats any host sharing the registrable domain as first-party, including user-controlled subdomains on private suffixes missing from tldts. This is documented, so I'm only flagging the edge case. The impact is a warning becoming an error.
  • (low) adapter.ts assetCapDroppedOf — it counts referenced URLs minus fetched rows, but externalAssetLimit is also capped by maxResources. Please check that the dropped count stays correct when maxResources is smaller than the 50 default. A test for that case would help.
  • (nit) resource-checker.ts — the wafBlockedFlag import sits between the utils imports. Move it to the local-import group to match the file's style.

@nc9
nc9 force-pushed the claude/703-broken-resources branch from 18bf19b to 4a8b5e4 Compare October 12, 2026 19:30
@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of the diff, focused on the egress guard, the asset-phase changes and the engine wiring. I did not run the tests, and CI was still pending when I looked.

  • (medium) packages/utils/src/public-egress.ts: the guard is not DNS-rebinding safe. The header comment says so openly and the exposure is limited to a HEAD or one-byte GET with no body read. A hostile page can still make the CLI send a status probe to an internal address, for example a rebinding hostname whose DNS answers public to the guard's lookup and private to fetch's own lookup. I'm not asking for a fix in this PR. Please make sure the docs for reliability/broken-resources (docs/rules/reliability/broken-resources.mdx) say this too, and open a follow-up issue to pin the vetted IP.
  • (low) packages/audit-engine/src/adapter.ts: externalScripts, externalCss and externalFonts collect every distinct third-party URL across the crawl. Only the first 50 per kind are probed, but the occurrence maps themselves have no bound, unlike MAX_TRACKED_INTERNAL_LINK_TARGETS. A page set that generates thousands of unique third-party URLs would grow these maps without limit. Consider capping how many distinct URLs get tracked, while still counting the dropped ones so assetCapDropped stays accurate.
  • (low) packages/audit-engine/src/adapter.ts: the isRuleEnabled call in fetchAssetsFromOccurrences copies the runner's default handling by hand. The comment says the two must agree, but nothing enforces it. A small test that fails if the runner's enable/disable semantics change would stop them drifting apart.
  • (nit) public-egress.ts: isNonPublicIpv4 and isAlwaysRefusedIpv4 both list the metadata addresses. One shared constant check would be easier to maintain.

The IPv6 embedding forms (mapped, NAT64, 6to4) are handled carefully. Dropping customHeaders and the prior-crawl cache for third-party probes is the right call. The new code in public-egress.ts and the fixtures in packages/audit-engine/tests/ are well covered by tests.

@nc9
nc9 force-pushed the claude/703-broken-resources branch from 4a8b5e4 to 4355cd3 Compare October 12, 2026 19:50
@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #714 (reliability/broken-resources). I read the diff in full but did not run the code or the tests. CI was still pending when I looked. The design is careful, and the egress guard is the strongest part: it checks every redirect hop, pins the vetted address, strips custom headers, covers the IPv6-embedded IPv4 forms and the metadata addresses, and is off when the rule is disabled. I found no blocking issues.

  • (low) docs/rules/reliability/index.mdx: the last line ("See Core Web Vitals for how an agent works through a report") looks copy-pasted from the Performance index and does not fit a Reliability page. Please replace it or drop it.
  • (low) docs/rules/performance/index.mdx and docs/rules/index.mdx: the Reliability card appears in the Performance index. That fits the group: "performance" mapping, but it is not obvious. Also, both the card and the category description say "Runtime errors, broken resources and failed requests", while the only rule covers broken resources. Narrow the description, or say that more rules are planned.
  • (low) Category counts: the docs, README and index.mdx go from 21 to 22, while the tests and core-contracts go from 23 to 24. This difference existed before the PR, but it is worth checking that the public count is meant to be 22.
  • (low) packages/utils/src/public-egress.ts (pickAddress): only one address is tried, IPv4 first. A host whose A record is dead while its AAAA works (or the reverse) is reported as an unreachable-resource warning. The comment says this is deliberate. Because the failure shows up as a finding, a fallback to a second vetted address could cut false warnings, and it would be cheap to add.
  • (low) resource-checker.ts (statusOnly GET path): the body is cancelled unread and the controller aborted. That is fine. Please confirm a test covers a HEAD that returns 405 followed by a GET that returns 200, so a server that refuses HEAD does not produce a false "broken" result.
  • (nit) packages/audit-engine/src/adapter.ts: the isRuleEnabled(...) call copies the runner's defaults (enable ?? []). The comment says they must stay in sync, so consider exporting a shared helper from the runner instead of duplicating the defaults.
  • (nit) docs/configuration/crawler.mdx: the rewrapped paragraph has one very long line. It reads fine as rendered.
  • (nit) Test coverage looks thorough (the egress unit tests, the fixture test, the rule tests and the golden update). A test with a real redirect from a public host to a private address through safeRedirectFetch would complement the mocked ones.

@nc9
nc9 force-pushed the claude/703-broken-resources branch from 4355cd3 to e15a193 Compare October 12, 2026 20:31
@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of the reliability/broken-resources rule and the third-party status probes. I read packages/rules/src/reliability/broken-resources.ts and packages/utils/src/public-egress.ts in full. I did not read the rest of the diff (resource-checker.ts, script-fetcher.ts, adapter.ts, the docs). I ran no tests, and CI was still pending when I looked, so confirm it goes green.

No blocking problems found in what I read.

  • (low) public-egress.ts:301 CONNECT_FAILURE_CODES is matched on error.code only. The header comment says this was measured on Bun 1.3.14. If another runtime reports these errors differently, the fallback to the second address silently stops working, and a ::1-only dev server then fails as a network error. A test that fakes each code would show the fallback still works, and a comment naming the runtimes that were checked would help.
  • (low) public-egress.ts:31-34 Behind HTTP_PROXY, a pinned plain-http probe can read the default vhost at the vetted address, so it can report 404 for an asset that is fine. The rule would then raise a first-party error for a file that exists, which is a false positive and not just a "correctness" cost. Consider skipping the pin, or treating the probe as unchecked, when a proxy is configured and the request is plain http.
  • (low) broken-resources.ts:91-92 host.endsWith(\.${site.host}`)` and the registrable-domain match treat any subdomain of the site's registrable domain as first-party. On a shared-hosting site whose suffix is missing from the private-suffix list, this widens first-party status to hosts the site does not own. The impact is only that a failure shows up as an error and not a warning, so I left it low.
  • (nit) public-egress.ts:96-98 METADATA_IPV4 lists 192.0.0.192, and isNonPublicIpv4 already refuses all of 192.0.0.0/24. The isAlwaysRefusedIpv4 path is the one that keeps it refused on private-network sites, so the entry is not dead, but a short comment would say why.
  • (nit) broken-resources.ts:262-312 The notChecked message counts unmeasured.length as the number of kinds, while the other parts count resources. The summary is readable, but the numbers are different units.

Tests are present for the egress guard and the rule, and the golden test is updated. I would add a case for an IPv6 ::ffff: form that embeds a metadata address, and one for a redirect from a public host to a private address on a private-network site (link-local should still be refused).

…egory #703

A page can answer 200 while the script or stylesheet it depends on returns
404 or 500, usually because a deploy deleted the hashed bundle that cached
HTML still references. No rule reported it.

reliability/broken-resources reads the statuses the asset phase records,
with no render:

- error: a first-party script or stylesheet answers 4xx/5xx. First-party is
  the same registrable domain as the site (tldts, private suffixes on), plus
  the site host and its subdomains, so www.example.com owns example.com and
  cdn.example.com while a.vercel.app does not own b.vercel.app.
- warn: a third-party script or stylesheet, or a font, answers 4xx/5xx, or a
  request fails at the network level.
- info: 429, 430, 503 with Retry-After, a WAF challenge on a 403/503, or a
  401/407 to the credential-less probe of a sibling first-party host is
  unverified, never broken. A bare 503 stays broken.
- info: a fetch the budget skipped, a URL a cap dropped, a URL the egress
  policy refused, or an unmeasured kind makes the result partial.
- one finding per resource URL, listing every referencing page.

Third-party scripts, stylesheets and fonts are status-checked into a separate
externalAssets field, only while the rule is enabled, capped at
RESOURCE_SIZE_LIMITS.MAX_EXTERNAL_ASSETS_TO_CHECK (50) per kind and never above
the caller's item cap. Those probes:

- carry none of the audit's custom or Web Bot Auth headers, only User-Agent
  and Accept, on every request and redirect hop;
- reach public addresses only, checked before every hop by the new
  @squirrelscan/utils/public-egress guard (resolve once and refuse private,
  loopback, link-local, CGNAT, reserved, multicast and metadata addresses,
  including IPv6 forms that embed one, and decimal/hex/octal IPv4 spellings).
  A site that is itself on a private network may probe private hosts, never
  link-local or metadata ones;
- connect to the exact address that was vetted, with the original Host header
  and TLS server name (Bun checks the certificate against the server name), so
  DNS rebinding cannot move a request. The first vetted IPv4 address is tried,
  then the first vetted IPv6 one, only when the connection was never made
  (a `::1`-only localhost dev server stays reachable; nothing is re-sent).
  ResourceCheckOverrides.egressPinnedByTransport lets a runtime whose fetch
  already pins (the hosted egress proxy) vet without pinning again;
- are status only: a HEAD below 400 ends the check, a GET body is never read.
  A refusal is recorded in the fetch budget as an answer, never a tarpit
  strike against the host.

The same-site maps and the size, compression and script rules are unchanged.
rateLimited and wafBlocked are carried on ResourceSizeData and
ScriptContentData, and assetCapDropped counts referenced URLs each cap left
unfetched. The budget-skip and egress-refusal placeholders are shared
constants.

Adds the Reliability category (group Performance) to RuleCategory, the rules
and report category mirrors and the loader. Docs: a category page and a rule
page under docs/rules/reliability/, the nav, the category count 21 -> 22 with
a Reliability row in README.md and docs/index.mdx, and the custom-headers
pages say third-party status checks never carry them.

Golden gate: 101736 -> 101737 findings and 301 -> 302 tally rows (one
whole-crawl check, info on the harness's empty assets); healthScore.overall
stays 51.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the claude/703-broken-resources branch from e15a193 to 6ccecb8 Compare October 12, 2026 21:23
@github-actions

Copy link
Copy Markdown
Contributor

Auto-review did not complete

The claude-review job failed before posting a review. This PR has not been auto-reviewed. Run a review manually (/review) before merging.

  • Result: success / is_error=true after 1 turns, 0 permission denial(s), $0.00
  • Job log

Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal):

Show partial review

You've hit your session limit · resets 10:10pm (UTC)

@github-actions

Copy link
Copy Markdown
Contributor

Auto-review did not complete

The claude-review job failed before posting a review. This PR has not been auto-reviewed. Run a review manually (/review) before merging.

  • Result: success / is_error=true after 1 turns, 0 permission denial(s), $0.00
  • Job log

Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal):

Show partial review

You've hit your session limit · resets 10:10pm (UTC)

@nc9
nc9 force-pushed the claude/703-broken-resources branch from e212e01 to 6ccecb8 Compare October 12, 2026 21:34
@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #714: reliability/broken-resources. I read the engine, checker, egress guard and rule diffs. I did not run the tests, but CI is green (the claude-review check was still pending). I have no (high) or (critical) findings. The egress guard is careful: it vets every hop, pins the vetted address, strips credentials from third-party probes, and refuses metadata addresses even for private sites.

  • (medium) packages/utils/src/public-egress.ts (pinning header comment): behind HTTP_PROXY, a pinned plain-http probe can read the default vhost of the address, because the proxy takes Host from the absolute-form URL. The comment says this is a correctness cost only, but it can produce false 404s/403s, which this rule reports as warnings or errors. Consider skipping the pin when a proxy is configured and vetting by name, or reporting these probes as unverified. Add a test for the proxy case.
  • (low) resource-checker.ts (statusOnly HEAD short-circuit): a HEAD below 400 returns without a GET. Some CDNs answer HEAD 200 for deleted objects, and some answer HEAD 404 where GET works. The 4xx case falls through to GET, which is good. The 200-on-HEAD case is an accepted false negative; say so in the rule docs.
  • (low) adapter.ts (externalAssetLimit): the cap is per kind and the three kinds run concurrently. The concurrency: 5 setting is shared with the other pools, so confirm the fetch budget (perf/total-byte-weight: loading=lazy images counted into the initial page weight #1252) also covers these probes. A page with many third-party hosts will take a DNS lookup each.
  • (low) public-egress.ts (orderAddresses): only the first IPv4 and first IPv6 address are tried. A multi-A name where the first record is down reads as a network failure (warning) while the site may be fine. This is fine as a tradeoff, but it is worth a test that pins the behaviour.
  • (low) broken-resources.ts (isFirstParty): registrable-domain matching makes sibling hosts (cdn.example.com) error-level. For multi-tenant private suffixes not in the tldts list, an asset on another tenant's host would be escalated to an error. Consider a rule option to override.
  • (nit) resource-checker.ts: the fetchResource(..., options) call sites were reformatted as }, options) and will trip the formatter. Run the formatter.
  • (nit) adapter.ts: externalAssets is absent when the rule is off, but assetCapDropped is always set. Add a one-line comment saying so in the type docs.
  • (nit) The PR is about 3k lines across engine, utils, rules and docs. Splitting the egress guard (public-egress.ts) into its own PR would make it easier to review as security-sensitive code.

Test coverage: there are fixture tests for the rule and the engine, and unit tests for public-egress. I would add cases for a redirect from a public host to a private one on the HEAD→GET fallback, and for the 304/prior-cache path being skipped on external probes.

@nc9
nc9 merged commit 0c733ec into main Oct 12, 2026
26 of 30 checks passed
@nc9
nc9 deleted the claude/703-broken-resources branch October 12, 2026 22:42
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: broken scripts, stylesheets and fonts (no render needed)

1 participant