Commit 24b87d3
feat: Allow external images (#3769)
Allow `Image` component to contain external URLs as well as SVGs. This
makes it easier for Snaps to show external images, however it is
required that the Snap has permission to use the network in order to use
this.
Additionally allow specifying `height` and `width` for images.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Enable https external images in `Image` JSX with optional
width/height, enforcing `endowment:network-access`; add URI struct and
update validation, controllers, policies, examples, and tests.
>
> - **SDK (JSX/UI/Internals)**:
> - `Image` now accepts external `https` URLs and optional
`width`/`height`; keeps SVG support.
> - Add `uri` struct and `UriOptions`; export via `@metamask/snaps-sdk`.
> - Validate external images via URI and require network permission.
> - Deprecate `getImageComponent` in favor of `<Image src="..." />`.
> - **Controllers/Utils**:
> - `SnapInterfaceController` validation now checks
`PermissionController:hasPermission`; blocks external images without
`endowment:network-access`.
> - `validateJsxElements` updated to verify external image URLs and
permission.
> - Consolidate URL validation by reusing SDK `uri` in `snaps-utils`
(removed duplicate implementation).
> - **Execution Environments (LavaMoat)**:
> - Allow `URL` global for `@metamask/snaps-sdk` policies.
> - **Examples**:
> - Images example snap switched to JSX (`index.tsx`), uses `<Image>`
with external URL; manifest shasum updated.
> - **Tests/Config**:
> - Extensive tests added/updated for dialogs, SVG/PNG, external image
permission checks.
> - Jest coverage config excludes `test-utils/**/*.tsx`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
394d7ed. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Maarten Zuidhoorn <[email protected]>1 parent 1e95bcd commit 24b87d3
File tree
26 files changed
+263
-121
lines changed- packages
- examples/packages/images
- src
- snaps-controllers
- src
- interface
- test-utils
- snaps-execution-environments/lavamoat/webpack
- iframe
- node-process
- node-thread
- webview
- snaps-sdk/src
- internals
- jsx
- components
- snaps-simulation/src
- snaps-utils
- src
26 files changed
+263
-121
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
Lines changed: 27 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
36 | 34 | | |
37 | 35 | | |
38 | 36 | | |
| 37 | + | |
| 38 | + | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
47 | | - | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 55 | + | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
81 | 70 | | |
82 | 71 | | |
83 | | - | |
84 | | - | |
| 72 | + | |
85 | 73 | | |
86 | 74 | | |
87 | 75 | | |
| |||
96 | 84 | | |
97 | 85 | | |
98 | 86 | | |
| 87 | + | |
| 88 | + | |
99 | 89 | | |
100 | 90 | | |
101 | 91 | | |
| |||
120 | 110 | | |
121 | 111 | | |
122 | 112 | | |
123 | | - | |
124 | | - | |
| 113 | + | |
125 | 114 | | |
126 | 115 | | |
127 | 116 | | |
| |||
136 | 125 | | |
137 | 126 | | |
138 | 127 | | |
| 128 | + | |
| 129 | + | |
139 | 130 | | |
140 | 131 | | |
141 | 132 | | |
| |||
160 | 151 | | |
161 | 152 | | |
162 | 153 | | |
163 | | - | |
164 | | - | |
| 154 | + | |
165 | 155 | | |
166 | 156 | | |
167 | 157 | | |
| |||
Lines changed: 31 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 2 | + | |
| 3 | + | |
10 | 4 | | |
11 | 5 | | |
12 | 6 | | |
| |||
26 | 20 | | |
27 | 21 | | |
28 | 22 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 23 | + | |
| 24 | + | |
33 | 25 | | |
34 | 26 | | |
35 | 27 | | |
| |||
44 | 36 | | |
45 | 37 | | |
46 | 38 | | |
47 | | - | |
| 39 | + | |
48 | 40 | | |
49 | 41 | | |
50 | 42 | | |
51 | 43 | | |
52 | 44 | | |
53 | 45 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
58 | 52 | | |
59 | 53 | | |
60 | 54 | | |
| |||
64 | 58 | | |
65 | 59 | | |
66 | 60 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
76 | 67 | | |
77 | 68 | | |
78 | 69 | | |
| |||
84 | 75 | | |
85 | 76 | | |
86 | 77 | | |
87 | | - | |
88 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
89 | 85 | | |
90 | 86 | | |
91 | 87 | | |
| |||
97 | 93 | | |
98 | 94 | | |
99 | 95 | | |
100 | | - | |
101 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
527 | 560 | | |
528 | 561 | | |
529 | 562 | | |
| |||
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
117 | | - | |
| 118 | + | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
282 | 284 | | |
283 | 285 | | |
284 | 286 | | |
285 | | - | |
| 287 | + | |
286 | 288 | | |
287 | 289 | | |
288 | 290 | | |
| |||
339 | 341 | | |
340 | 342 | | |
341 | 343 | | |
342 | | - | |
| 344 | + | |
343 | 345 | | |
344 | 346 | | |
345 | 347 | | |
| |||
530 | 532 | | |
531 | 533 | | |
532 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
533 | 543 | | |
534 | 544 | | |
535 | 545 | | |
536 | 546 | | |
| 547 | + | |
537 | 548 | | |
538 | 549 | | |
539 | | - | |
| 550 | + | |
540 | 551 | | |
541 | 552 | | |
542 | 553 | | |
| |||
549 | 560 | | |
550 | 561 | | |
551 | 562 | | |
| 563 | + | |
552 | 564 | | |
553 | 565 | | |
554 | 566 | | |
| |||
0 commit comments