Skip to content

Rendered audits miss scripts the server HTML references when client code removes them after hydration #1769

Closed

Description

@nc9

What happens

In a rendered (cloud or render-mode) audit, script discovery and secret scanning read the DOM snapshot taken right after domcontentloaded. Some frameworks remove server-rendered head scripts once hydration finishes. TanStack Router's Script component, for example, returns null after useHydrated(), so React drops the server nodes. Whether the audit sees those scripts then depends on whether the snapshot lands before or after hydration.

Observed on our own test site: the server HTML of a product page contained <script src="/_fault/shop-config.js"> and an inline script, and curl returned both. A slow render (about 1.5 s) stored a DOM without them. As a result:

  • the external script was never fetched;
  • security/leaked-secrets did not report a key the server shipped to every visitor;
  • perf/critical-request-chains and perf/unminified-js stopped listing the script.

A fast render (about 0.5 s) of the same build kept them. A later run of the same page reused the slow render from the render cache, so it repeated the miss.

A script the server sends is public, whether or not client code later removes it from the DOM, so it has to be audited.

Acceptance Criteria

  • For a rendered page, the scripts that are fetched and scanned (external src and inline bodies) are the union of those in the server HTML and those in the rendered DOM.
  • security/leaked-secrets reports a secret in a script that only the server HTML contains, and the finding names the page.
  • Rules that list page scripts (critical request chains, unminified JS, render-blocking) see a server-HTML-only script at least once, as a server-sent resource. Each rule decides whether a removed script still counts for its own purpose, and the docs say which.
  • An engine-level test uses a local fixture whose served HTML includes a script and whose rendered DOM does not. It covers both the v1 and the streaming engine.
  • The result does not depend on render timing: the same page gives the same script set for a fast and a slow render.

Activity

  1. added
    bug
    on Nov 11, 2026
  2. added theissue type on Nov 11, 2026
  3. nc9 commented on Nov 12, 2026

    @nc9
    ContributorAuthor

    Not closed after v0.0.179 (https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.179). Local renders audit the union of server and rendered scripts (parser, engine and e2e tests). Still open: the hosted render path (private repo#4022) and rule-level tests that critical-request-chains, unminified-js and render-blocking see a server-only script. The change that shipped is 7f8598e.

    nik

  4. added
    rules
    size: M
    on Nov 12, 2026
  5. nc9 commented on Nov 13, 2026

    @nc9
    ContributorAuthor

    Shipped in v0.0.179. Implemented in 7f8598e (an ancestor of the v0.0.179 tag), and described in that release's CHANGELOG entry for #1769.

    nik

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

    bugrulessize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions