Skip to content

Multiple global prototype patches stack without coordination #402

@aram356

Description

@aram356

Summary

Five integrations (Lockr, Permutive, DataDome, GTM, GPT) independently monkey-patch Element.prototype.appendChild and Element.prototype.insertBefore. Each captures the current prototype method at install time, creating a chain of 4+ wrappers. Every single appendChild call on the publisher page (including text nodes, divs, analytics pixels) now executes 4+ function calls with string checks.

The shared guard's reset() only flips a boolean — it does not restore the original prototype methods, so SPA contexts and test runs accumulate wrappers.

Refs

  • crates/js/lib/src/shared/script_guard.ts lines 155-191 — shared factory patches
  • crates/js/lib/src/integrations/gpt/script_guard.ts lines 432-450 — independent GPT patch
  • crates/js/lib/src/shared/script_guard.ts lines 197-199 — reset() doesn't restore originals

Recommendation

Use a centralized dispatcher — single prototype patch, register per-integration handlers. Implement proper reset() that restores originals.

Context

Production readiness audit — see #396

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions