Skip to content

tech-detect: a 5 MB page of unclosed <script openers takes about 12 s because every script-src signature rescans it #1456

Closed

Description

@nc9

Found in the review of #1450 and #1451; it is on main today and not caused by either.

What happens

A 5 MB page made of unclosed <script openers (<script <script <script ...) takes about 12 s of technology detection on a development machine; a normal 5 MB page takes about 0.5 s. Timing each signature on its own shows no single one dominates: most signatures that match a script src cost 0.1 to 1.2 s each (the top ones were clerk, replit, supabase, shortpixel, lovable, firebase), and they add up.

Where the time goes

The scriptSrc helper's html form, <script\s(?:[^>]{0,300}\s)?src\s*=\s*["']<url>, and other patterns that start at <script\s scan up to 300 characters after every opener. A page of 600,000 openers makes that about 200 million steps per signature, and there are roughly a hundred such signatures. The per-pattern bound is linear in the page, but it is multiplied by the number of signatures, and a hostile or broken page pays it on every one.

Acceptance Criteria

  • A 5 MB page of unclosed <script openers is detected in under 2 s, with the same technologies as before on ordinary pages
  • The script src values of a page are extracted once per page (quote-aware, linear) and the signatures that match a script src read that list, instead of each scanning the HTML for <script\s
  • The corpus check (squirrelscan-53 label) shows no loss of true detections
  • A hostile-input test at 5 MB covers unclosed openers, unbalanced quotes and a very long attribute run, with a time ceiling

Activity

  1. added
    size: M
    rules
    performance
    on Oct 31, 2026
  2. added theissue type on Oct 31, 2026
  3. nc9 commented on Nov 1, 2026

    @nc9
    ContributorAuthor

    Checked against main after v0.0.154. Ticked: criteria 2 and 4. Open: criterion 1, the 5 MB hostile case runs in about 0.5 s but the committed test asserts only a 6 s ceiling; and criterion 3, no corpus comparison is recorded in this issue. Leaving this open for those.

    nik

  4. added a commit that references this issue on Nov 2, 2026
  5. nc9 commented on Nov 2, 2026

    @nc9
    ContributorAuthor

    Ticked the corpus criterion. Corpus run on Boat (masked, by squirrelscan-53): 0 true detections lost, 0 status changes, 13 gains (animate-css via a single-quoted href the old regex missed); per-site time down 15.6 percent (p95 799 to 663 ms). The corpus has no real 5 MB page of unclosed script openers, so the first criterion (under 2 s on that page) stays open for the tightened time bounds in the open test PR.

    nik

  6. added a commit that references this issue on Nov 2, 2026
  7. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    Acceptance check against main 7c31d5b. The fix and tests are in v0.0.161 (the tests landed in 0cd2a5c, the single-parse change in 8c8528a and 9cc866b).

    # Criterion Result Evidence
    1 A 5 MB page of unclosed <script openers detects in under 2 s, same technologies on ordinary pages PASS packages/tech-detect/tests/tag-attr-1456.test.ts "hostile pages (5 MB)" > "script: unclosed openers" now asserts under 2,000 ms (it was 6 s) and no per-page budget overrun. I also timed the page by hand on main: 257 to 276 ms for <script , 236 to 246 ms for <script x=", 384 to 442 ms for <script a=' + newline. Same technologies: the real-markup tests in the same file and pattern-bounds.test.ts "bounded patterns still match real markup" pass, and the corpus comparison in the comments above shows 0 true detections lost.
    2 Script src values extracted once per page PASS (ticked earlier) tag-attr detectors read one parsed tag list
    3 Corpus check shows no loss PASS (ticked earlier) see the corpus comment above
    4 Hostile-input test at 5 MB with a time ceiling PASS (ticked earlier) same file, script, link, img and iframe shapes

    Ran on main: tag-attr-1456.test.ts (22 pass), tag-attr-bounds-1474.test.ts (12 pass), pattern-bounds.test.ts (5 pass).

    All four boxes are proven, so closing.

    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

    performancerulessize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions