@vitrinka/web 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @vitrinka/web
2
2
 
3
+ ## 0.5.3
4
+
5
+ - **Credentials in URL paths no longer reach vitrinka (`sanitizeUrl`).**
6
+ The recorder scrubbed secrets only in query strings and fragments, and
7
+ recorded `route` fields with no redaction at all. An app whose routes
8
+ carry tokens in the path (`/reset-password/:token`, `/cart/:id/:token`,
9
+ `/invite/:token`) uploaded them with every session and bug report.
10
+ `VitrinkaRecorderRoot` and `RecorderConfig` now take an optional
11
+ `sanitizeUrl: (url: string) => string`. It rewrites every URL and route
12
+ the recorder captures before the redaction engine scrubs it:
13
+ - navigation `url` and `route`, including the page a session starts on;
14
+ - the `route` of clicks, notes and annotations;
15
+ - network request URLs;
16
+ - the page URL on each rrweb full snapshot;
17
+ - a bug report's navigation and note.
18
+
19
+ It applies under `fullFidelity` too. A sanitizer that throws or returns a
20
+ non-string fails closed: the recorder keeps only the URL's origin, or
21
+ `[redacted]` when there is none, and logs one warning. See
22
+ [Credentials in URL paths](README.md#credentials-in-url-paths-sanitizeurl).
23
+ - **Routes are redacted.** Every `route` field now passes the same scrub as
24
+ a URL, so a workspace's value patterns reach routes too. Without a
25
+ `sanitizeUrl`, a route that matches no pattern is recorded as before.
26
+
3
27
  ## 0.5.2
4
28
 
5
29
  - **A page that leads keeps the recording against an extension that is only
@@ -7,9 +31,13 @@
7
31
  extension records in another tab) also fired on the `starting` the
8
32
  extension's Start probe announces before it reads the page's claim. The
9
33
  page stepped aside and the extension's Start went through instead of being
10
- refused (extension 0.11.0 against web 0.5.1). The page now yields only to
11
- an extension recording or paused elsewhere; a probe meets the claim and is
12
- refused, as first-to-start-leads demands.
34
+ refused. The page now yields only to an extension recording or paused
35
+ elsewhere, so a `starting` probe meets the claim and is refused. This does
36
+ not cover extension 0.11.0. Its `one.js` announces `recording` as soon as
37
+ the Start probe installs it, before the probe reads the claim, and a page
38
+ cannot tell that apart from a real recording in another tab. Use extension
39
+ 0.11.1 or later, which installs `one.js` only where no recorder already
40
+ leads.
13
41
 
14
42
  ## 0.5.1
15
43
 
package/README.md CHANGED
@@ -88,6 +88,50 @@ can file each app's sessions into its own project: pass `project` per app.
88
88
  Without it, the host's project rule decides; a recorder key's project pin
89
89
  always wins, and a different `project` is refused.
90
90
 
