Skip to content

Custom request headers reach every subdomain of the audited host: limit them to the audited origin #732

Closed

Description

@nc9

Summary

Custom request headers ([crawler] headers, -H, and the cloud setting Custom request headers) usually carry credentials: Web Bot Auth signatures, CF-Access-Client-Secret, API keys. Today squirrel sends them on the first request to any asset on the audited host or on any subdomain of it. An audit of example.com sends them to cdn.example.com, help.example.com, user-content.example.com, or any other subdomain a page's assets point at. That covers scripts, preloaded chunks, stylesheets, images, fonts, PDFs, and web app manifests and their icons. The docs describe this behaviour (docs/configuration/crawler.mdx, headers: "assets on the audited host and its subdomains"). It dates from custom request headers (#25), which applied them to asset fetches as well as pages.

A subdomain is not always run by the same party. It can be hosted user content, a SaaS CNAME (status page, help desk, a shop on a subdomain), or a dangling CNAME that someone else has claimed. Each of these gets the audit's credentials.

On a redirect that changes origin, safeRedirectFetch already drops every header that is not allowlisted. The gap is the first request. The third-party status checks (reliability/broken-resources) never carry the headers, so they are fine.

Where this happens on main (527d4f8):

  • packages/audit-engine/src/adapter.ts:1035-1038 and :1048-1050: resourceCheckOptions and scriptFetchOptions carry customHeaders. The CSS, image, font, PDF, sitemap, manifest and icon pools use the first; the script and preload pools use the second.
  • adapter.ts:3588 (isSameDomainResource) and packages/parser/src/extractors/scripts.ts:53 (isSameDomainScript): an asset goes into a headered pool when its host is the audited host or a subdomain of it.
  • adapter.ts:813: manifest links go through the same check. Manifest icons are already held to the manifest's own origin (web-app-manifest.ts:134).

Found during the review of #715 (web app manifest). That PR kept the existing rule rather than making manifests the one asset kind treated differently.

Acceptance Criteria

  • With a custom header set, an audit of https://example.com requests each asset kind on https://cdn.example.com without the custom header: script, preloaded chunk, stylesheet, image, font, PDF, web app manifest, and manifest icon. The same assets on https://example.com carry it. There is a fixture test for each pool.
  • Only the audited origin carries the headers by default. That is the scheme, host and port of the start URL after its redirects, so an apex start URL that redirects to www uses www. Another port or scheme on the same host does not get the headers.
  • A user whose assets need the headers on another host (a signed CDN, Cloudflare Access on assets.example.com) can name those hosts in squirrel.toml and with a CLI flag. Only the named hosts get the headers. Shell completions list the flag.
  • If a subdomain asset answers 401 or 403 to a request sent without the custom headers, it is reported as not checked, never as a broken resource. The message names the host, so the user knows which one to opt in.
  • Cloud audits follow the same rule, and the cloud Custom request headers setting says which hosts receive the headers.
  • docs/configuration/crawler.mdx (headers), docs/dashboard/crawl-settings.mdx and docs/guides/web-bot-auth.mdx describe the new scope and the opt-in. A CHANGELOG entry under behaviour changes says that subdomain assets no longer get the headers unless they are named.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsecuritysize: M

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions