@remit/ui 0.0.184 → 0.0.186

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/ui",
3
- "version": "0.0.184",
3
+ "version": "0.0.186",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -280,6 +280,8 @@ export const Counting: Story = {
280
280
  * A bulk delete in progress reports a running total via `statusLabel` and a
281
281
  * determinate `ProgressBar`; the delete button shows its busy spinner (never
282
282
  * disables) and the overflow verbs drop out — nothing here can act mid-delete.
283
+ * Stop rides on the notice, the way it does while counting: the run outlives
284
+ * the wizard's run screen, so the bar has to be able to end it too.
283
285
  */
284
286
  export const DeletingWithProgress: Story = {
285
287
  args: {
@@ -287,6 +289,37 @@ export const DeletingWithProgress: Story = {
287
289
  statusLabel: "Deleting 1,200 of 3,412…",
288
290
  isBusy: true,
289
291
  progress: { value: 1200, max: 3412 },
292
+ notice: {
293
+ tone: "info",
294
+ text: "",
295
+ action: { label: "Stop", onClick: () => undefined },
296
+ },
297
+ },
298
+ };
299
+
300
+ /**
301
+ * The same run, as the user finds it after leaving the mailbox and coming back.
302
+ * The selection did not survive the route and nothing is ticked, so the count
303
+ * and the label are the run's own: an idle header over mail that is still being
304
+ * deleted would be the lie this replaces. Stop is the same press it was before
305
+ * they left.
306
+ */
307
+ export const RunResumedAfterLeaving: Story = {
308
+ args: {
309
+ count: 3412,
310
+ statusLabel: "Deleting 2,100 of 3,412…",
311
+ isBusy: true,
312
+ progress: { value: 2100, max: 3412 },
313
+ selectAll: {
314
+ checked: false,
315
+ indeterminate: false,
316
+ onChange: () => undefined,
317
+ },
318
+ notice: {
319
+ tone: "info",
320
+ text: "",
321
+ action: { label: "Stop", onClick: () => undefined },
322
+ },
290
323
  },
291
324
  };
292
325
 
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Every way an email can name a remote image, and what blocking does to each
3
+ * (#352).
4
+ *
5
+ * `src` on an `<img>` is the obvious one and was the only one the hook rewrote.
6
+ * Three more fetch without a click and none of them are forbidden by config:
7
+ * `srcset` on an `<img>` wins over `src` on any 2x screen, a `<source srcset>`
8
+ * inside a `<picture>` outranks the `<img>` it wraps in every modern browser,
9
+ * and `<video poster>` loads before playback. A blocked or untrusted sender's
10
+ * tracker fires through any of them, so blocking has to close all four.
11
+ *
12
+ * Mounted against jsdom because DOMPurify needs a real DOM.
13
+ */
14
+
15
+ import "@remit/test-dom";
16
+ import assert from "node:assert/strict";
17
+ import { describe, test } from "node:test";
18
+ import { createEmailSanitizer } from "./email-sanitizer.js";
19
+
20
+ const TRACKER = "https://tracker.example/pixel.png";
21
+ const TRACKER_2X = "https://tracker.example/pixel@2x.png";
22
+ const POSTER = "https://tracker.example/poster.jpg";
23
+
24
+ const sanitize = (html: string, allowExternalImages: boolean): string =>
25
+ createEmailSanitizer({ allowExternalImages })(html).html;
26
+
27
+ // The blocked `<img src>` is deliberately parked in `data-blocked-src` so
28
+ // "load once" can restore it. Anywhere else, a tracker URL in the output is a
29
+ // fetch the browser will make.
30
+ const remoteUrlsOutsideBlockedSrc = (html: string): string[] =>
31
+ [...html.replace(/data-blocked-src="[^"]*"/g, "").matchAll(/https:\/\/\S+/g)]
32
+ .map((match) => match[0])
33
+ .filter((url) => url.includes("tracker.example"));
34
+
35
+ describe("blocking closes every remote-image vector (#352)", () => {
36
+ test("drops srcset on an img, keeping the placeholder swap", () => {
37
+ const html = sanitize(
38
+ `<img src="${TRACKER}" srcset="${TRACKER_2X} 2x" alt="x" />`,
39
+ false,
40
+ );
41
+ assert.doesNotMatch(html, /srcset/);
42
+ assert.match(html, /data-blocked-src="https:\/\/tracker\.example/);
43
+ assert.match(html, /src="data:image\/svg\+xml/);
44
+ assert.deepEqual(remoteUrlsOutsideBlockedSrc(html), []);
45
+ });
46
+
47
+ test("drops srcset on an img whose src is a harmless data URI", () => {
48
+ const html = sanitize(
49
+ `<img src="data:image/gif;base64,R0lGOD" srcset="${TRACKER_2X} 2x" />`,
50
+ false,
51
+ );
52
+ assert.doesNotMatch(html, /srcset/);
53
+ assert.deepEqual(remoteUrlsOutsideBlockedSrc(html), []);
54
+ });
55
+
56
+ test("neuters a picture's source, which would otherwise beat the placeholder img", () => {
57
+ const html = sanitize(
58
+ `<picture><source srcset="${TRACKER_2X}" type="image/png" /><img src="${TRACKER}" /></picture>`,
59
+ false,
60
+ );
61
+ assert.doesNotMatch(html, /srcset/);
62
+ assert.deepEqual(remoteUrlsOutsideBlockedSrc(html), []);
63
+ });
64
+
65
+ test("neuters a bare source src", () => {
66
+ const html = sanitize(
67
+ `<video><source src="${TRACKER}" type="video/mp4" /></video>`,
68
+ false,
69
+ );
70
+ assert.deepEqual(remoteUrlsOutsideBlockedSrc(html), []);
71
+ });
72
+
73
+ test("drops a video poster, which loads before any playback", () => {
74
+ const html = sanitize(`<video poster="${POSTER}"></video>`, false);
75
+ assert.doesNotMatch(html, /poster/);
76
+ assert.deepEqual(remoteUrlsOutsideBlockedSrc(html), []);
77
+ });
78
+ });
79
+
80
+ describe("loading images restores every vector (#352)", () => {
81
+ test("keeps srcset on an img", () => {
82
+ const html = sanitize(
83
+ `<img src="${TRACKER}" srcset="${TRACKER_2X} 2x" alt="x" />`,
84
+ true,
85
+ );
86
+ assert.match(html, /srcset="[^"]*pixel@2x\.png/);
87
+ assert.match(html, /src="https:\/\/tracker\.example\/pixel\.png"/);
88
+ assert.doesNotMatch(html, /data-blocked-src/);
89
+ });
90
+
91
+ test("keeps a picture's source srcset", () => {
92
+ const html = sanitize(
93
+ `<picture><source srcset="${TRACKER_2X}" type="image/png" /><img src="${TRACKER}" /></picture>`,
94
+ true,
95
+ );
96
+ assert.match(html, /srcset="[^"]*pixel@2x\.png/);
97
+ });
98
+
99
+ test("keeps a source src", () => {
100
+ const html = sanitize(
101
+ `<video><source src="${TRACKER}" type="video/mp4" /></video>`,
102
+ true,
103
+ );
104
+ assert.match(html, /src="https:\/\/tracker\.example\/pixel\.png"/);
105
+ });
106
+
107
+ test("keeps a video poster", () => {
108
+ const html = sanitize(`<video poster="${POSTER}"></video>`, true);
109
+ assert.match(html, /poster="https:\/\/tracker\.example\/poster\.jpg"/);
110
+ });
111
+ });
@@ -372,6 +372,28 @@ export const createEmailSanitizer = (options: SanitizeOptions = {}) => {
372
372
 
373
373
  // Hook: Process elements after attribute sanitization
374
374
  purify.addHook("afterSanitizeAttributes", (node) => {
375
+ // `src` is not the only way to name a remote image. DOMPurify keeps
376
+ // `srcset` on `<img>`, `<source srcset>` inside `<picture>`, and
377
+ // `<video poster>`, and every one of them fetches without a click —
378
+ // a `<source>` outranks the `<img>` it wraps, and a bare `srcset`
379
+ // wins on any 2x screen. Blocking a sender's images has to close all
380
+ // of them, so these are stripped rather than parked in
381
+ // `data-blocked-src`: there is no per-candidate "load once" to
382
+ // restore them with. Turning `allowExternalImages` on re-sanitizes
383
+ // the original HTML, which is how the images come back.
384
+ if (!options.allowExternalImages) {
385
+ if (node.tagName === "IMG") {
386
+ node.removeAttribute("srcset");
387
+ }
388
+ if (node.tagName === "SOURCE") {
389
+ node.removeAttribute("srcset");
390
+ node.removeAttribute("src");
391
+ }
392
+ if (node.tagName === "VIDEO") {
393
+ node.removeAttribute("poster");
394
+ }
395
+ }
396
+
375
397
  // Handle images
376
398
  if (node.tagName === "IMG") {
377
399
  const src = node.getAttribute("src") || "";