Skip to content

feat(userale): add createUserAle() factory, opt-in PrivacyOptions, and replay/exporter hardening - #225

Open
brucearctor wants to merge 2 commits into
apache:masterfrom
brucearctor:feat/userale-factory-privacy-hardening
Open

brucearctor wants to merge 2 commits into
apache:masterfrom
brucearctor:feat/userale-factory-privacy-hardening

Conversation

@brucearctor

@brucearctor brucearctor commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Encapsulated createUserAle() factory & per-instance isolation (src/runtime.ts, src/packageLogs.ts, src/attachHandlers.ts, src/sendLogs.ts, src/replay/index.ts, src/configure.ts, src/getInitialSettings.ts, src/utils/index.ts, src/exporters/headers.ts):
    • Moves mutable log buffers, configuration state, callback maps, per-config auth/header credential resolvers (WeakMap), exporters, interval tracking, event handlers, and replay controllers into isolated closures per createUserAle() instance and per flagon-userale/manual runtime while keeping backwards compatibility for legacy singleton APIs.
  • Opt-in pre-packaging PrivacyOptions, preset: "strict", lockPrivacy(), and configurable events (src/privacy.ts, src/configure.ts, src/packageLogs.ts, src/attachHandlers.ts, src/types.d.ts):
    • Adds granular pre-packaging capture toggles (capturePageUrl, capturePageTitle, capturePageReferrer, captureHost, captureUserAgent, captureScreenRes, captureLocation, captureTargetRect, captureDetails, captureMicroTime, attachTraceContext, ignoreUntrustedEvents, domSelectorMode, allowlistSelector, allowedAttributes) and preset: "strict" with zero global reads for disabled fields.
    • Protects Configuration.update() against shallow nested overwrites, __proto__/method pollution, and unescaped RegExp matching in getUserIdFromParams().
    • Adds lockPrivacy() / isPrivacyLocked() to prevent post-init tampering across options(), addCallbacks(), log(), packageCustomLog(), details(), registerExporter(), and startSessionReplay(), plus dynamic events[] handler rebinding via AbortController.
  • DOM clobbering, Shadow DOM & nested element hardening (src/domUtils.ts, src/packageLogs.ts, src/attachHandlers.ts):
    • Uses prototype-chain getters/methods so <form><input name="closest|parentNode|id|attributes|..."> cannot bypass redaction or ignore markers, walks across open ShadowRoot hosts, handles SVGAnimatedString, enforces [data-userale-ignore] precedence over allowlistSelector, and reads raw allowedAttributes from the matched allowlist ancestor.
  • Replay, exporter, Protobuf, and JSON Schema hardening (src/replay/index.ts, src/exporters/*, proto/apache/flagon/userale/v1/log.proto, example/log.schema.json):
    • ReplayRingBuffer preserves prior Meta (type 4) anchors on checkout, adds maxBytes cap, fixes RageClickDetector empty-target/null-location false positives, adds [data-userale-redact] parity / maskAllText / !config.on guard, and routes > 48 KiB replay flushes through configured exporters.
    • HttpJsonExporter measures UTF-8 bytes and awaits keepalive chunks sequentially; createExporter() honors explicit exporterType (including "otel-sdk") over otlpEndpoint; OtlpJsonExporter respects null minimized session fields and attachTraceContext: false; OtelSdkExporter omits empty values; ProtoJsonExporter guards non-finite numbers, omits empty location/screenResolution, preserves native google.protobuf.Struct values, and adds targetRect, traceId/spanId, LOG_TYPE_MUTATION, and LOG_TYPE_REPLAY to log.proto; log.schema.json fixes "maxmaximumi" -> "maximum" and validates privacy-minimized, interval, mutation, and replay logs.
  • Site demo E2E autostart race fix (products/userale/test/spec/04-package-site-demo.spec.ts):
    • Waits for window.userale?.options?.().on === true after load so Playwright interactions do not race the 100ms autostart setup timer on fast headless runners.

Closes #217

Verification

  • pnpm --dir packages/flagon-userale build, tsc --noEmit -p packages/flagon-userale/tsconfig.json, and strict external consumer .d.ts compile (--strict --moduleResolution bundler --module esnext --target es2022 for build/main and build/manual)
  • pnpm lint:check (0 errors) and pnpm format:check (Prettier clean)
  • pnpm --dir packages/flagon-userale test --runInBand: 13 passed, 13 total suites; 147 passed, 147 total tests (including test/spec/factory_and_privacy.spec.ts and expanded exporters.spec.ts / replay.spec.ts)
  • buf lint, buf breaking --against ".git#branch=upstream/master", and buf generate

@brucearctor
brucearctor force-pushed the feat/userale-factory-privacy-hardening branch from e8f9d61 to cf8c31a Compare November 27, 2026 19:47
@brucearctor
brucearctor marked this pull request as ready for review November 27, 2026 19:54
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.

feat(userale): add encapsulated createUserAle() factory, pre-packaging opt-in PrivacyOptions, and exporter/replay hardening

2 participants