91
+ ### Credentials in URL paths (`sanitizeUrl`)
92
+
93
+ The redaction engine scrubs secrets in query strings and fragments
94
+ (`?token=…`, `#access_token=…`), but it cannot know which path segments of
95
+ your routes are credentials. A reset link at `/reset-password/<token>` or a
96
+ guest cart at `/cart/<id>/<token>` would otherwise reach vitrinka in every
97
+ navigation, click, note and bug report. Name them with `sanitizeUrl`:
98
+
99
+ ```tsx
100
+ // Each rule rewrites a path segment that IS a credential into a placeholder.
101
+ const SECRET_PATHS: [RegExp, string][] = [
102
+ [/\/(reset-password|set-password|invite|activation)\/[^/?#]+/g, '/$1/:token'],
103
+ [/\/cart\/([^/?#]+)\/[^/?#]+/g, '/cart/$1/:cartToken'],
104
+ [/\/verify-email\/[^/?#]+\/[^/?#]+/g, '/verify-email/:id/:hash'],
105
+ ];
106
+ const sanitizeUrl = (url: string) => SECRET_PATHS.reduce((u, [rx, to]) => u.replace(rx, to), url);
107
+
108
+ <VitrinkaRecorderRoot url={…} sanitizeUrl={sanitizeUrl}>
109
+ ```
110
+
111
+ - **Coverage:** it runs on every URL and route the recorder captures:
112
+ - navigation `url` and `route`, including the page a session starts on;
113
+ - the `route` of clicks, notes and annotations;
114
+ - network request URLs;
115
+ - the page URL on each rrweb full snapshot;
116
+ - a bug report's navigation and note.
117
+ - **Input:** it receives each string as captured: an absolute page URL, a
118
+ request URL as your code passed it (often relative), or a bare path. Match
119
+ on path segments, not on a URL you parse.
120
+ - **Order:** it runs first. The query/fragment scrub and your workspace's
121
+ patterns still apply to what it returns, and routes now pass them too.
122
+ - **`fullFidelity`:** it applies even under a `fullFidelity` policy. It is
123
+ your statement about your own URLs, not a workspace redaction rule.
124
+ - **Failure:** it fails closed. If it throws or returns a non-string, the
125
+ recorder keeps only the URL's origin (or `[redacted]` when there is none),
126
+ never the raw value. It logs one `vitrinka:` warning per sanitizer, saying
127
+ whether it threw or returned a non-string, and nothing of the thrown value
128
+ (its message or name may quote the URL).
129
+ - **Not covered:** free text and the DOM stay under the workspace policy:
130
+ request and response headers and bodies, console lines (a router error
131
+ that quotes the path, say), and the page's own text and links. Add a policy
132
+ pattern for a token shape that shows up in text. If a page renders a
133
+ credential as visible text or in a link, mark that element `.rr-block`.
134
+
91
135
  ### Env vars
92
136
 
93
137
  | Var | What |
@@ -330,12 +374,15 @@ same mount as one self-contained script with React bundled in:
330
374
  |---|---|---|
