Skip to content

fix(tech-detect): restore Klaviyo loader recall - #1463

Closed
WilliamK112 wants to merge 3 commits into
squirrelscan:mainfrom
WilliamK112:codex/klaviyo-script-recall-1457
Closed

WilliamK112 wants to merge 3 commits into
squirrelscan:mainfrom
WilliamK112:codex/klaviyo-script-recall-1457

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • restore Klaviyo detection for unquoted and long-attribute script tags, lazy data-src, preload links, inline .src loaders, and proxied collected URLs
  • keep every new URL signature anchored while scanning only executable/resource markup, excluding anchor links, escaped code samples, and commented-out tags
  • add regression fixtures with and without attached script bodies, plus release notes and technology documentation

Closes #1457.

Verification

  • bun test ./packages/tech-detect/tests/klaviyo-script-recall-1457.test.ts — 6 pass
  • bun test ./packages/tech-detect/tests/klaviyo-script-recall-1457.test.ts ./packages/tech-detect/tests/klaviyo-shopify-payments-1447.test.ts ./packages/tech-detect/tests/pattern-bounds.test.ts — 20 pass
  • bun test ./packages/tech-detect/tests — 425 pass
  • bun run typecheck in packages/tech-detect — pass
  • oxlint on the changed TypeScript files — pass

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).

Docs: updated docs/cloud/technologies.mdx and CHANGELOG.md.
Skill: none.

nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: aa9e382

Verdict: pending maintainer review. Thank you for picking up #1457. The recall cases are well chosen and the tests are good, but one new pattern is quadratic on a page of repeated <script> tags, which this repo treats as a blocker for tech-detect patterns. CI is green (all checks pass or are skipped by design) and the DCO sign-off is present.

Findings, most severe first:

  1. High: the inline loader pattern in packages/tech-detect/src/fingerprints/other.ts (^<script\b[^>]{0,65536}>[\s\S]{0,16384}?\b[A-Za-z_$][\w$]{0,63}\.src\s*=\s*["']...) is quadratic. pageMarkup joins tags with newlines, so every <script> opener is a line start where ^ matches, and each start then scans up to 16,384 characters ahead with an identifier attempt at every position. A read-only probe of this exact regex on 2 MB of repeated <script>\n took about 9.3 s, and 2 MB of <script>a.b.c.d.e.f.g.h\n took about 3.5 s. A hostile page can stall an audit this way. Suggested direction: drop the regex for this case and find .src = loaders in the script bodies that pageMarkup already isolates (a linear indexOf scan), or anchor the loader pattern to the body text only and bound the total work per page. pattern-bounds.test.ts should get a repeated-opener case for it (the existing test did not catch this one, so please check which openers it feeds).
  2. Low: the quoted alternatives require the URL right after the quote, so src=" https://static.klaviyo.com/..." (leading space, which browsers trim) is still missed. Optional.
  3. Low: the inline pattern can match across script boundaries, since [\s\S] reads into later tags of the markup. It still needs a .src = "<klaviyo url>" assignment, so the false-positive risk is small, but a body-level scan would remove it.

Checked and fine: the script-url and <script>/<link> patterns stay anchored and tag-bounded, comments, anchors and escaped samples are excluded by pageMarkup (confirmed in detect.ts), the CHANGELOG entry and docs/cloud/technologies.mdx are updated, no new dependency, and the PR is scoped to #1457.

nik

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review. Addressed in 37cdc95:

  • Replaced the cross-markup inline-loader expression with a line-bounded body expression: ^(?!<)[^\\r\\n]{0,16384}?.... pageMarkup emits each retained tag and inline body as separate newline-delimited parts, so tag lines are rejected and the scan cannot cross into another part.
  • Added the two reported 2 MB repeated-line probes directly against the Klaviyo loader pattern. Both complete together in about 7 ms locally, with a 400 ms per-case assertion.
  • Added the repeated forms to the shared opener coverage.
  • Accepted browser-trimmed whitespace inside quoted src/href values and added a regression fixture.

Validation: all 427 tech-detect tests pass; package typecheck and oxlint pass.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Follow-up 1dc03c3 moves the #1457 release note under ## [Unreleased]; the v0.0.152 tag was published after the original PR run, so that released section is now kept byte-for-byte unchanged. scripts/check-released-changelog.sh passes locally against the PR base and v0.0.152 tag.

nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 1dc03c3

Verdict: the earlier findings are addressed; ready for maintainer review. Thanks for the quick turnaround.

Previous review, point by point:

  1. High (quadratic inline loader): addressed. packages/tech-detect/src/fingerprints/other.ts now uses ^(?!<)[^\r\n]{0,16384}?\b...\.src\s*=\s*["']<url>, which cannot cross a line and rejects tag lines. I probed the same regex read-only on about 2 MB of repeated <script> lines, 60-character identifier lines, dotted runs and .src runs. Each finished in under 30 ms. The new Klaviyo loader pattern bounds test and the extra openers in pattern-bounds.test.ts cover the repeated-line case.
  2. Low (leading space inside a quoted src): addressed by KLAVIYO_ATTR_VALUE (\s* after the quote), with a regression test.
  3. Low (match across script boundaries): addressed, since the line-bounded pattern cannot read into a later part.

Checked and fine: the CHANGELOG entry is under ## [Unreleased] and the released v0.0.152 section is untouched. docs/cloud/technologies.mdx is updated, there is no new dependency, the scope stays on #1457, and CI is green on this head (skipped jobs are by design). The one residual is that PR #1464 (a maintainer PR) adopts this change for #1457, so the maintainer will decide which of the two lands.

nik

@nc9

nc9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Thank you William, the loader recall fix is going in with your three commits and authorship intact (aa9e382a, 37cdc95e, 1dc03c38), as part of the next release batch. We add a maintainer commit on top: the inline-loader check now stops at the end of its own script (1 MB of empty script tags went from about 4 s to about 0.1 s here), only a rel=preload or rel=modulepreload link counts as a loader, there is a bounded-time test for the hostile case, and the changelog names the known limits. Your bound tests and the leading-space fix are kept and pass against the final pattern. The 23-bundle real-library comparison shows 0 diffs. This PR will be closed with the new SHAs once the release is out.

nik

@nc9 nc9 mentioned this pull request Nov 1, 2026
@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Landed in v0.0.153 as 18310961 52d5ef4f 8b554b89 via #1476, with your authorship intact, plus the maintainer commits from #1464. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.153. Thank you William. Closing this original.

nik

@nc9 nc9 closed this Nov 1, 2026
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.

tech-detect: restore Klaviyo script recall lost by the anchored scriptSrc signature

2 participants