331
375
  | rrweb | `rrweb` | `{count}` + `blobKey` — the batch itself is uploaded as a chunk; inputs always masked, all text under a `maskAllText` policy; the page URL each full snapshot carries is scrubbed of query/fragment secrets; images recorded by URL, never inlined (inlining would alter the page's own `<img>`) |
332
376
  | clicks | `click` | `{selector, text, rect, route}` — `text` is never a form field's value, and empty at, inside or around `.rr-mask` / `.rr-block` and under `maskAllText` |
333
- | navigation | `nav` | `{url, route, spa}` — `url` scrubbed of query/fragment secrets, the start URL included |
377
+ | navigation | `nav` | `{url, route, spa}` — `url` scrubbed of query/fragment secrets, the start URL included; `route` passes the value patterns |
334
378
  | network | `net` | `{method, url, status, ms, reqHeaders, resHeaders, reqBody, resBody, via}` — redacted, capped at 64 KiB per body; the recorder's own uploads are never recorded |
335
379
  | console | `console` | `{level: 'error', text}` |
336
380
  | notes | `note` | `{text, route}`; annotations add `{rect, selector, annotate: true, task?}`; a note with images adds `attachments: [seq…]` |
337
381
  | images | `attachment` | `{name, mime, bytes, w, h}` + `blobKey` — the image itself is uploaded to `/shot?seq=N` first; its seq sits just below its note's |
338
382
 
383
+ Every `url` and `route` above, and the rrweb page URL, passes your
384
+ [`sanitizeUrl`](#credentials-in-url-paths-sanitizeurl) first when you pass one.
385
+
339
386
  Data goes to your vitrinka server only. Details, the redaction rules and the
340
387
  policy fetch: [`docs/PROTOCOL.md`](../../docs/PROTOCOL.md).
341
388
 
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { pushEvent } from '../queue';
10
10
  import { currentRoute } from '../state';
11
- import { maskDirectives, redactText } from './redact';
11
+ import { maskDirectives, redactedRoute, redactText } from './redact';
12
12
  import { elementText, shortSelector } from './selector';
13
13
  export { elementText, shortSelector };
14
14
  const CLICKABLE = 'a,button,[role=button],input,select,textarea,label';
@@ -47,7 +47,7 @@ export function installClickLane(opts) {
47
47
  selector: shortSelector(el),
48
48
  text: clickText(el),
49
49
  rect: imageRect(el),
50
- route: currentRoute.pathname,
50
+ route: redactedRoute(),
51
51
  }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
52
52
  }
53
53
  catch {
@@ -23,7 +23,7 @@ export function noteNavigation(force = false) {
23
23
  if (url === lastUrl && !force)
24
24
  return false;
25
25
  lastUrl = url;
26
- return null !== pushEvent('nav', { url: redactUrl(url), route: loc.pathname, spa: true }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
26
+ return null !== pushEvent('nav', { url: redactUrl(url), route: redactUrl(loc.pathname), spa: true }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
27
27
  }
28
28
  /** Seed the dedupe with the URL the session started on (its nav is pushed by startSession). */
29
29
  export function primeNavigation() {
@@ -9,7 +9,9 @@
9
9
  * or slow policy fetch means the defaults, never capture-everything.
10
10
  *
11
11
  * Capture layers import the bound helpers below so every call site stays a
12
- * one-liner and can never forget to pass the rules.
12
+ * one-liner and can never forget to pass the rules. URLs and routes also pass
13
+ * the host's own `sanitizeUrl` (config) first: credentials in PATHS are the
14
+ * app's to name, the engine only sees query and fragment pairs.
13
15
  */
14
16
  import type { eventWithTime, metaEvent } from '@rrweb/types';
15
17
  import { type MaskDirectives, type RedactionPolicy, type RuleSet } from '@vitrinka/redact';
@@ -31,8 +33,14 @@ export declare function redactText(text: string | undefined): string | undefined
31
33
  * generic text scanner.
32
34
  */
33
35
  export declare function redactAndCap(body: string, cap: number, contentType?: string): string | undefined;
34
- /** Scrub URL query/fragment secrets under the active rules. */
36
+ /**
37
+ * Scrub one URL or route under the active rules: the host's `sanitizeUrl`
38
+ * first (path credentials), then the engine's query/fragment scrub and
39
+ * patterns. Every URL-bearing field the recorder captures passes here.
40
+ */
35
41
  export declare function redactUrl(url: string): string;
42
+ /** The `route` an event carries: the current pathname through `redactUrl`. */
43
+ export declare function redactedRoute(): string;
36
44
  /** rrweb's Meta event — the head of every full snapshot (start, each checkout, resume). */
37
45
  export declare function isMetaEvent(ev: eventWithTime): ev is metaEvent & eventWithTime;
38
46
  /**
@@ -1,4 +1,6 @@
1
- import { compileRules, redactAndCap as engineRedactAndCap, redactHeaders as engineRedactHeaders, redactText as engineRedactText, redactUrl as engineRedactUrl, maskDirectives as engineMaskDirectives, } from '@vitrinka/redact';
1
+ import { compileRules, REDACTED, redactAndCap as engineRedactAndCap, redactHeaders as engineRedactHeaders, redactText as engineRedactText, redactUrl as engineRedactUrl, maskDirectives as engineMaskDirectives, } from '@vitrinka/redact';
2
+ import { recorderConfig } from '../config';
3
+ import { currentRoute } from '../state';
2
4
  // Engine primitives that need no binding, re-exported for tests and callers.
3
5
  export { isSecretKey, REDACTED } from '@vitrinka/redact';
4
6
  let rules = compileRules(null);
@@ -27,9 +29,57 @@ export function redactText(text) {
27
29
  export function redactAndCap(body, cap, contentType) {
28
30
  return engineRedactAndCap(rules, body, cap, contentType);
29
31
  }
30
- /** Scrub URL query/fragment secrets under the active rules. */
32
+ /** The sanitizer whose failure was last reported: once, not on every URL. */
33
+ let reportedSanitizer = null;
34
+ /**
35
+ * The host's `sanitizeUrl` over one captured URL or route. FAIL CLOSED: a
36
+ * sanitizer that throws or returns a non-string leaves the URL's origin, or
37
+ * `[redacted]` when it has none (a relative URL, a route), never the raw
38
+ * value. It applies under `fullFidelity` too: it is the host's statement
39
+ * about its own URLs, not a workspace redaction rule.
40
+ */
41
+ function sanitizeUrl(url) {
42
+ const sanitize = recorderConfig().sanitizeUrl;
43
+ if (!sanitize)
44
+ return url;
45
+ let failure;
46
+ try {
47
+ const out = sanitize(url);
48
+ if (typeof out === 'string')
49
+ return out;
50
+ failure = `returned ${typeof out}`;
51
+ }
52
+ catch {
53
+ // Nothing of the thrown value: its message or name may quote the very URL it
54
+ // could not handle, and reading a property (or `instanceof`) can throw again.
55
+ failure = 'threw';
56
+ }
57
+ if (reportedSanitizer !== sanitize) {
58
+ reportedSanitizer = sanitize;
59
+ console.warn(`vitrinka: sanitizeUrl ${failure} — such URLs are recorded as their origin only`);
60
+ }
61
+ return originOf(url) ?? REDACTED;
62
+ }
63
+ function originOf(url) {
64
+ try {
65
+ const { origin } = new URL(url);
66
+ return origin === 'null' ? null : origin;
67
+ }
68
+ catch {
69
+ return null;
70
+ }
71
+ }
72
+ /**
73
+ * Scrub one URL or route under the active rules: the host's `sanitizeUrl`
74
+ * first (path credentials), then the engine's query/fragment scrub and
75
+ * patterns. Every URL-bearing field the recorder captures passes here.
76
+ */
31
77
  export function redactUrl(url) {
32
- return engineRedactUrl(rules, url);
78
+ return engineRedactUrl(rules, sanitizeUrl(url));
79
+ }
80
+ /** The `route` an event carries: the current pathname through `redactUrl`. */
81
+ export function redactedRoute() {
82
+ return redactUrl(currentRoute.pathname);
33
83
  }
34
84
  /** rrweb's `EventType.Meta`; `@rrweb/types` is type-only here, so the value. */
35
85
  const RRWEB_META = 4;
@@ -33,6 +33,16 @@ export interface RecorderConfig {
33
33
  * starts, and Report a bug is offered only during one.
34
34
  */
35
35
  flightRecorder?: boolean;
36
+ /**
37
+ * Rewrites every URL and route the recorder captures before the redaction
38
+ * engine scrubs it — for credentials an app keeps in its PATHS
39
+ * (`/reset-password/:token`), which the query/fragment scrub cannot see.
40
+ * It receives the string as captured: an absolute page URL, a request URL
41
+ * as the app passed it (often relative), or a bare route path. Fail closed:
42
+ * a sanitizer that throws (or returns a non-string) leaves the URL's origin,
43
+ * or `[redacted]` when it has none — never the raw value.
44
+ */
45
+ sanitizeUrl?: (url: string) => string;
36
46
  }
37
47
  export declare function configureRecorder(next: RecorderConfig): void;
38
48
  export declare function recorderConfig(): Readonly<RecorderConfig>;
@@ -9,6 +9,7 @@ export function configureRecorder(next) {
9
9
  config.project = next.project;
10
10
  config.label = next.label;
11
11
  config.flightRecorder = next.flightRecorder;
12
+ config.sanitizeUrl = next.sanitizeUrl;
12
13
  }
13
14
  export function recorderConfig() {
14
15
  return config;
@@ -40,6 +40,11 @@ export interface FlightWindow {
40
40
  bytes: number;
41
41
  /** The Meta event's (already redacted) page URL. */
42
42
  href: string;
43
+ /**
44
+ * The page's route when the window opened: the raw path through `redactUrl`,
45
+ * so route-only rules apply (never re-derived from the scrubbed `href`).
46
+ */
47
+ route: string;
43
48
  }
44
49
  /** What a report sends: oldest window first, lanes in capture order. */
45
50
  export interface FlightClip {
@@ -1,4 +1,5 @@
1
- import { isMetaEvent } from './capture/redact';
1
+ import { isMetaEvent, redactUrl } from './capture/redact';
2
+ import { currentRoute } from './state';
2
3
  export const FLIGHT_CHECKOUT_MS = 30_000;
3
4
  export const FLIGHT_MAX_RRWEB_BYTES = 4 * 1024 * 1024;
4
5
  export const FLIGHT_MAX_RRWEB_EVENTS = 20_000;
@@ -59,7 +60,9 @@ export function pushFlightRRWeb(ev) {
59
60
  return;
60
61
  const oldest = windows[0];
61
62
  if (isMetaEvent(ev)) {
62
- windows.push({ events: [], bytes: 0, href: ev.data.href });
63
+ // rrweb stamps the Meta event synchronously: the document is still on its page.
64
+ const path = globalThis.location?.pathname ?? currentRoute.pathname;
65
+ windows.push({ events: [], bytes: 0, href: ev.data.href, route: redactUrl(path) });
63
66
  if (windows.length > 2)
64
67
  windows.shift();
65
68
  }
@@ -37,6 +37,14 @@ export interface VitrinkaRecorderRootProps {
37
37
  * last minute, so "Report a bug" is offered only while recording.
38
38
  */
39
39
  flightRecorder?: boolean;
40
+ /**
41
+ * Rewrites every URL and route the recorder captures (navigation, clicks,
42
+ * notes, network requests, rrweb page URLs, bug reports) before redaction —
43
+ * name the path segments that carry credentials (`/reset-password/:token`).
44
+ * It gets absolute URLs, relative request URLs and bare paths alike. A
45
+ * sanitizer that throws records only the URL's origin.
46
+ */
47
+ sanitizeUrl?: (url: string) => string;
40
48
  /** A router's pathname, when the History wrap is not enough. */
41
49
  route?: string | null;
42
50
  children?: ReactNode;
@@ -36,6 +36,7 @@ export function VitrinkaRecorderRoot(props) {
36
36
  project: props.project,
37
37
  label: props.label,
38
38
  flightRecorder: props.flightRecorder,
39
+ sanitizeUrl: props.sanitizeUrl,
39
40
  },
40
41
  }, createElement(RouteFeed, { route: props.route }), props.children);
41
42
  }
@@ -1,6 +1,6 @@
1
1
  import { api, fetchPolicy, uploadChunk, uploadImage } from './api';
2
2
  import { stageAttachments } from './attachments';
3
- import { setRedactionPolicy } from './capture/redact';
3
+ import { redactedRoute, setRedactionPolicy } from './capture/redact';
4
4
  import { checkoutRRWeb } from './capture/rrweb';
5
5
  import { recorderConfig, vitrinkaLinked } from './config';
6
6
  import { clipHasSnapshot, flightActive, startFlightBuffer, stopFlightBuffer, takeFlightClip } from './flight';
@@ -121,14 +121,6 @@ function reportTitle(text) {
121
121
  function viewportRect() {
122
122
  return { x: 0, y: 0, w: globalThis.innerWidth || 0, h: globalThis.innerHeight || 0 };
123
123
  }
124
- function pathOf(href) {
125
- try {
126
- return new URL(href).pathname;
127
- }
128
- catch {
129
- return currentRoute.pathname;
130
- }
131
- }
132
124
  function buildJob(clip, note) {
133
125
  const tab = { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost };
134
126
  const events = [];
@@ -136,7 +128,7 @@ function buildJob(clip, note) {
136
128
  const first = clip.windows[0];
137
129
  const startMs = first?.events[0]?.timestamp;
138
130
  if (first && startMs !== undefined) {
139
- events.push({ seq: ++seq, ts: new Date(startMs).toISOString(), ...tab, kind: 'nav', payload: { url: first.href, route: pathOf(first.href) } });
131
+ events.push({ seq: ++seq, ts: new Date(startMs).toISOString(), ...tab, kind: 'nav', payload: { url: first.href, route: first.route } });
140
132
  }
141
133
  for (const e of clip.lanes) {
142
134
  events.push({ seq: ++seq, ts: e.ts, tabId: e.tabId, tabHost: e.tabHost, kind: e.kind, ...(e.payload ? { payload: e.payload } : {}) });
@@ -183,7 +175,7 @@ function buildJob(clip, note) {
183
175
  selector: note.selector,
184
176
  annotate: true,
185
177
  task: true,
186
- route: currentRoute.pathname,
178
+ route: redactedRoute(),
187
179
  ...(images.length ? { attachments: images.map((image) => image.seq) } : {}),
188
180
  },
189
181
  },
@@ -1,7 +1,7 @@
1
1
  import { api, fetchPolicy, permanentStatus, VitrinkaApiError } from './api';
2
2
  import { stageAttachments } from './attachments';
3
3
  import { primeNavigation } from './capture/nav';
4
- import { redactUrl, setRedactionPolicy } from './capture/redact';
4
+ import { redactedRoute, redactUrl, setRedactionPolicy } from './capture/redact';
5
5
  import { recorderConfig } from './config';
6
6
  import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, markStopping, persistNow, pruneBlobJournal, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, runBeforeStopHooks, setState, stoppingElsewhere, } from './queue';
7
7
  import { claimForStart, settleStart, setLeadStopping } from './lead';
@@ -216,7 +216,7 @@ export async function startSession(opts = {}) {
216
216
  // followed until this Start never heard the navigations in between) and
217
217
  // seeds the nav lane's dedupe with it.
218
218
  primeNavigation();
219
- pushEvent('nav', { url: redactUrl(currentUrl()), route: currentRoute.pathname }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
219
+ pushEvent('nav', { url: redactUrl(currentUrl()), route: redactedRoute() }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
220
220
  notify();
221
221
  return getState();
222
222
  }
@@ -282,7 +282,7 @@ function imagesOf(list) {
282
282
  * empty. Their bytes upload through `/shot` before their rows ride (queue.ts).
283
283
  */
284
284
  export function addNote(text, attachments) {
285
- pushEvent('note', { text, route: currentRoute.pathname }, route(), imagesOf(attachments));
285
+ pushEvent('note', { text, route: redactedRoute() }, route(), imagesOf(attachments));
286
286
  }
287
287
  /** Scale a viewport rect to device pixels — the extension's `imageRect` space. */
288
288
  export function imagePixels(r) {
@@ -307,7 +307,7 @@ export function addAnnotation(text, rect, selector, opts = {}) {
307
307
  rect: imagePixels(rect),
308
308
  selector,
309
309
  annotate: true,
310
- route: currentRoute.pathname,
310
+ route: redactedRoute(),
311
311
  ...(opts.task ? { task: true } : {}),
312
312
  }, route(), imagesOf(opts.attachments));
313
313
  }
@@ -1,3 +1,3 @@
1
1
  /** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
2
- export declare const RECORDER_VERSION = "0.5.2";
3
- export declare const RECORDER_ID = "web/0.5.2";
2
+ export declare const RECORDER_VERSION = "0.5.3";
3
+ export declare const RECORDER_ID = "web/0.5.3";
@@ -1,3 +1,3 @@
1
1
  /** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
2
- export const RECORDER_VERSION = '0.5.2';
2
+ export const RECORDER_VERSION = '0.5.3';
3
3
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitrinka/web",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "vitrinka toolkit for React DOM apps — the journey recorder: capture manual-testing sessions (rrweb DOM stream, clicks, navigation, network, console, notes) straight into vitrinka boards.",
5
5
  "license": "Elastic-2.0",
6
6
  "repository": {